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

exists() public static method

Does the user exist.
public static exists ( integer $id, boolean $active = true ) : boolean
$id integer The userId to check for existence.
$active boolean Should the user be active also?
return boolean
    public static function exists($id, $active = true)
    {
        $id = (int) $id;
        $active = (bool) $active;
        // get db
        $db = BackendModel::getContainer()->get('database');
        // if the user should also be active, there should be at least one row to return true
        if ($active) {
            return (bool) $db->getVar('SELECT 1
                 FROM users AS i
                 WHERE i.id = ? AND i.deleted = ?
                 LIMIT 1', array($id, 'N'));
        }
        // fallback, this doesn't take the active nor deleted status in account
        return (bool) $db->getVar('SELECT 1
             FROM users AS i
             WHERE i.id = ?
             LIMIT 1', array($id));
    }

Usage Example

Exemplo n.º 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');
     }
 }
All Usage Examples Of Backend\Modules\Users\Engine\Model::exists