You are here

public function media_browser_plus_views_handler_area_navigation::query in Media Browser Plus 7.3

Add folder filter to the query.

Overrides views_handler_area::query

File

views/media_browser_plus_views_handler_area_navigation.inc, line 55
Definition of media_browser_plus_views_handler_area_navigation.

Class

media_browser_plus_views_handler_area_navigation
MBP navigation handler.

Code

public function query() {
  $root_folder = media_browser_plus_get_media_root_folder();
  if (!empty($this->view->exposed_data['mbp_current_folder'])) {
    $this->value = (int) $this->view->exposed_data['mbp_current_folder'];
    user_cookie_save(array(
      'mbp.current_folder' => $this->value,
    ));
  }
  elseif (!empty($_COOKIE['Drupal_visitor_mbp_current_folder']) && (int) $_COOKIE['Drupal_visitor_mbp_current_folder'] > 0) {
    $this->value = (int) $_COOKIE['Drupal_visitor_mbp_current_folder'];
  }
  else {
    $this->value = $root_folder->tid;
  }
  $this
    ->ensure_my_table();
  $where_group = 1;

  // Ensure folders is always an array.
  $folders = array(
    $this->value,
  );

  // If including subfolders is enabled fetch all child terms of the current
  // folder.
  if (isset($this->view->exposed_data['mbp_current_folder_include_subfolders']) && $this->view->exposed_data['mbp_current_folder_include_subfolders'] !== 0) {
    $taxonomy_tree = taxonomy_get_tree(taxonomy_vocabulary_machine_name_load('media_folders')->vid, $this->value);
    if (is_array($taxonomy_tree)) {
      foreach ($taxonomy_tree as $term) {
        $folders[] = (int) $term->tid;
      }
    }
  }

  // If this is the root folder also show files without a folder.
  if ($this->value == $root_folder->tid) {

    // Add new where group to use OR condition.
    $where_group = $this->query
      ->set_where_group('OR');
    $this->query
      ->add_where($where_group, "{$this->table_alias}.{$this->real_field}", $this->value, 'IS NULL');
  }
  $this->query
    ->add_where($where_group, "{$this->table_alias}.{$this->real_field}", $folders, 'IN');
}