/**
* Save one or more preferences for a user. If no user ID is given the current user is used.
* The array has to assign every preference key a value to store.
* Example: array ( 'setting1' => 'value1', 'setting2' => 'value2');
*
* A prefix can be specified, which will be prepended to every preference key.
*
* @param array $data key/value pairs to store
* @param string $prefix prefix for all preferences
* @param integer $userId (optional) id of another user than the current
* @return boolean true on success, false on failure
* @author sl
*/
public function user_set_preferences(array $data, $prefix = '', $userId = null)
{
if ($userId === null) {
$userId = $this->kga['user']['userID'];
}
if (!$this->conn->TransactionBegin()) {
$this->logLastError('user_set_preferences');
return false;
}
$table = $this->kga['server_prefix'] . "preferences";
$filter['userID'] = MySQL::SQLValue($userId, MySQL::SQLVALUE_NUMBER);
$values['userID'] = $filter['userID'];
foreach ($data as $key => $value) {
$values['option'] = MySQL::SQLValue($prefix . $key);
$values['value'] = MySQL::SQLValue($value);
$filter['option'] = $values['option'];
$this->conn->AutoInsertUpdate($table, $values, $filter);
}
return $this->conn->TransactionEnd();
}