예제 #1
0
 /**
  * Remove specified contributions
  *
  * @param integer|array $ids         Contributions identifiers to delete
  * @param boolean       $transaction True to begin a database transaction
  *
  * @return boolean
  */
 public function removeContributions($ids, $transaction = true)
 {
     global $zdb, $hist;
     $list = array();
     if (is_numeric($ids)) {
         //we've got only one identifier
         $list[] = $ids;
     } else {
         $list = $ids;
     }
     if (is_array($list)) {
         $res = true;
         try {
             if ($transaction) {
                 $zdb->connection->beginTransaction();
             }
             $select = $zdb->select(self::TABLE);
             $select->where->in(self::PK, $list);
             $contributions = $zdb->execute($select);
             foreach ($contributions as $contribution) {
                 $c = new Contribution($contribution);
                 $res = $c->remove(false);
                 if ($res === false) {
                     throw new \Exception();
                 }
             }
             if ($transaction) {
                 $zdb->connection->commit();
             }
             $hist->add(str_replace('%list', print_r($list, true), _T("Contributions deleted (%list)")));
         } catch (\Exception $e) {
             if ($transaction) {
                 $zdb->connection->rollBack();
             }
             Analog::log('An error occured trying to remove contributions | ' . $e->getMessage(), Analog::ERROR);
             return false;
         }
     } else {
         //not numeric and not an array: incorrect.
         Analog::log('Asking to remove contribution, but without providing an array or a single numeric value.', Analog::WARNING);
         return false;
     }
 }