Kimai_Database_Mysql::user_get_preferences PHP Method

user_get_preferences() public method

Get several preferences for a user. If no user ID is given the current user is used.
Author: sl
public user_get_preferences ( array $keys, integer $userId = null ) : array
$keys array names of the preference to fetch in an array
$userId integer (optional) id of the user to fetch the preference for
return array with keys for every found preference and the found value
    public function user_get_preferences(array $keys, $userId = null)
    {
        if ($userId === null) {
            $userId = $this->kga['user']['userID'];
        }
        $table = $this->kga['server_prefix'] . "preferences";
        $userId = MySQL::SQLValue($userId, MySQL::SQLVALUE_NUMBER);
        $preparedKeys = array();
        foreach ($keys as $key) {
            $preparedKeys[] = MySQL::SQLValue($key);
        }
        $keysString = implode(",", $preparedKeys);
        $query = "SELECT `option`,`value` FROM {$table} WHERE userID = {$userId} AND `option` IN ({$keysString})";
        $this->conn->Query($query);
        $preferences = array();
        while (!$this->conn->EndOfSeek()) {
            $row = $this->conn->RowArray();
            $preferences[$row['option']] = $row['value'];
        }
        return $preferences;
    }
Kimai_Database_Mysql