Kimai_Database_Mysql::user_create PHP Method

user_create() public method

Adds a new user
Author: th
public user_create ( array $data ) : boolean | integer
$data array username, email, and other data of the new user
return boolean | integer false on failure, otherwise the new user id
    public function user_create($data)
    {
        // find random but unused user id
        do {
            $data['userID'] = random_number(9);
        } while ($this->user_get_data($data['userID']));
        $data = $this->clean_data($data);
        $values['name'] = MySQL::SQLValue($data['name']);
        $values['userID'] = MySQL::SQLValue($data['userID'], MySQL::SQLVALUE_NUMBER);
        $values['globalRoleID'] = MySQL::SQLValue($data['globalRoleID'], MySQL::SQLVALUE_NUMBER);
        $values['active'] = MySQL::SQLValue($data['active'], MySQL::SQLVALUE_NUMBER);
        // 'mail' and 'password' are just set when actually provided because of compatibility reasons
        if (array_key_exists('mail', $data)) {
            $values['mail'] = MySQL::SQLValue($data['mail']);
        }
        if (array_key_exists('password', $data)) {
            $values['password'] = MySQL::SQLValue($data['password']);
        }
        $table = $this->kga['server_prefix'] . "users";
        $result = $this->conn->InsertRow($table, $values);
        if ($result === false) {
            $this->logLastError('user_create');
            return false;
        }
        if (isset($data['rate'])) {
            if (is_numeric($data['rate'])) {
                $this->save_rate($data['userID'], null, null, $data['rate']);
            } else {
                $this->remove_rate($data['userID'], null, null);
            }
        }
        return $data['userID'];
    }
Kimai_Database_Mysql