public function store(User $user) { if (!$this->db->tableExists($this->table)) { $this->createTable($this->table); } $query = "DELETE FROM :::table WHERE id=:id"; $bindings = array(':::table' => $this->table, ':id' => $user->getID()); try { $this->db->execute($query, $bindings); } catch (Exception $e) { throw new UserStorageException('Unable to store user.'); } $query = "INSERT INTO :::table " . "(id, username, fullName, email, birthdate, gender, timezoneOffset, locale, lastLogin, secret) " . "VALUES (:id, :username, :fullName, :email, :birthdate, :gender, :timezoneOffset, :locale, :lastLogin, :secret)"; $bindings = array(':::table' => $this->table, ':id' => $user->getID(), ':username' => $user->getUsername(), ':fullName' => $user->getFullName(), ':email' => $user->getEmail(), ':birthdate' => $user->getBirthdate(), ':gender' => $user->getGender(), ':timezoneOffset' => $user->getTimezoneOffset(), ':locale' => $user->getLocale(), ':lastLogin' => $user->getLastLogin(), ':secret' => $user->getSecret()); try { $this->db->execute($query, $bindings); } catch (Exception $e) { throw new UserStorageException('Unable to store user.'); } }
/** * Converts a user to an array. * * @param User $user the user to convert * @return array the array */ private function userToArray(User $user) { $res = array(); $res['id'] = $user->getID(); $res['username'] = $user->getUsername(); $res['fullName'] = $user->getFullName(); $res['email'] = $user->getEmail(); $res['birthdate'] = $user->getBirthdate(); $res['gender'] = $user->getGender(); $res['timezoneOffset'] = $user->getTimezoneOffset(); $res['locale'] = $user->getLocale(); $res['lastLogin'] = $user->getLastLogin(); $res['secret'] = $user->getSecret(); return $res; }