You are here

public function FacetapiDependencyBundle::execute in Facet API 7.2

Same name and namespace in other branches
  1. 6.3 plugins/facetapi/dependency_bundle.inc \FacetapiDependencyBundle::execute()
  2. 7 plugins/facetapi/dependency_bundle.inc \FacetapiDependencyBundle::execute()

Implements FacetapiDependency::execute().

Overrides FacetapiDependency::execute

File

plugins/facetapi/dependency_bundle.inc, line 24
The bundle dependency class.

Class

FacetapiDependencyBundle
Dependency plugin adding bundle conditions.

Code

public function execute() {
  switch ($this->settings['bundle']) {
    case 'referenced':

      // @todo Do we need defensive coding here?
      $field_info = field_info_field($this->facet['field api name']);

      // Iterate over field info, collect bundles this field is attached to.
      $field_bundles = array();
      foreach ($field_info['bundles'] as $entity => $bundles) {
        $field_bundles[$entity] = array_flip($bundles);
      }

      // Check match between the field's bundles and active bundle items.
      foreach ($this
        ->getEnabledBundleFacets() as $facet) {
        foreach ($facet['field api bundles'] as $entity) {
          $bundles = isset($field_bundles[$entity]) ? $field_bundles[$entity] : array();
          if (array_intersect_key($this->activeItems[$facet['name']], $bundles)) {
            return NULL;
          }
        }
      }

      // There was no match.
      return FALSE;
    case 'selected':

      // Check match between selected bundles and active bundle items.
      $selected = array_filter($this->settings['bundle_selected']);
      foreach ($this
        ->getEnabledBundleFacets() as $facet) {
        if (array_intersect_key($this->activeItems[$facet['name']], $selected)) {
          return NULL;
        }
      }

      // There was no match.
      return FALSE;
  }
}