UserRoleModel::saveRoleToDatabase PHP Method

saveRoleToDatabase() public static method

Writes the new account type marker to the database and to the session
public static saveRoleToDatabase ( $type ) : boolean
$type
return boolean
    public static function saveRoleToDatabase($type)
    {
        // if $type is not 1 or 2
        if (!in_array($type, [1, 2])) {
            return false;
        }
        $database = DatabaseFactory::getFactory()->getConnection();
        $query = $database->prepare("UPDATE users SET user_account_type = :new_type WHERE user_id = :user_id LIMIT 1");
        $query->execute(array(':new_type' => $type, ':user_id' => Session::get('user_id')));
        if ($query->rowCount() == 1) {
            // set account type in session
            Session::set('user_account_type', $type);
            return true;
        }
        return false;
    }