public function prepareQueryBeforeCount(xPDOQuery $c) { $c = parent::prepareQueryBeforeCount($c); $folders = array(startId); $where = array('id:in' => $this->getFolders((int) $this->getProperty('startId'), $folders), 'or:parent:in' => $this->getFolders((int) $this->getProperty('startId'), $folders)); $c->where($where); return $c; }
public function prepareQueryBeforeCount(xPDOQuery $c) { $c = parent::prepareQueryBeforeCount($c); $alias = $c->getAlias(); if ($this->getProperty('JoinParents')) { if ($this->getProperty('parent_joining_type') == 'inner') { $c->innerJoin('modResource', "Parent"); } else { $c->leftJoin('modResource', "Parent"); } } $where = array(); /* Поиск по тегам */ if ($tag = (int) $this->getProperty('tag')) { # $c->query['where'][] = new xPDOQueryCondition(array('sql' => "find_in_set('{$tag}', {$alias}.tags)")); $c->innerJoin("modResourceTag", "Tags", "Tags.tag_id = {$tag} AND Tags.resource_id = {$alias}.id"); # $where['Tags.tag_id'] = $tag; } // Поиск по автору if ($author = (int) $this->getProperty('author')) { $where["createdby"] = $author; } /* Поиск по датам */ if ($date_from = $this->getProperty('date_from')) { $time = strtotime($date_from); $c->where(array("createdon:>=" => $time, "OR:publishedon:>=" => $time)); } if ($date_till = $this->getProperty('date_till')) { $time = strtotime($date_till); $c->where(array("createdon:<=" => $time, "OR:publishedon:<=" => $time)); } /* По типу статей */ if ($article_type = (int) $this->getProperty('article_type')) { $where['article_type'] = $article_type; } /* Только топовые новости */ if ($this->getProperty('top_news_only')) { $where['top_news'] = '1'; } /* Только главные новости */ if ($this->getProperty('main_news_only')) { $where['main'] = '1'; } /* Только для новостной ленты */ if ($this->getProperty('in_news_list_only')) { $where['news_list'] = '1'; } /* Только для RSS */ if ($this->getProperty('in_rss_only')) { $where['rss'] = '1'; } /* По статусу Выберите из списка==||Пишется==0||На редакции==1||Опубликована==2||Скрыта==3||Просрочена==4 */ $article_status = $this->getProperty('article_status', null); if (is_numeric($article_status)) { switch ($article_status) { case '2': $where['published'] = 1; break; case '3': $where['hidemenu'] = 1; break; default: $where['article_status'] = $article_status; } } /* Только собственные статьи */ if ($this->getProperty('own_articles')) { $where['createdby'] = $this->modx->user->id; } /* Поиск по рубрикам */ if ($section = (int) $this->getProperty('section')) { $c->leftJoin("modResourceSection", "Section", "Section.resource_id = {$alias}.id AND Section.section_id = {$section}"); $c->where(array("parent" => $section, "OR:Section.id:!=" => null)); } // Поиск по запросу if ($query_string = $this->getProperty('query') or $query_string = $this->getProperty('query_string')) { # $c->where(array( # "id" => $query_string, # "OR:pagetitle:like" => "%{$query_string}%", # "OR:longtitle:like" => "%{$query_string}%", # # "OR:content:like" => "%{$query_string}%", # )); /* Обрабатываем поисковый запрос */ $searcher = $this->modx->getService('modSearch', 'modSearch', MODX_CORE_PATH . 'components/modsearch/model/modsearch/'); $lemmas = $searcher->textToLemmas($query_string); foreach ($lemmas as &$lemma) { $lemma = "{$lemma}"; } # unset($lemma); # # print_r($lemmas); # # exit; $indexes_table = $this->modx->getTableName('modSearchIndex'); /* Поиск по любому из слов */ # $sql = "EXISTS ( # SELECT NULL FROM {$indexes_table} WHERE {$indexes_table}.resource_id = {$alias}.id AND {$indexes_table}.lemma IN (". implode(", ", $lemmas) .") # )"; /* Поиск по всем словам */ # $sql = ''; $condition = array(); foreach ($lemmas as $lemma) { $quoted = $this->modx->quote("%{$lemma}%"); $condition[] = "{$indexes_table}.lemma LIKE {$quoted}"; } $sql = "EXISTS (\n SELECT NULL FROM {$indexes_table} \n WHERE {$indexes_table}.resource_id = {$alias}.id \n AND (" . implode(' OR ', $condition) . ")\n )"; $c->query['where'][] = new xPDOQueryCondition(array('sql' => $sql)); # $sql = "SELECT NULL FROM {$indexes_table} WHERE {$indexes_table}.resource_id = {$alias}.id"; # # foreach($lemmas as $lemma){ # $sql .= " AND {$indexes_table}.lemma = $lemma"; # } # # $sql = "EXISTS ( # {$sql} # )"; # # print_r($lemmas); # exit; # $c->select(array( # "{$alias}.*", # )); # # $c->select(array( # "{$alias}.id", # "{$alias}.pagetitle", # )); # $c->prepare(); # # print $c->toSQL(); # exit; } /* Скрытые с главной */ if (!$this->getProperty('show_hidden_on_mainpage')) { $where['hide_on_mainpage'] = '0'; } # if($this->modx->hasPermission('debug')){ # print_r($where); # } if ($where) { $c->where($where); } return $c; }