예제 #1
0
 /**
  * Method to store a record
  *
  * @return boolean True on success
  */
 public function store($data = null)
 {
     if (!$data) {
         $data = $this->app->input->post->getArray();
     }
     //Load Table
     $row = new UserTable();
     if (isset($data['id']) && $data['id']) {
         $row->load($data['id']);
     }
     if (isset($data['fullscreen'])) {
         $data['fullscreen'] = !$row->fullscreen;
     }
     if (isset($data['password']) && $data['password']) {
         $data['password'] = UsersHelper::hashPassword($data['password']);
     }
     //date generation
     $date = DateHelper::formatDBDate(date('Y-m-d H:i:s'));
     $data['modified'] = $date;
     // Bind the form fields to the table
     if (!$row->bind($data)) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     // Make sure the record is valid
     if (!$row->check()) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     // Store the web link table to the database
     if (!$row->store()) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     //update users email address
     if (array_key_exists('email', $data)) {
         $this->updateEmail($row->id, $data['email']);
     }
     if (isset($data['team_name']) && $data['team_name']) {
         $teamModel = new Teams();
         $teamModel->createTeam($row->id, $data['team_name']);
     }
     $this->app->refreshUser();
     return $row->id;
 }
예제 #2
0
 /**
  * Method to load a User object by user id number.
  *
  * @param   mixed  $identifier  The user id of the user to load.
  *
  * @return  $this  Method allows chaining
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function load($identifier)
 {
     // Create the user table object
     $table = new UserTable(null, null, $this->database);
     // Load the User object based on the user id or throw a warning.
     if (!$table->load($identifier)) {
         // Reset to guest user
         $this->guest = 1;
         throw new \RuntimeException('Unable to load the user with id: ' . $identifier);
     }
     // Assuming all is well at this point let's bind the data
     foreach ($table->getFields() as $key => $value) {
         if (isset($this->{$key}) && $key != 'params') {
             $this->{$key} = $table->{$key};
         }
     }
     $this->params->loadString($table->params);
     // The user is no longer a guest
     if ($this->id != 0) {
         $this->guest = 0;
     } else {
         $this->guest = 1;
     }
     return $this;
 }