Example #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;
 }
Example #2
0
 public function store()
 {
     //Load Tables
     $row = new UserTable();
     $data = $this->app->input->post->getArray();
     //$this->app->triggerEvent('onBeforeCRMUserSave', array(&$data));
     //date generation
     $date = date('Y-m-d H:i:s');
     if (!array_key_exists('id', $data)) {
         $data['created'] = $date;
         $data['time_zone'] = ConfigHelper::getConfigValue('timezone');
         $data['time_format'] = ConfigHelper::getConfigValue('time_format');
         $data['block'] = 0;
         $data['registerDate'] = $date;
         $data['activation'] = 0;
         $data['params'] = "";
     }
     if (array_key_exists('password', $data) && $data['password'] != "") {
         $data['password'] = UsersHelper::hashPassword($data['password']);
     } else {
         unset($data['password']);
     }
     //generate team data
     $model = new Teams();
     if (array_key_exists('id', $data) && $data['id'] > 0) {
         $teamId = $this->getTeamId($data['id']);
     }
     //assign user priviliges
     $data['modified'] = $date;
     $data['admin'] = array_key_exists('admin', $data) && $data['admin'] == '1' ? 1 : 0;
     $data['exports'] = array_key_exists('exports', $data) && $data['exports'] == 'on' ? 1 : 0;
     $data['can_delete'] = array_key_exists('can_delete', $data) && $data['can_delete'] == 'on' ? 1 : 0;
     //republish / register users
     if (array_key_exists('id', $data) && $data['id'] != "") {
         $query = $this->db->getQuery(true);
         $query->clear()->select("id")->from("#__users")->where("id=" . $data['id']);
         $this->db->setQuery($query);
         $id = $this->db->loadResult();
         if ($id) {
             $data['id'] = $id;
             $data['published'] = 1;
         }
     }
     if (array_key_exists('team_id', $data) && $data['team_id'] == "") {
         unset($data['team_id']);
     }
     // 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;
     }
     if (array_key_exists('role_type', $data) && $data['role_type'] == "manager") {
         $teamModel = new Teams();
         $teamName = array_key_exists('team_name', $data) ? $data['team_name'] : "";
         $teamModel->createTeam($row->id, $teamName);
     }
     //if we are downgrading a users priviliges
     if (array_key_exists('manager_assignment', $data) && $data['manager_assignment'] != null && $data['manager_assignment'] != "") {
         $newTeamId = $this->getTeamId($data['manager_assignment']);
         $model->updateTeam($teamId, $newTeamId);
     }
     $row->id = array_key_exists('id', $data) && $data['id'] > 0 ? $data['id'] : $this->db->insertId();
     $this->updateUserMap($row);
     //$this->app->triggerEvent('onAfterCRMUserSave', array(&$data));
     return true;
 }
Example #3
0
 /**
  * Strategy Constructor
  *
  * @param   Input  $input  The input object from which to retrieve the request credentials.
  *
  * @since   1.0
  */
 public function __construct(Input $input)
 {
     $this->input = $input;
     $usersTable = new UserTable();
     $this->credentialStore = $usersTable->getUserPasswords();
 }
Example #4
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;
 }
Example #5
0
 /**
  * Assign a leader to a team and update the users table
  * @param  int  $leader_id the id of the new leader
  * @param  int  $team_id   the id of the newly created team
  * @return void
  */
 public function assignLeader($leader_id, $team_id)
 {
     //bind user tables
     $row = new UserTable();
     $team_data = array('id' => $leader_id, 'team_id' => $team_id);
     if (!$row->bind($team_data)) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     if (!$row->check()) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     if (!$row->store()) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
 }