You are here

function image_attach_views_handler_field_attached_images::pre_render in Image 6

We don't add to the query (see the parent class). Instead, run our own query on pre-render. This is the same approach as CCK multiple fields.

File

contrib/image_attach/image_attach_views_handler_field_attached_images.inc, line 62

Class

image_attach_views_handler_field_attached_images
Field handler to display the attached images on a node.

Code

function pre_render(&$values) {
  $nids = array();
  foreach ($values as $v) {
    if (isset($v->{$this->aliases['image_attach_nid']})) {

      // Make the nid safe.
      $nid = intval($v->{$this->aliases['image_attach_nid']});

      // Use the nid as the key to make the values unique.
      $nids[$nid] = $nid;
    }
  }
  if (count($nids)) {
    $nids_string = implode(',', $nids);
    $result = db_query("SELECT nid, iid FROM {image_attach} WHERE nid IN (" . $nids_string . ") ORDER BY weight");
    while ($data = db_fetch_object($result)) {

      // Store all the attached image nids (iid) keyed by attaching nid.
      $attached_images[$data->nid][] = $data->iid;
    }

    // Place the data into the $values array for each result, beneath a
    // unique key in case this field is on the view several times.
    $this->handler_key = $this->options['id'];
    foreach ($values as $id => $v) {
      if (isset($attached_images[$v->{$this->aliases['image_attach_nid']}])) {
        $values[$id]->image_attach_iids[$this->handler_key] = $attached_images[$v->{$this->aliases['image_attach_nid']}];
      }
    }
  }
}