private function getDbFunctions() { return InstructionControl::getDbFunctionsInstance(); }
/** * Gets a User. * * If $loginKey is null a new User will be created, if it is not, it will try * and load that User. * * @param string $loginKey A Key which the User may have for loading himself. * @param string $knownAs If supplied this could be displayed in the * browser, it will be stored in the database. * @return array Associative array containing user information. * @throws InstructionControl_Exception should we fail loading a User. */ public static function getUser($loginKey = null, $knownAs = null) { // Make sure we have a User if ($loginKey) { // If we can just load it do so, $user = self::loadUser($loginKey, $knownAs); } else { // otherwise we need to create a new record $loginKey = genSaneGuid(); $communicationKey = genSaneGuid(); $insertData = array('login_key' => $loginKey, 'communication_key' => $communicationKey, 'known_as' => $knownAs); $id = self::getDbFunctionsInstance()->pdoInsert(' insert into user (login_key,communication_key,known_as) values (:login_key,:communication_key,:known_as) ', $insertData); $user = array_merge(array('id' => $id), $insertData); } // If known_as is different from what was passed in, sync it if ($knownAs && $user['known_as'] != $knownAs) { $stmt = InstructionControl::getDbFunctionsInstance()->pdoUpdate(' update user set known_as = :ka where id = :id ', array('ka' => $knownAs, 'id' => $user['id'])); $stmt->execute(); $user['known_as'] = $knownAs; } return $user; }