You are here

function views_plugin_style_swftools::query in SWF Tools 6.3

Modifies the basic query to accommodate the case where there is not a thumbnail for every item of content.

File

views/views_plugin_style_swftools.inc, line 20
Defines the SWF Tools Views plug-in.

Class

views_plugin_style_swftools
Style plugin to render each item in an ordered or unordered list.

Code

function query() {

  // Initialise two work variables
  $deltas = array();
  $thumbnail = '';

  // Iterate over the fields in this query
  foreach ($this->view->field as $field => $info) {

    // Deltas are used to cross check files and thumbnails - capture them
    // TODO: Is this a valid assumption? Could be made configurable via options?
    if (strpos($field, 'delta') === 0) {
      $deltas[] = $info->table_alias . '.' . $info->field;
    }

    // When we find the field being used for thumbnails capture that too
    if ($info->field == $this->options['image']) {

      //        dsm($info);
      $thumbnail = $info->table_alias . '.' . $info->field;
    }
  }

  // If we have two deltas then we can modify the query to fetch
  // only those items where the file and thumbnail deltas match, or
  // where the thumbnail is not defined (null, zero or empty string)
  if (count($deltas) == 2) {

    // Basic WHERE to match deltas
    $where = $deltas[0] . ' = ' . $deltas[1];

    // Additional WHERE to match empty / null thumbnails
    if ($thumbnail) {
      $where = '(' . $where . ') OR ' . $thumbnail . ' IS NULL OR ' . $thumbnail . ' = \'\' OR ' . $thumbnail . ' = 0';
    }

    // Attach the WHERE to the basic query
    $this->view->query
      ->add_where(0, $where);
  }

  //    dsm($this->view->query);
}