/** * getListQuery * * @param Query $query * * @return Query */ protected function getListQuery(Query $query) { $queryHelper = $this->getQueryHelper(); $queryHelper->addTable('author', 'authors')->addTable('user', 'users', 'user.id = author.user')->addTable('blog', 'blogs', 'blog.id = author.blog'); $query->select($queryHelper->getSelectFields()); if ($this['blog.id']) { $query->where($query->format('%n = %q', 'blog.id', $this['blog.id'])); } if ($this['find.query']) { $q = '%' . $this['find.query'] . '%'; $conditions[] = $query->format('%n LIKE %q', 'user.username', $q); $conditions[] = $query->format('%n LIKE %q', 'user.fullname', $q); $conditions[] = $query->format('%n LIKE %q', 'user.email', $q); $conditions[] = $query->format('%n LIKE %q', 'author.name', $q); $query->where(new QueryElement('()', $conditions, ' OR ')); } $query = $queryHelper->registerQueryTables($query); if ($this['list.search']) { $search[] = $query->format('%n LIKE %q', 'title', '%' . $this['list.search'] . '%'); $search[] = $query->format('%n LIKE %q', 'alias', '%' . $this['list.search'] . '%'); $query->where(new QueryElement('()', $search, ' OR ')); } return $query; }
/** * getListQuery * * @param Query $query * * @return Query */ protected function getListQuery(Query $query) { $queryHelper = $this->getQueryHelper(); $queryHelper->addTable('post', 'posts')->addTable('author', 'authors', 'post.author = author.id')->addTable('user', 'users', 'user.id = author.user')->addTable('blog', 'blogs', 'post.blog = blog.id')->addTable('catmap', 'category_post_maps', 'catmap.post = post.id')->addTable('category', 'categories', 'category.id = catmap.category'); $query->select($queryHelper->getSelectFields())->where($query->format('%n = %q', 'blog.id', $this['blog.id']))->where($query->format('%n = %q', 'type', $this->get('post.type', 'post'))); if ($this['blog.published']) { $query->where('post.state >= 1'); } $query = $queryHelper->registerQueryTables($query); if ($this['list.search']) { $search[] = $query->format('%n LIKE %q', 'title', '%' . $this['list.search'] . '%'); $search[] = $query->format('%n LIKE %q', 'alias', '%' . $this['list.search'] . '%'); $query->where(new QueryElement('()', $search, ' OR ')); } if ($this['list.ordering']) { $query->order($this['list.ordering']); } $query->group('post.id'); return $query; }
/** * buildConditions * * @param Query $query * @param array $conditions * * @return Query */ public static function buildWheres(Query $query, array $conditions) { foreach ($conditions as $key => $value) { if (empty($value)) { continue; } // If using Compare class, we convert it to string. if ($value instanceof Compare) { $query->where((string) static::buildCompare($key, $value, $query)); } elseif (is_numeric($key)) { $query->where((string) $value); } elseif (is_array($value) || is_object($value)) { $value = array_map(array($query, 'quote'), (array) $value); $query->where($query->quoteName($key) . new QueryElement('IN ()', $value, ',')); } else { $query->where($query->format('%n = %q', $key, $value)); } } return $query; }
/** * Method to append the primary keys for this table to a query. * * @param Query $query A query object to append. * @param mixed $pk Optional primary key parameter. * * @return $this Method allows chaining * * @since 2.0 */ public function appendPrimaryKeys(Query $query, $pk = null) { if (is_null($pk)) { foreach ($this->keys as $k) { $query->where($this->db->quoteName($k) . ' = ' . $this->db->quote($this->{$k})); } } else { if (is_string($pk)) { $pk = array($this->keys[0] => $pk); } $pk = (object) $pk; foreach ($this->keys as $k) { $query->where($this->db->quoteName($k) . ' = ' . $this->db->quote($pk->{$k})); } } return $this; }
/** * buildConditions * * @param Query $query * @param array $conditions * * @return Query */ public static function buildWheres(Query $query, array $conditions) { foreach ($conditions as $key => $value) { // NULL if ($value === null) { $query->where($query->format('%n = NULL', $key)); } elseif ($value instanceof Compare) { $query->where((string) static::buildCompare($key, $value, $query)); } elseif (is_numeric($key)) { $query->where($query->format('%n = %a', $key, $value)); } elseif (is_array($value) || is_object($value)) { $value = array_map(array($query, 'quote'), (array) $value); $query->where($query->quoteName($key) . new QueryElement('IN ()', $value, ',')); } else { $query->where($query->format('%n = %q', $key, $value)); } } return $query; }