/** * Generic check for whether dependencies exist for this object in the database schema * * Can be overloaded/supplemented by the child class * * @param mixed $pk An optional primary key value check the row for. If not * set the instance property value is used. * @param array $joins An optional array to compiles standard joins formatted like: * [label => 'Label', name => 'table name' , idfield => 'field', joinfield => 'field'] * * @return boolean True on success. * * @deprecated 12.1 * @link http://docs.joomla.org/JTable/canDelete * @since 11.1 */ public function canDelete($pk = null, $joins = null) { // Deprecation warning. JLog::add('JTable::canDelete() is deprecated.', JLog::WARNING, 'deprecated'); // Initialise variables. $k = $this->_tbl_key; $pk = is_null($pk) ? $this->{$k} : $pk; // If no primary key is given, return false. if ($pk === null) { return false; } if (is_array($joins)) { // Get a query object. $query = $this->_db->getQuery(true); // Setup the basic query. $query->select($this->_db->quoteName($this->_tbl_key)); $query->from($this->_db->quoteName($this->_tbl)); $query->where($this->_db->quoteName($this->_tbl_key) . ' = ' . $this->_db->quote($this->{$k})); $query->group($this->_db->quoteName($this->_tbl_key)); // For each join add the select and join clauses to the query object. foreach ($joins as $table) { $query->select('COUNT(DISTINCT ' . $table['idfield'] . ') AS ' . $table['idfield']); $query->join('LEFT', $table['name'] . ' ON ' . $table['joinfield'] . ' = ' . $k); } // Get the row object from the query. $this->_db->setQuery((string) $query, 0, 1); $row = $this->_db->loadObject(); // Check for a database error. if ($this->_db->getErrorNum()) { $this->setError($this->_db->getErrorMsg()); return false; } $msg = array(); $i = 0; foreach ($joins as $table) { $k = $table['idfield'] . $i; if ($row->{$k}) { $msg[] = JText::_($table['label']); } $i++; } if (count($msg)) { $this->setError("noDeleteRecord" . ": " . implode(', ', $msg)); return false; } else { return true; } } return true; }
/** * Returns the ordering value to place a new item last in its group * * @access public * @param string query WHERE clause for selecting MAX(ordering). */ function getNextOrder($where = '') { if (!in_array('ordering', array_keys($this->getProperties()))) { $this->setError(get_class($this) . ' does not support ordering'); return false; } $query = 'SELECT MAX(ordering)' . ' FROM ' . $this->_tbl . ($where ? ' WHERE ' . $where : ''); $this->_db->setQuery($query); $maxord = $this->_db->loadResult(); if ($this->_db->getErrorNum()) { $this->setError($this->_db->getErrorMsg()); return false; } return $maxord + 1; }
protected function _modTopicList($data) { $result = array(); $catid = intval($data); $user = KunenaFactory::getuser(); if ($catid && $user->isModerator($catid)) { $query = "SELECT id, subject\n\t\t\t\t\t\t\tFROM #__kunena_messages\n\t\t\t\t\t\t\tWHERE catid={$this->_db->Quote($catid)} AND parent=0 AND moved=0\n\t\t\t\t\t\t\tORDER BY id DESC"; $this->_db->setQuery($query, 0, 15); $topics_list = $this->_db->loadObjectlist(); if ($this->_db->getErrorNum()) { $result = array('status' => '-1', 'error' => KunenaError::getDatabaseError()); } else { $result['status'] = '1'; $result['topiclist'] = $topics_list; } } else { $result['status'] = '0'; $result['error'] = 'Error'; } return $result; }
/** * Gets error number * * @deprecated 2.0 (use exceptions instead) * * @return int The error number for the most recent query */ public function getErrorNum() { return $this->_db->getErrorNum(); }
public function getRows($class = null) { // get the subset (based on limits) of records $query = 'SELECT *' . ' FROM #__acctexp_' . $this->table . $this->getConstraints() . $this->getOrdering() . $this->getLimit(); $this->db->setQuery($query); $rows = $this->db->loadObjectList(); if ($this->db->getErrorNum()) { echo $this->db->stderr(); return false; } if ($class) { foreach ($rows as $k => $obj) { $rows[$k] = new $class(); $rows[$k]->load($obj->id); } } return $rows; }