CommonDBTM::deleteByCriteria PHP Method

deleteByCriteria() public method

Clean all infos which match some criteria
public deleteByCriteria ( $crit = [], $force, $history = 1 )
$crit array of criteria (ex array('is_active'=>'1'))
$force boolean force purge not on put in dustbin (default 0)
$history boolean do history log ? (true by default)
    function deleteByCriteria($crit = array(), $force = 0, $history = 1)
    {
        global $DB;
        $ok = false;
        if (is_array($crit) && count($crit) > 0) {
            $crit['FIELDS'] = 'id';
            $ok = true;
            foreach ($DB->request($this->getTable(), $crit) as $row) {
                if (!$this->delete($row, $force, $history)) {
                    $ok = false;
                }
            }
        }
        return $ok;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     switch ($ma->getAction()) {
         case 'delete_for_user':
             $input = $ma->getInput();
             if (isset($input['users_id'])) {
                 $user = new User();
                 $user->getFromDB($input['users_id']);
                 foreach ($ids as $id) {
                     if ($input['users_id'] == Session::getLoginUserID()) {
                         if ($item->deleteByCriteria(array('users_id' => $input['users_id'], 'itemtype' => $id))) {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                         } else {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                             $ma->addMessage($user->getErrorMessage(ERROR_ON_ACTION));
                         }
                     } else {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                         $ma->addMessage($user->getErrorMessage(ERROR_RIGHT));
                     }
                 }
             } else {
                 $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
CommonDBTM