/** * Creates a {@link Blueprint} instance from an {@link ActiveRecord\Query}. * * @param Query $query * * @return Blueprint */ public static function from(Query $query) { $query->mode(\PDO::FETCH_CLASS, __NAMESPACE__ . '\\BluePrintNode'); $relation = array(); $children = array(); $index = array(); foreach ($query as $row) { $row->parent = null; $row->depth = null; $row->children = array(); $nid = $row->nid; $parent_id = $row->parentid; $index[$nid] = $row; $relation[$nid] = $parent_id; $children[$parent_id][$nid] = $nid; } $tree = array(); foreach ($index as $nid => $page) { if (!$page->parentid || empty($index[$page->parentid])) { $tree[$nid] = $page; continue; } $page->parent = $index[$page->parentid]; $page->parent->children[$nid] = $page; } self::set_depth($tree); return new static($query->model, $relation, $children, $index, $tree); }
protected function alter_query(Query $query, array $conditions) { if (isset($conditions['nid'])) { $query->where('nid = ?', (int) $conditions['nid']); } $query->where('status != "spam" && status != "pending"'); return $query->order('created'); }
public function alter_query_with_value(Query $query, $value) { $token = self::generate_token(); $v_alias = $token . '_v'; $t_alias = $token . '_t'; $q = ActiveRecord\get_model('taxonomy.vocabulary')->select("nid, vocabularyslug AS {$v_alias}, termslug AS {$t_alias}")->join(':taxonomy.terms')->join(':taxonomy.terms/nodes'); $query->join($q, ['on' => 'nid'])->where([$v_alias => $this->id, $t_alias => $value]); return $query; }
/** * Alters the query to search for records from the same constructor, a similar site and a * similar language. * * The method also alters the query if the `nid` or `slug` conditions are defined. * * Finaly if the return type is RETURN_MANY the query is altered to search for online nodes * only. */ protected function alter_query(Query $query, array $conditions) { $query->own->similar_site->similar_language; if (isset($conditions['nid'])) { $query->filter_by_nid($conditions['nid']); } else { if (isset($conditions['slug'])) { $query->filter_by_slug($conditions['slug']); } } if ($this->returns == self::RETURNS_MANY) { $query->filter_by_is_online(true); } return parent::alter_query($query, $conditions)->order('created_at DESC'); }
public function alter_query_with_filter(Query $query, $filter_value) { if ($filter_value) { list($type, $name) = explode(':', $filter_value); if ($type == 'operation') { $query->and('class LIKE ?', '%\\' . $name . 'Operation'); } } return $query; }
/** * Alters the query to search for records from the same constructor, a similar site and a * similar language. * * The method also alters the query if the `nid` or `slug` conditions are defined. * * Finaly if the return type is RETURN_MANY the query is altered to search for online nodes * only. * * @see BriskView.ActiveRecordProvider::alter_query() */ protected function alter_query(Query $query, array $conditions) { static $mapping = ['uid', 'constructor', 'username', 'language']; foreach ($mapping as $property) { if (!isset($conditions[$property])) { continue; } $filter = 'filter_by_' . $property; $query->{$filter}($conditions[$property]); } if ($this->returns == self::RETURNS_MANY) { $query->filter_by_is_activated(true); } return parent::alter_query($query, $conditions)->order('created_at DESC'); }
/** * Support for the `year`, `month` and `day` conditions. Changes the order to * `date DESC, created_at DESC`. * * If the view is of type "home" the query is altered to search for nodes which are not * excluded from _home_. */ protected function alter_query(Query $query, array $conditions) { foreach ($conditions as $property => $value) { switch ($property) { case 'year': $query->where('YEAR(date) = ?', (int) $value); break; case 'month': $query->where('MONTH(date) = ?', (int) $value); break; case 'day': $query->where('DAY(date) = ?', (int) $value); break; } } if ($this->view->type == 'home') { $query->where('is_home_excluded = 0'); } return parent::alter_query($query, $conditions)->order('date DESC, created_at DESC'); }
public function alter_query_with_value(Query $query, $value) { if (!$value) { return $query; } $field = $this->id; list($year, $month, $day) = explode('-', $value) + [0, 0, 0]; if ($day) { $query->and("DATE(`{$field}`) = ?", "{$year}-{$month}-{$day}"); } else { if ($month) { $query->and("YEAR(`{$field}`) = ? AND MONTH(`{$field}`) = ?", (int) $year, (int) $month); } else { if ($year) { $query->and("YEAR(`{$field}`) = ?", (int) $year); } } } return $query; }
/** * Changes the order of the query with "weight, create". * * @param Query $query * * @return Query */ protected function scope_ordered(Query $query, $direction = 1) { $direction = $direction < 0 ? 'DESC' : 'ASC'; return $query->order("weight {$direction}, created_at {$direction}"); }
/** * Adds the "constructor = <constructor>" condition to the query. * * @param Query $query The query to alter. * * @return Query */ protected function scope_own(Query $query) { return $query->filter_by_constructor($this->constructor); }
public function alter_query_with_value(Query $query, $value) { $users = \ICanBoogie\app()->models['users']->select('id AS user_id, username'); return $query->join($users, ['on' => 'user_id'])->and("post.user_id = ? OR username = ?", $value, $value); }
/** * Orders the records according to their popularity. */ public function alter_query_with_order(Query $query, $order_direction) { return $query->order("(SELECT COUNT(vtid) FROM {self}__nodes WHERE vtid = term.vtid) " . ($order_direction < 0 ? 'DESC' : 'ASC')); }
public function alter_query_with_order(Query $query, $order_direction) { return $query->order("(SELECT COUNT(uid) FROM {prefix}users_logins WHERE uid = user.uid) " . ($order_direction < 0 ? 'desc' : 'asc')); }
/** * Alerts the query to match recors of a similar language. * * A record is considered of a similar language when it doesn't have a language defined * (`language` = "") or it matches the specified language. * * @param Query $query * @param string $language The language to match. If the language is `null` the current * language is used instead. * * @return Query */ protected function scope_similar_language(Query $query, $language = null) { global $core; return $query->where('language = "" OR language = ?', $language !== null ? $language : $core->site->language); }
/** * Orders the records according to the `author` column. */ public function alter_query_with_order(Query $query, $order_direction) { return $query->order('`author` ' . ($order_direction < 0 ? 'DESC' : 'ASC')); }
/** * @inheritdoc */ public function alter_query_with_limit(Query $query, $offset, $limit) { return $query->limit($offset, $limit); }
public function alter_query_with_order(Query $query, $order_direction) { $usage_query = $query->model->join(':taxonomy.terms/nodes')->join(':nodes')->select('vtid, COUNT(nid) as `usage`')->where('is_online = 1')->group('vtid'); return $query->join($usage_query, ['as' => 'term_usage'])->order('`usage` ' . ($order_direction < 0 ? 'DESC' : 'ASC')); }
public function alter_query_with_order(Query $query, $order_direction) { $keys = array_keys($this->resolved_user_names); if ($order_direction < 0) { $keys = array_reverse($keys); } return $query->order($this->id, $keys); }
protected function scope_ordered(Query $query, $direction = -1) { return $query->order('created ' . ($direction < 0 ? 'DESC' : 1)); }
/** * Alters the query with an order. * * The {@link $column_name} property is used. * * @param Query $query * @param int $order_direction "DESC" if inferior to 0, "ASC" otherwise. * * @return Query */ public function alter_query_with_order(Query $query, $order_direction) { return $query->order("`{$this->column_name}` " . ($order_direction < 0 ? 'DESC' : 'ASC')); }
/** * Adds a condition on the `status` field, which should equal {@link Comment::STATUS_SPAM}. * * @param Query $query * * @return Query */ protected function scope_spam(Query $query, $approved = true) { return $query->filter_by_status(Comment::STATUS_SPAM); }
public function alter_query_with_value(Query $query, $value) { $categories = \ICanBoogie\app()->models['categories']->select('`id` AS category_id, `slug` AS category_slug'); return $query->join($categories, ['on' => 'category_id'])->filter_by_category_slug($value); }