/**
  * Delete records by where conditions.
  *
  * @param mixed   $conditions Where conditions, you can use array or Compare object.
  *                            Example:
  *                            - `array('id' => 5)` => id = 5
  *                            - `new GteCompare('id', 20)` => 'id >= 20'
  *                            - `new Compare('id', '%Flower%', 'LIKE')` => 'id LIKE "%Flower%"'
  *
  * @return  boolean Will be always true.
  */
 public function delete($conditions)
 {
     $this->observers->update('onBeforeDelete', array(&$conditions));
     $result = parent::delete($conditions);
     $this->observers->update('onAfterDelete', array(&$result));
     return $result;
 }
예제 #2
0
파일: table.php 프로젝트: fur81/zofaxiopeu
 /**
  * Deletes this row in database (or if provided, the row of key $pk)
  *
  * @param   mixed  $pk  An optional primary key value to delete.  If not set the instance property value is used.
  *
  * @return  boolean  True on success.
  *
  * @link    http://docs.joomla.org/JTable/delete
  * @since   11.1
  * @throws  UnexpectedValueException
  */
 public function delete($pk = null)
 {
     $k = $this->_tbl_key;
     // Implement JObservableInterface: Pre-processing by observers
     $this->_observers->update('onBeforeDelete', array($pk, $k));
     $pk = is_null($pk) ? $this->{$k} : $pk;
     // If no primary key is given, return false.
     if ($pk === null) {
         throw new UnexpectedValueException('Null primary key not allowed.');
     }
     // If tracking assets, remove the asset first.
     if ($this->_trackAssets) {
         // Get and the asset name.
         $savedK = $this->{$k};
         $this->{$k} = $pk;
         $name = $this->_getAssetName();
         $asset = self::getInstance('Asset');
         if ($asset->loadByName($name)) {
             if (!$asset->delete()) {
                 $this->setError($asset->getError());
                 return false;
             }
         } else {
             $this->setError($asset->getError());
             return false;
         }
         $this->{$k} = $savedK;
     }
     // Delete the row by primary key.
     $query = $this->_db->getQuery(true)->delete($this->_tbl)->where($this->_tbl_key . ' = ' . $this->_db->quote($pk));
     $this->_db->setQuery($query);
     // Check for a database error.
     $this->_db->execute();
     // Implement JObservableInterface: Post-processing by observers
     $this->_observers->update('onAfterDelete', array($pk));
     return true;
 }
예제 #3
0
파일: table.php 프로젝트: klas/joomla-cms
 /**
  * Method to delete a row from the database table by primary key value.
  *
  * @param   mixed  $pk  An optional primary key value to delete.  If not set the instance property value is used.
  *
  * @return  boolean  True on success.
  *
  * @link    https://docs.joomla.org/JTable/delete
  * @since   11.1
  * @throws  UnexpectedValueException
  */
 public function delete($pk = null)
 {
     if (is_null($pk)) {
         $pk = array();
         foreach ($this->_tbl_keys as $key) {
             $pk[$key] = $this->{$key};
         }
     } elseif (!is_array($pk)) {
         $pk = array($this->_tbl_key => $pk);
     }
     foreach ($this->_tbl_keys as $key) {
         $pk[$key] = is_null($pk[$key]) ? $this->{$key} : $pk[$key];
         if ($pk[$key] === null) {
             throw new UnexpectedValueException('Null primary key not allowed.');
         }
         $this->{$key} = $pk[$key];
     }
     // Implement JObservableInterface: Pre-processing by observers
     $this->_observers->update('onBeforeDelete', array($pk));
     // If tracking assets, remove the asset first.
     if ($this->_trackAssets) {
         // Get the asset name
         $name = $this->_getAssetName();
         $asset = self::getInstance('Asset');
         if ($asset->loadByName($name)) {
             if (!$asset->delete()) {
                 $this->setError($asset->getError());
                 return false;
             }
         }
     }
     // Delete the row by primary key.
     $query = $this->_db->getQuery(true)->delete($this->_tbl);
     $this->appendPrimaryKeys($query, $pk);
     $this->_db->setQuery($query);
     // Check for a database error.
     $this->_db->execute();
     // Implement JObservableInterface: Post-processing by observers
     $this->_observers->update('onAfterDelete', array($pk));
     return true;
 }