/** * Build query for load operation. * * @param \JDatabaseQuery $query The query object to handle. * * @return \JDatabaseQuery Return handled query object. */ public function buildLoadQuery(\JDatabaseQuery $query = null) { $conditions = array(); foreach ($this->fks as $field => $foreign) { $conditions[$foreign] = $this->parent->{$field}; } $query = $query ?: $this->db->getQuery(true); QueryHelper::buildWheres($query, $conditions); $query->select('*')->from($this->tableName); return $query; }
/** * Method to get a JDatabaseQuery object for retrieving the data set from a database. * * @return JDatabaseQuery A JDatabaseQuery object to retrieve the data set. */ protected function getListQuery() { $query = $this->db->getQuery(true); $queryHelper = $this->getQueryHelper(); // Prepare $this->prepareGetQuery($query); // Build filter query $this->processFilters($query, ArrayHelper::flatten((array) $this->get('filter'))); // Build search query $this->processSearches($query, ArrayHelper::flatten((array) $this->get('search'))); // Ordering $this->processOrdering($query); // Custom Where foreach ((array) $this->state->get('query.where', array()) as $k => $v) { $query->where($v); } // Custom Having foreach ((array) $this->state->get('query.having', array()) as $k => $v) { $query->having($v); } // Build query // ======================================================================== // Get select columns $select = $this->state->get('query.select'); if (!$select) { $select = $queryHelper->getSelectFields(); } $query->select($select); // Build Selected tables query $queryHelper->registerQueryTables($query); $this->postGetQuery($query); // Debug if (JDEBUG) { ProfilerHelper::mark(QueryHelper::highlightQuery($this->db->replacePrefix((string) $query))); } return $query; }
/** * Method to get a JDatabaseQuery object for retrieving the data set from a database. * * @return JDatabaseQuery A JDatabaseQuery object to retrieve the data set. */ protected function getListQuery() { $query = $this->db->getQuery(true); $queryHelper = $this->container->get('model.' . $this->getName() . '.helper.query'); // Prepare $this->prepareGetQuery($query); // Build filter query $this->processFilters($query, $this->state->get('filter', array())); // Build search query $this->processSearches($query, $this->state->get('search', array())); // Ordering $this->processOrdering($query); // Custom Where foreach ((array) $this->state->get('query.where', array()) as $k => $v) { $query->where($v); } // Custom Having foreach ((array) $this->state->get('query.having', array()) as $k => $v) { $query->having($v); } // Build query // ======================================================================== // Get select columns $select = $this->state->get('query.select'); if (!$select) { $selectType = $this->selectType ?: QueryHelper::COLS_WITH_FIRST | QueryHelper::COLS_PREFIX_WITH_FIRST; $select = $queryHelper->getSelectFields($selectType); } $query->select($select); // Build Selected tables query $queryHelper->registerQueryTables($query); $this->postGetQuery($query); // Debug if (JDEBUG) { ProfilerHelper::mark(QueryHelper::highlightQuery($this->db->replacePrefix((string) $query))); } return $query; }
/** * Batch update some data. * * @param string $table Table name. * @param string $data Data you want to update. * @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 True if update success. */ public static function updateBatch($table, $data, $conditions = array()) { $db = static::getInstance(); $query = $db->getQuery(true); // Build conditions $query = QueryHelper::buildWheres($query, $conditions); // Build update values. $fields = array_keys(static::getColumns($table)); $hasField = false; foreach ((array) $data as $field => $value) { if (!in_array($field, $fields)) { continue; } $query->set($query->format('%n = %q', $field, $value)); $hasField = true; } if (!$hasField) { return false; } $query->update($table); return $db->setQuery($query)->execute(); }
foreach ($cats as $cat) { // Get category link $link = ArticleHelper::getCategoryLink($cat->id); if (in_array($link, $linkCache)) { continue; } // Set some data $modified = $cat->modified_time != '0000-00-00 00:00:00' ? $cat->modified_time : $cat->created_time; $modified = JFactory::getDate($modified, JFactory::getConfig()->get('offset')); $modified = $modified->format('Y-m-d'); // Set xml data $sitemap->addItem($link, '0.7', 'weekly', $modified); $linkCache[] = $link; } // Build content map $where = \Windwalker\Model\Helper\QueryHelper::publishingItems('', 'state'); $query = $db->getQuery(true); $query->select("*")->from("#__content")->where($where)->order('id DESC'); if ($locale) { $query->where($query->format('language IN (%q, %q)', $locale, '*')); } $db->setQuery($query); $contents = $db->loadObjectList(); foreach ($contents as $content) { // Get category link $link = ArticleHelper::getArticleLink($content->id, $content->catid); if (in_array($link, $linkCache)) { continue; } // Set some data $modified = $content->modified != '0000-00-00 00:00:00' ? $content->modified : $content->created;