Index: views_handler_field_views_all_terms_image.inc =================================================================== --- views_handler_field_views_all_terms_image.inc (revision 0) +++ views_handler_field_views_all_terms_image.inc (revision 170) @@ -0,0 +1,168 @@ + ''); + $options['link_to_taxonomy'] = array('default' => FALSE); + $options['only_one_image'] = array('default' => FALSE); + $options['limit'] = array('default' => FALSE); + $options['vids'] = array('default' => array()); + + return $options; + } + + /** + * Build option configuration form. + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + $form['link_to_taxonomy'] = array( + '#title' => t('Link this image to its term page'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['link_to_taxonomy']), + ); + + $form['limit'] = array( + '#type' => 'checkbox', + '#title' => t('Limit term images by vocabulary'), + '#default_value'=> $this->options['limit'], + ); + + $voc_opts = array(); + $vocs = taxonomy_get_vocabularies(); + foreach ($vocs as $voc) { + $voc_opts[$voc->vid] = check_plain($voc->name); + } + + $form['vids'] = array( + '#prefix' => '
', + '#suffix' => '
', + '#type' => 'checkboxes', + '#title' => t('Vocabularies'), + '#options' => $voc_opts, + '#default_value' => $this->options['vids'], + '#process' => array('expand_checkboxes', 'views_process_dependency'), + '#dependency' => array('edit-options-limit' => array(TRUE)), + ); + + $form['only_one_image'] = array( + '#title' => t('If several images are available, show only one'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['only_one_image']), + ); + + // If ImageCache module is found, add its presets as available options + // for how to display the image. + if (module_exists('imagecache')) { + $raw_presets = imagecache_presets(); + $presets[''] = t('Default'); + foreach ($raw_presets as $preset_id => $preset_info) { + $preset = $preset_info['presetname']; + $presets[$preset] = $preset; + } + $form['imagecache_preset'] = array( + '#type' => 'select', + '#title' => t('ImageCache preset'), + '#options' => $presets, + '#default_value' => $this->options['imagecache_preset'], + ); + } + } + + /** + * Add node revision to the query + */ + function query() { + $alias_tid_1 = $this->aliases['all_tid']; + $base_table = $this->view->base_table == 'node_revisions' ? 'node_revisions' : 'node'; + $this->alias_revid = $this->query->add_field($base_table, 'vid'); + $this->alias_all_tids = $this->query->add_field(NULL, 0, 'all_tid_all_tids'); + $this->field_alias = $this->query->add_field(NULL, 0, 'all_tid'); + } + + /** + * Compute our virtual fields + */ + function pre_render($values) { + $revids = array(); + $all_tids = array(); + foreach ($values as $val) { + $revid = $val->{$this->alias_revid}; + if (!empty($revid)) { + $revids[] = $revid; + $all_tids[$revid] = array(); + } + } + + + if ($revids) { + $voc_clause = ""; + if (!empty($this->options['limit']) && !empty($this->options['vids'])) + $voc_clause = " AND td.vid IN (" . implode(', ', array_keys(array_filter($this->options['vids']))) . ")"; + + if ($this->options['only_one_image']) + $order_clause = " ORDER BY tn.tid DESC LIMIT 1"; + else + $order_clause = " ORDER BY tn.tid ASC"; + + $results = db_query("SELECT DISTINCT tn.vid as revid, ti.tid AS tid FROM {term_image} ti INNER JOIN {term_node} tn ON ti.tid = tn.tid INNER JOIN {term_data} td ON ti.tid = td.tid WHERE tn.vid IN (" . implode(', ', $revids) . ")" . $voc_clause . $order_clause); + + while ($res = db_fetch_object($results)) + $all_tids[$res->revid][] = $res->tid; + } + + foreach ($values as &$val) { + $revid = $val->{$this->alias_revid}; + if ($all_tids[$revid]) { + $tids = array_values($all_tids[$revid]); + $val->{$this->alias_all_tids} = $tids; + $val->{$this->field_alias} = $tids[0]; + } + else { + $val->{$this->alias_all_tids} = array(); + $val->{$this->field_alias} = NULL; + } + } + } + + /** + * Render field output to the browser. + */ + function render($value) { + $images = ''; + foreach ($value->{$this->alias_all_tids} as $tid) { + // Render image using ImageCache preset, if any. + if ($this->options['imagecache_preset']) + $image = taxonomy_image_display($tid, NULL, $this->options['imagecache_preset']); + else + $image = taxonomy_image_display($tid); + + // Output image as a link, if option is set. + if ($this->options['link_to_taxonomy']) + $image = l($image, drupal_get_path_alias(taxonomy_term_path(taxonomy_get_term($tid))), array('html' => TRUE)); + + $images .= $image; + } + + return $images; + } +} + Index: taxonomy_image.module =================================================================== --- taxonomy_image.module (revision 169) +++ taxonomy_image.module (working copy) @@ -736,19 +736,3 @@ 'path' => drupal_get_path('module', 'taxonomy_image'), ); } - -/** - * Implementation of hook_views_handlers(). - */ -function taxonomy_image_views_handlers() { - return array( - 'info' => array( - 'path' => drupal_get_path('module', 'taxonomy_image'), - ), - 'handlers' => array( - 'views_handler_field_taxonomy_image' => array( - 'parent' => 'views_handler_field', - ), - ), - ); -} Index: taxonomy_image.views.inc =================================================================== --- taxonomy_image.views.inc (revision 169) +++ taxonomy_image.views.inc (working copy) @@ -7,6 +7,26 @@ */ /** + * Implementation of hook_views_handlers(). + */ +function taxonomy_image_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'taxonomy_image'), + ), + 'handlers' => array( + 'views_handler_field_taxonomy_image' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_views_all_terms_image' => array( + 'parent' => 'views_handler_field', + ), + ), + ); +} + + +/** * Implementation of hook_views_data(). */ function taxonomy_image_views_data() { @@ -37,6 +57,14 @@ 'handler' => 'views_handler_field_taxonomy_image', ), ); + + $data['term_image']['all_tid'] = array( + 'title' => t('All Terms images'), + 'help' => t("All images associated with related taxonomy terms."), + 'field' => array( + 'handler' => 'views_handler_field_views_all_terms_image', + ), + ); return $data; }