Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * 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;
 }
 /**
  * Gets the instance of the observer of class $observerClass
  *
  * @param   string  $observerClass  The observer class-name to return the object of
  *
  * @return  \JTableObserver|null
  *
  * @since   3.1.2
  */
 public function getObserverOfClass($observerClass)
 {
     return $this->observers->getObserverOfClass($observerClass);
 }
 /**
  * Adds an observer to this JObservableInterface instance.
  * Ideally, this method should be called fron the constructor of JObserverInterface
  * which should be instanciated by JObserverMapper.
  * The implementation of this function can use JObserverUpdater
  *
  * @param   JObserverInterface $observer The observer to attach to $this observable subject
  *
  * @return  void
  */
 public function attachObserver(JObserverInterface $observer)
 {
     $this->observers->attachObserver($observer);
 }