Backend\Modules\Users\Engine\Model::undoDelete PHP Метод

undoDelete() публичный статический Метод

Restores a user
public static undoDelete ( string $email ) : boolean
$email string The e-mail address of the user to restore.
Результат boolean
    public static function undoDelete($email)
    {
        // redefine
        $email = (string) $email;
        // get db
        $db = BackendModel::getContainer()->get('database');
        // get id
        $id = $db->getVar('SELECT id
             FROM users AS i
             INNER JOIN users_settings AS s ON i.id = s.user_id
             WHERE i.email = ? AND i.deleted = ?', array($email, 'Y'));
        // no valid users
        if ($id === null) {
            return false;
        } else {
            // restore
            $db->update('users', array('active' => 'Y', 'deleted' => 'N'), 'id = ?', (int) $id);
            // return
            return true;
        }
    }

Usage Example

Пример #1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     $email = $this->getParameter('email', 'string');
     // does the user exist
     if ($email !== null) {
         parent::execute();
         // delete item
         if (BackendUsersModel::undoDelete($email)) {
             // get user
             $user = new BackendUser(null, $email);
             // trigger event
             $item = array('id' => $user->getUserId(), 'email' => $email);
             BackendModel::triggerEvent($this->getModule(), 'after_undelete', array('item' => $item));
             // item was deleted, so redirect
             $this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $user->getUserId() . '&report=restored&var=' . $user->getSetting('nickname') . '&highlight=row-' . $user->getUserId());
         } else {
             // invalid user
             $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing');
         }
     } else {
         $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing');
     }
 }