예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     /** @var \Drupal\core_search_facets\Plugin\CoreSearchFacetSourceInterface $facet_source */
     $facet_source = $this->facet->getFacetSource();
     $query_info = $facet_source->getQueryInfo($this->facet);
     /** @var \Drupal\core_search_facets\FacetsQuery $facet_query */
     $facet_query = $facet_source->getFacetQueryExtender();
     $tables_joined = [];
     // Add the filter to the query if there are active values.
     $active_items = $this->facet->getActiveItems();
     foreach ($active_items as $item) {
         foreach ($query_info['fields'] as $field_info) {
             // Adds join to the facet query.
             $facet_query->addFacetJoin($query_info, $field_info['table_alias']);
             // Adds join to search query, makes sure it is only added once.
             if (isset($query_info['joins'][$field_info['table_alias']])) {
                 if (!isset($tables_joined[$field_info['table_alias']])) {
                     $tables_joined[$field_info['table_alias']] = TRUE;
                     $join_info = $query_info['joins'][$field_info['table_alias']];
                     $this->query->join($join_info['table'], $join_info['alias'], $join_info['condition']);
                 }
             }
             // Adds facet conditions to the queries.
             $field = $field_info['table_alias'] . '.' . $field_info['field'];
             $this->query->condition($field, $item);
             $facet_query->condition($field, $item);
         }
     }
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     /** @var \Drupal\facets\Utility\FacetsDateHandler $date_handler */
     $date_handler = \Drupal::getContainer()->get('facets.utility.date_handler');
     /** @var \Drupal\core_search_facets\Plugin\CoreSearchFacetSourceInterface $facet_source */
     $facet_source = $this->facet->getFacetSource();
     // Gets the last active date, bails if there isn't one.
     $active_items = $this->facet->getActiveItems();
     if (!($active_item = end($active_items))) {
         return;
     }
     // Gets facet query and this facet's query info.
     /** @var \Drupal\core_search_facets\FacetsQuery $facet_query */
     $facet_query = $facet_source->getFacetQueryExtender();
     $query_info = $facet_source->getQueryInfo($this->facet);
     $tables_joined = [];
     $active_item = $date_handler->extractActiveItems($active_item);
     foreach ($query_info['fields'] as $field_info) {
         // Adds join to the facet query.
         $facet_query->addFacetJoin($query_info, $field_info['table_alias']);
         // Adds join to search query, makes sure it is only added once.
         if (isset($query_info['joins'][$field_info['table_alias']])) {
             if (!isset($tables_joined[$field_info['table_alias']])) {
                 $tables_joined[$field_info['table_alias']] = TRUE;
                 $join_info = $query_info['joins'][$field_info['table_alias']];
                 $this->query->join($join_info['table'], $join_info['alias'], $join_info['condition']);
             }
         }
         // Adds field conditions to the facet and search query.
         $field = $field_info['table_alias'] . '.' . $field_info['field'];
         $this->query->condition($field, $active_item['start']['timestamp'], '>=');
         $this->query->condition($field, $active_item['end']['timestamp'], '<');
         $facet_query->condition($field, $active_item['start']['timestamp'], '>=');
         $facet_query->condition($field, $active_item['end']['timestamp'], '<');
     }
 }