Esempio n. 1
0
  /**
   * Builds the necessary info to execute the query.
   */
  public function build(ViewExecutable $view) {
    // Make the query distinct if the option was set.
    if (!empty($this->options['distinct'])) {
      $this->setDistinct(TRUE);
    }

    // Store the view in the object to be able to use it later.
    $this->view = $view;

    $view->initPager();

    // Let the pager modify the query to add limits.
    $view->pager->query();

    $view->build_info['query'] = $this->query();
    $view->build_info['count_query'] = $this->query(TRUE);
  }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function build(ViewExecutable $view)
 {
     $this->view = $view;
     if ($this->shouldAbort()) {
         return;
     }
     // Setup the nested filter structure for this query.
     if (!empty($this->conditions)) {
         // If the different groups are combined with the OR operator, we have to
         // add a new OR filter to the query to which the filters for the groups
         // will be added.
         if ($this->group_operator === 'OR') {
             $base = $this->query->createConditionGroup('OR');
             $this->query->addConditionGroup($base);
         } else {
             $base = $this->query;
         }
         // Add a nested filter for each filter group, with its set conjunction.
         foreach ($this->conditions as $group_id => $group) {
             if (!empty($group['conditions']) || !empty($group['condition_groups'])) {
                 $group += array('type' => 'AND');
                 // For filters without a group, we want to always add them directly to
                 // the query.
                 $conditions = $group_id === '' ? $this->query : $this->query->createConditionGroup($group['type']);
                 if (!empty($group['conditions'])) {
                     foreach ($group['conditions'] as $condition) {
                         list($field, $value, $operator) = $condition;
                         $conditions->addCondition($field, $value, $operator);
                     }
                 }
                 if (!empty($group['condition_groups'])) {
                     foreach ($group['condition_groups'] as $nested_conditions) {
                         $conditions->addConditionGroup($nested_conditions);
                     }
                 }
                 // If no group was given, the filters were already set on the query.
                 if ($group_id !== '') {
                     $base->addConditionGroup($conditions);
                 }
             }
         }
     }
     // Initialize the pager and let it modify the query to add limits.
     $view->initPager();
     $view->pager->query();
     // Set the search ID, if it was not already set.
     if ($this->query->getOption('search id') == get_class($this->query)) {
         $this->query->setOption('search id', 'search_api_views:' . $view->storage->id() . ':' . $view->current_display);
     }
     // Add the "search_api_bypass_access" option to the query, if desired.
     if (!empty($this->options['bypass_access'])) {
         $this->query->setOption('search_api_bypass_access', TRUE);
     }
     // If the View and the Panel conspire to provide an overridden path then
     // pass that through as the base path.
     if (($path = $this->view->getPath()) && strpos(Url::fromRoute('<current>')->toString(), $this->view->override_path) !== 0) {
         $this->query->setOption('search_api_base_path', $path);
     }
 }