Example #1
0
 /**
  * (non-PHPdoc)
  * @see sample/admin/tables/DSCTable#delete($oid)
  */
 function delete($oid = '')
 {
     if (empty($oid)) {
         // if empty, use the values of the current keys
         $keynames = $this->getKeyNames();
         foreach ($keynames as $key => $value) {
             $oid[$key] = $this->{$key};
         }
         if (empty($oid)) {
             // if still empty, fail
             $this->setError(JText::_("Cannot delete with empty key"));
             return false;
         }
     }
     $oid = (array) $oid;
     $before = JFactory::getApplication()->triggerEvent('onBeforeDelete' . $this->get('_suffix'), array($this, $oid));
     if (in_array(false, $before, true)) {
         return false;
     }
     $db = $this->getDBO();
     // initialize the query
     $query = new DSCQuery();
     $query->delete();
     $query->from($this->getTableName());
     foreach ($oid as $key => $value) {
         // Check that $key is field in table
         if (!in_array($key, array_keys($this->getProperties()))) {
             $this->setError(get_class($this) . ' does not have the field ' . $key);
             return false;
         }
         // add the key=>value pair to the query
         $value = $db->q($db->escape(trim(strtolower($value))));
         $query->where($key . ' = ' . $value);
     }
     $db->setQuery((string) $query);
     if ($db->query()) {
         JFactory::getApplication()->triggerEvent('onAfterDelete' . $this->get('_suffix'), array($this, $oid));
         return true;
     } else {
         $this->setError($db->getErrorMsg());
         return false;
     }
 }
Example #2
0
 /**
  * (non-PHPdoc)
  * @see tienda/admin/tables/TiendaTable#delete($oid)
  */
 function delete($oid = '')
 {
     if (empty($oid)) {
         // if empty, use the values of the current keys
         $keynames = $this->getKeyNames();
         foreach ($keynames as $key => $value) {
             $oid[$key] = $this->{$key};
         }
         if (empty($oid)) {
             // if still empty, fail
             $this->setError(JText::_('COM_TIENDA_CANNOT_DELETE_WITH_EMPTY_KEY'));
             return false;
         }
     }
     if (!is_array($oid)) {
         $keyName = $this->getKeyName();
         $arr = array();
         $arr[$keyName] = $oid;
         $oid = $arr;
     }
     $dispatcher = JDispatcher::getInstance();
     $before = $dispatcher->trigger('onBeforeDelete' . $this->get('_suffix'), array($this, $oid));
     if (in_array(false, $before, true)) {
         return false;
     }
     $db = $this->getDBO();
     // initialize the query
     $query = new DSCQuery();
     $query->delete();
     $query->from($this->getTableName());
     foreach ($oid as $key => $value) {
         // Check that $key is field in table
         if (!in_array($key, array_keys($this->getProperties()))) {
             $this->setError(get_class($this) . ' does not have the field ' . $key);
             return false;
         }
         // add the key=>value pair to the query
         $value = $db->Quote($db->getEscaped(trim(strtolower($value))));
         $query->where($key . ' = ' . $value);
     }
     $db->setQuery((string) $query);
     if ($db->query()) {
         $dispatcher = JDispatcher::getInstance();
         $dispatcher->trigger('onAfterDelete' . $this->get('_suffix'), array($this, $oid));
         return true;
     } else {
         $this->setError($db->getErrorMsg());
         return false;
     }
 }