Backend\Modules\Profiles\Engine\Model::delete PHP Method

delete() public static method

Delete the given profiles.
public static delete ( mixed $ids )
$ids mixed One ID, or an array of IDs.
    public static function delete($ids)
    {
        // init db
        $db = BackendModel::getContainer()->get('database');
        // redefine
        $ids = (array) $ids;
        // delete profiles
        foreach ($ids as $id) {
            // redefine
            $id = (int) $id;
            // delete sessions
            $db->delete('profiles_sessions', 'profile_id = ?', $id);
            // set profile status to deleted
            self::update($id, array('status' => 'deleted'));
        }
    }

Usage Example

Esempio n. 1
0
 /**
  * Execute the action.
  */
 public function execute()
 {
     // get parameters
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendProfilesModel::exists($this->id)) {
         // call parent, this will probably add some general CSS/JS or other required files
         parent::execute();
         // get profile
         $profile = BackendProfilesModel::get($this->id);
         // already deleted? Prolly want to undo then
         if ($profile['status'] === 'deleted') {
             // set profile status to active
             BackendProfilesModel::update($this->id, array('status' => 'active'));
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_reactivate', array('id' => $this->id));
             // redirect
             $this->redirect(BackendModel::createURLForAction('Index') . '&report=profile-undeleted&var=' . urlencode($profile['email']) . '&highlight=row-' . $profile['id']);
         } else {
             // delete profile
             BackendProfilesModel::delete($this->id);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_delete_profile', array('id' => $this->id));
             // redirect
             $this->redirect(BackendModel::createURLForAction('Index') . '&report=profile-deleted&var=' . urlencode($profile['email']) . '&highlight=row-' . $profile['id']);
         }
     } else {
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing');
     }
 }
All Usage Examples Of Backend\Modules\Profiles\Engine\Model::delete