/** * Called before delete(). * * @param mixed $pk An optional primary key value to delete. If not set the instance property value is used. * * @return boolean True on success. */ protected function beforeDelete($pk = null) { // Initialise variables. $k = $this->_tbl_key; // Received an array of ids? if (is_array($pk)) { // Sanitize input. JArrayHelper::toInteger($pk); $pk = RHelperArray::quote($pk); $pk = implode(',', $pk); } $pk = is_null($pk) ? $this->{$k} : $pk; // If no primary key is given, return false. if ($pk === null) { return false; } // Make sure it's not being used in projects $db = $this->_db; $query = $db->getQuery(true); $query->select('p.id'); $query->from('#__tracks_projects AS p'); $query->where('p.competition_id in (' . $pk . ')'); $db->setQuery($query); $res = $db->loadObject(); if ($res) { $this->setError(Jtext::_('COM_TRACKS_COMPETITION_DELETE_ERROR_ASSIGNED')); return false; } return true; }
/** * Delete project round events * * @param mixed $pk An optional primary key value to delete. If not set the instance property value is used. * * @return boolean True on success. */ protected function deleteResults($pk) { $pks = $this->getPkArray($pk); $pks = implode(', ', RHelperArray::quote($pks)); $query = $this->_db->getQuery(true)->delete('#__tracks_events_results')->where('event_id IN (' . $pks . ')'); $this->_db->setQuery($query); $this->_db->execute(); return true; }
/** * Delete project round events * * @param mixed $pk An optional primary key value to delete. If not set the instance property value is used. * * @return boolean True on success. */ protected function deleteProjectroundEvents($pk) { $pks = $this->getPkArray($pk); $pks = implode(', ', RHelperArray::quote($pks)); $query = $this->_db->getQuery(true)->select('id')->from('#__tracks_events')->where('projectround_id IN (' . $pks . ')'); $this->_db->setQuery($query); $eventIds = $this->_db->loadColumn(); $table = RTable::getAdminInstance('Event'); foreach ($eventIds as $id) { $table->delete((int) $id); } return true; }
/** * Delete one or more registers * * @param string/array $pk Array of ids or ids comma separated * * @return boolean Deleted successfuly? */ private function doDelete($pk = null) { // Initialise variables. $k = $this->_tbl_key; // Multiple keys $multiplePrimaryKeys = count($this->_tbl_keys) > 1; // We are dealing with multiple primary keys if ($multiplePrimaryKeys) { // Received an array of ids? if (is_null($pk)) { $pk = array(); foreach ($this->_tbl_keys as $key) { $pk[$key] = $this->{$key}; } } elseif (is_array($pk)) { $pk = array(); foreach ($this->_tbl_keys as $key) { $pk[$key] = !empty($pk[$key]) ? $pk[$key] : $this->{$key}; } } } else { if (is_array($pk)) { // Sanitize input. JArrayHelper::toInteger($pk); $pk = RHelperArray::quote($pk); $pk = implode(',', $pk); $multipleDelete = true; } elseif (empty($pk) && $this->{$k}) { $pk = $this->{$k}; } } // If no primary key is given, return false. if ($pk === null) { return false; } // Delete the row by primary key. $query = $this->_db->getQuery(true); $query->delete($this->_db->quoteName($this->_tbl)); if ($multiplePrimaryKeys) { foreach ($this->_tbl_keys as $k) { $query->where($this->_db->quoteName($k) . ' = ' . $this->_db->quote($pk[$k])); } } else { $query->where($this->_db->quoteName($this->_tbl_key) . ' IN (' . $pk . ')'); } $this->_db->setQuery($query); $this->_db->execute(); // Check for a database error. if ($this->_db->getErrorNum()) { $this->setError($this->_db->getErrorMsg()); return false; } return true; }
/** * Delete on or more registers * * @param string/array $pk Array of ids or ids comma separated * * @return boolean Deleted successfuly? */ private function doDelete($pk = null) { // Initialise variables. $k = $this->_tbl_key; // Received an array of ids? if (is_array($pk)) { // Sanitize input. JArrayHelper::toInteger($pk); $pk = RHelperArray::quote($pk); $pk = implode(',', $pk); } $pk = is_null($pk) ? $this->{$k} : $pk; // If no primary key is given, return false. if ($pk === null) { return false; } // Delete the row by primary key. $query = $this->_db->getQuery(true); $query->delete($this->_db->quoteName($this->_tbl)); $query->where($this->_db->quoteName($this->_tbl_key) . ' IN (' . $pk . ')'); $this->_db->setQuery($query); $this->_db->query(); // Check for a database error. if ($this->_db->getErrorNum()) { $this->setError($this->_db->getErrorMsg()); return false; } return true; }