/[drupal]/contributions/modules/node_images/node_images.views.inc
ViewVC logotype

Contents of /contributions/modules/node_images/node_images.views.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Sat Feb 3 01:28:22 2007 UTC (2 years, 9 months ago) by stefano73
Branch: MAIN
CVS Tags: DRUPAL-6--2-1, HEAD
Branch point for: DRUPAL-5--3, DRUPAL-4-7--2, DRUPAL-6--2
Changes since 1.2: +17 -7 lines
File MIME type: text/x-php
Views filtering with inner join.
1 <?php
2 // $Id: node_images.views.inc,v 1.2 2007/02/02 19:38:34 stefano73 Exp $
3
4 /**
5 * @file
6 * Views API hook implementations for the node_images module.
7 */
8
9 function _node_images_views_tables() {
10 $tables['node_images'] = array(
11 'name' => 'node_images',
12 'provider' => 'internal',
13 'join' => array(
14 'left' => array(
15 'table' => 'node',
16 'field' => 'nid'
17 ),
18 'right' => array(
19 'field' => 'nid'
20 ),
21 ),
22 'fields' => array(
23 'node_images_display' => array(
24 'name' => t('Node Images: Display node images'),
25 'notafield' => TRUE,
26 'query_handler' => '_node_images_query_handler_display',
27 'handler' => array(
28 '_node_images_views_handler_image_thumb' => t('Thumbnails'),
29 '_node_images_views_handler_image_fullsize' => t('Full size'),
30 ),
31 'sortable' => false,
32 'help' => t('Display all node images in one field.'),
33 ),
34 ),
35 'filters' => array(
36 'nid' => array(
37 'name' => t('Node images: Has node images'),
38 'operator' => array('=' => t('Exists')),
39 'list' => 'views_handler_operator_yesno',
40 'list-type' => 'select',
41 'handler' => '_node_images_handler_images_exist',
42 'help' => t('Filter whether the node has node images.'),
43 ),
44 ),
45 );
46 return $tables;
47 }
48
49 function _node_images_query_handler_display($field, $fieldinfo, &$query) {
50 $query->add_field('nid', 'node');
51 }
52
53 /**
54 * Views handler for displaying images.
55 */
56 function _node_images_views_handler_image_thumb($fieldinfo, $fielddata, $value, $data, $thumb = TRUE) {
57 $node = node_load(array('nid' => $data->nid));
58 $format = ($thumb ? 'thumbs' :'fullsize');
59 return theme('node_images_view', $node, TRUE, FALSE, $format);
60 }
61
62 /**
63 * Views handler for displaying images in links to a popup window
64 */
65 function _node_images_views_handler_image_fullsize($fieldinfo, $fielddata, $value, $data) {
66 return _node_images_views_handler_image_thumb($fieldinfo, $fielddata, $value, $data, FALSE);
67 }
68
69 /**
70 * Views handler for filtering
71 */
72 function _node_images_handler_images_exist($op, $filter, $filterdata, &$query) {
73 switch ($op) {
74 case 'handler':
75 $query->ensure_table('node_images');
76 if ($filter['value']) {
77 $query->set_distinct();
78 $table_data = _views_get_tables();
79 $joins = array('type' => 'inner');
80 $joins = array_merge($joins, $table_data['node_images']['join']);
81 $query->joins['node_images'][1] = $joins;
82 }
83 else {
84 $query->add_where('ISNULL(node_images.id)');
85 }
86 }
87 }

  ViewVC Help
Powered by ViewVC 1.1.2