Backend\Modules\Users\Engine\Model::get PHP Method

get() public static method

Get all data for a given user
public static get ( integer $id ) : array
$id integer The userId to get the data for.
return array
    public static function get($id)
    {
        // redefine
        $id = (int) $id;
        // get db
        $db = BackendModel::getContainer()->get('database');
        // get general user data
        $user = (array) $db->getRecord('SELECT i.id, i.email, i.password, i.active
             FROM users AS i
             WHERE i.id = ?', array($id));
        // Don't add a settings element, just return an empty array here if no user is found.
        if (empty($user)) {
            return array();
        }
        // get user-settings
        $user['settings'] = (array) $db->getPairs('SELECT s.name, s.value
             FROM users_settings AS s
             WHERE s.user_id = ?', array($id));
        // loop settings and unserialize them
        foreach ($user['settings'] as &$value) {
            $value = unserialize($value);
        }
        // return
        return $user;
    }

Usage Example

Example #1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     $this->id = $this->getParameter('id', 'int');
     $error = $this->getParameter('error', 'string');
     $this->loadAuthenticatedUser();
     // If id and error parameters are not set we'll assume the user logged in
     // and has been redirected to this action by the authentication index action.
     // When this is the case the user will be redirected to the index action of this module.
     // An action to which he may not have any user rights.
     // Redirect to the user's own profile instead to avoid unnessary words.
     if ($this->id === null && $error === null && $this->authenticatedUser->getUserId()) {
         $this->redirect(BackendModel::createURLForAction('Edit') . '&id=' . $this->authenticatedUser->getUserId());
     }
     // does the user exists
     if ($this->id !== null && BackendUsersModel::exists($this->id)) {
         parent::execute();
         $this->record = (array) BackendUsersModel::get($this->id);
         $this->loadForm();
         $this->validateForm();
         $this->parse();
         $this->display();
     } else {
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing');
     }
 }