? views/image_gallery_handler_field_gallery_count.inc
? views/image_gallery_handler_field_gallery_latest.inc
Index: image_gallery.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/image/contrib/image_gallery/image_gallery.module,v
retrieving revision 1.31
diff -u -r1.31 image_gallery.module
--- image_gallery.module  17 Jan 2009 22:29:47 -0000  1.31
+++ image_gallery.module  20 Mar 2009 20:22:52 -0000
@@ -374,6 +374,12 @@
     'image_gallery' => array(
       'arguments' => array('galleries' => NULL, 'images' => NULL),
     ),
+    'image_gallery_count' => array(
+      'arguments' => array('count' => 0),
+    ),
+    'image_gallery_updated' => array(
+      'arguments' => array('timestamp' => 0),
+    ),
     'image_gallery_img' => array(
       'arguments' => array('image' => NULL, 'size' => NULL),
     ),
@@ -450,6 +456,20 @@
 }
 
 /**
+ * Theme the count of gallery items on a gallery list.
+ */
+function theme_image_gallery_count($count) {
+  return "There are $count images in this gallery.";
+}
+
+/**
+ * Theme the gallery last updated time on a gallery list.
+ */
+function theme_image_gallery_updated($timestamp) {
+  return '<p class="last">'. t('%date', array('%date' => format_date($timestamp))) ."</p>\n";
+}
+
+/**
  * Returns (and possibly creates) a new vocabulary for Image galleries.
  */
 function _image_gallery_get_vid() {
@@ -467,3 +487,13 @@
 
   return $vid;
 }
+
+/**
+ * Implementation of hook_views_api().
+ */
+function image_gallery_views_api() {
+  return array(
+    'api' => 2,
+    'path' => drupal_get_path('module', 'image_gallery') .'/views',
+  );
+}
Index: views/image_gallery.views.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/image/contrib/image_gallery/views/image_gallery.views.inc,v
retrieving revision 1.1
diff -u -r1.1 image_gallery.views.inc
--- views/image_gallery.views.inc 21 Mar 2009 00:52:59 -0000  1.1
+++ views/image_gallery.views.inc 20 Mar 2009 20:21:04 -0000
@@ -6,3 +6,62 @@
  * Image Gallery views integration.
  */
 
+/**
+ * Implementation of hook_views_data_alter().
+ * Add fields for image gallery (ie vocabulary terms) to the term_data table.
+ */
+function image_gallery_views_data_alter(&$data) {
+  // ----------------------------------------------------------------------
+  // Image gallery terms.
+  $data['term_data']['gallery_count'] = array(
+    'group' => t('Image gallery'),    
+    'field' => array(
+      'title' => t('Count'),
+      'help' => t('Count of items in a gallery.'),
+      'handler' => 'image_gallery_handler_field_gallery_count',
+    ),
+  );
+  $data['term_data']['gallery_latest_thumbnail'] = array(
+    'group' => t('Image gallery'),    
+    'field' => array(
+      'title' => t('Latest image'),
+      'help' => t('The most recently posted image in the gallery or its child galleries.'),
+      'handler' => 'image_gallery_handler_field_gallery_latest_thumbnail',
+    ),
+  );
+  $data['term_data']['gallery_latest_time'] = array(
+    'group' => t('Image gallery'),    
+    'field' => array(
+      'title' => t('Last updated'),
+      'help' => t('The updated time of the most recently posted image in the gallery or its child galleries.'),
+      'handler' => 'image_gallery_handler_field_gallery_latest_time',
+    ),
+  );
+}
+
+/**
+ * Implementation of hook_views_handlers().
+ */
+function image_gallery_views_handlers() {
+  return array(
+    'info' => array(
+      'path' => drupal_get_path('module', 'image_gallery') .'/views',
+    ),
+    'handlers' => array(
+      'image_gallery_handler_field_gallery_count' => array(
+        'parent' => 'views_handler_field_taxonomy',
+      ),
+      'image_gallery_handler_field_gallery_latest' => array(
+        'parent' => 'views_handler_field_taxonomy',
+      ),
+      'image_gallery_handler_field_gallery_latest_thumbnail' => array(
+        'parent' => 'image_gallery_handler_field_gallery_latest',
+        'file'   => 'image_gallery_handler_field_gallery_latest.inc',
+      ),
+      'image_gallery_handler_field_gallery_latest_time' => array(
+        'parent' => 'image_gallery_handler_field_gallery_latest',
+        'file'   => 'image_gallery_handler_field_gallery_latest.inc',
+      ),
+    ),
+  );
+}
--- contrib/image_gallery/views/image_gallery_handler_field_gallery_count.inc
+++ contrib/image_gallery/views/image_gallery_handler_field_gallery_count.inc
@@ -0,0 +1,31 @@
+<?php+// $Id$++/**+ * @file+ * Views handler for Image gallery count field.+ */++/**+ * TODO+ */+class image_gallery_handler_field_gallery_count extends views_handler_field_taxonomy {  +  /**+   * Override query() so we don't query: fake field.+   */+  function query() {+    $this->ensure_my_table();+    $this->add_additional_fields();+  }+  +  /**+   * Returns field html.+   */+  function render($values) {+    $count = taxonomy_term_count_nodes($values->tid, 'image');+    $output = theme('image_gallery_count', $count);+    return $this->render_link($output, $values);+  }++}+--- contrib/image_gallery/views/image_gallery_handler_field_gallery_latest.inc
+++ contrib/image_gallery/views/image_gallery_handler_field_gallery_latest.inc
@@ -0,0 +1,133 @@
+<?php+// $Id$++/**+ * @file+ * Views handlers for Image gallery recent image and data.+ * Views of galleries show a thumbnail of the image and data about when it was last updated.+ * This file has a common parent class for the query and node loading, and child handlers for presentation+ * of the different fields.+ */++/**+ * TODO+ */+class image_gallery_handler_field_gallery_latest extends views_handler_field_taxonomy {+  +  /**+   * Constructor to provide additional fields to add.+   */+  function construct() {+    parent::construct();+    +    $this->additional_fields['tid'] = 'tid';+  }  +  +  /**+   * Override query() so we don't query: fake field.+   */+  function query() {+    $this->ensure_my_table();+    $this->add_additional_fields();+  }+  +  /**+   * Run our own query to get the most recent image from the current gallery or its child galleries.+   */+   function get_latest_image_nid($tid) {+     $vid = _image_gallery_get_vid();++     $tree = taxonomy_get_tree($vid, $tid, -1);+     $descendant_tids = array_merge(array($tid), array_map('_taxonomy_get_tid_from_term', $tree));+     // The values of $descendant_tids should be safe for raw inclusion in the+     // SQL since they're all loaded from integer fields in the database.+     $sql = "SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN (". implode(',', $descendant_tids) .") AND n.type = 'image' AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC";+     if ($nid = db_result(db_query(db_rewrite_sql($sql)))) {+       return $nid;+     }+   }+  +  /**+   * Render: obtain the nid of the latest image.+   * This should be called by subclasses.+   */+  function render($values) {+    if (!$values->image_gallery_latest_nid) {+      $nid = $this->get_latest_image_nid($values->tid);+      // Stash the nid in the $values object so other fields that need this don't have to run the query again.+      $values->image_gallery_latest_nid = $nid;+    }+  }++} // class image_gallery_handler_field_gallery_latest++/**+ * Display a thumbnail of the latest image node, at the chosen derivative size.+ */+class image_gallery_handler_field_gallery_latest_thumbnail extends image_gallery_handler_field_gallery_latest {+  /**+   * Defines default values for options.+   */+  function option_definition() {+    $options = parent::option_definition();++    $options['image_derivative'] = array('default' => array(IMAGE_THUMBNAIL));+      +    return $options;+  }++  /**+   * Extends the field's basic options with more image specific+   * options.+   */+  function options_form(&$form, &$form_state) {+    parent::options_form($form, $form_state);++    foreach (image_get_sizes() as $key => $size) {+      $sizes[$key] = $size['label'];  +    }+    $form['image_derivative'] = array(+      '#type' => 'select',+      '#title' => t('Image size to show'),+      '#options' => $sizes,+      '#default_value' => $this->options['image_derivative'], +      '#description' => t('Pick an image derivative to display.')+    );  +  }++   +  /**+   * Returns field html.+   */+  function render($values) {+    // Call parent function to get our latest node nid.+    parent::render($values);+    +    $latest_node = node_load($values->image_gallery_latest_nid);+    $output = image_display($latest_node, $this->options['image_derivative']); +    return $this->render_link($output, $values);+  }++} // class image_gallery_handler_field_gallery_latest_thumbnail++/**+ * Show the last updated time for the gallery: the changed time of the latest node.+ */+class image_gallery_handler_field_gallery_latest_time extends image_gallery_handler_field_gallery_latest {+ +  /**+   * Returns field html.+   */+  function render($values) {+    // Call parent function to get our latest node nid.+    parent::render($values);+    +    $latest_node = node_load($values->image_gallery_latest_nid);        +    if ($latest_node->changed) {+      $output = theme('image_gallery_updated', $latest_node->changed);+      return $this->render_link($output, $values);+    }+  }++} // class image_gallery_handler_field_gallery_latest_time+