image_attach_views_handler_field_attached_images.inc in Image 6
File
contrib/image_attach/image_attach_views_handler_field_attached_images.inc
View source
<?php
class image_attach_views_handler_field_attached_images extends image_handler_field_image_node_image {
function construct() {
parent::construct();
$this->additional_fields['image_attach_nid'] = array(
'table' => 'node',
'field' => 'nid',
);
}
function option_definition() {
$options = parent::option_definition();
$options['as_link'] = array(
'default' => 'none',
);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['as_link'] = array(
'#type' => 'select',
'#title' => t('Link'),
'#options' => array(
'none' => t('No link'),
'node' => t('Node'),
'image' => t('Image node'),
),
'#default_value' => $this->options['as_link'],
);
}
function pre_render(&$values) {
$nids = array();
foreach ($values as $v) {
if (isset($v->{$this->aliases['image_attach_nid']})) {
$nid = intval($v->{$this->aliases['image_attach_nid']});
$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)) {
$attached_images[$data->nid][] = $data->iid;
}
$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']}];
}
}
}
}
function render($values) {
if (isset($values->image_attach_iids[$this->handler_key])) {
foreach ($values->image_attach_iids[$this->handler_key] as $iid) {
$image_nodes[$iid] = node_load($iid);
}
$options = array(
'size' => $this->options['image_derivative'],
'link' => $this->options['as_link'],
);
$output = theme('image_attach_attached_images', $values->{$this->aliases['image_attach_nid']}, $image_nodes, $options);
return $output;
}
}
}