/[drupal]/contributions/modules/eventfinder_filter/eventfinder_filter.module
ViewVC logotype

Contents of /contributions/modules/eventfinder_filter/eventfinder_filter.module

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


Revision 1.1 - (show annotations) (download) (as text)
Wed Mar 1 10:11:17 2006 UTC (3 years, 9 months ago) by grugnog
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-php
Moving active_profiles, arooga, eventfinder_filter and userpoints_levels from sandbox to modules
1 <?php
2
3 // $Id: eventfinder_filter.module
4
5 /**
6 * Implementation of hook_help().
7 */
8 function eventfinder_filter_help($section) {
9 $output = '';
10 switch ($section) {
11 case 'admin/modules#description' :
12 $output = t('A URL interface to events. Generates filtered, sorted list of events from URL parameters.');
13 break;
14 }
15 return $output;
16 }
17
18 /**
19 * Menu callback; A URL interface to events. Generates filtered, sorted list of events from URL parameters.
20 *
21 * URLs have the following format:
22 * /eventfinder/filter/tid?start=date&finish=date&sort=direction
23 *
24 * Where:
25 * tid is the taxonomy id of the events you want to list; multiple tids (tidA OR tidB) can be separated by + symbols
26 * date is a date in strtotime date format; underscores can be used instead of spaces
27 * direction is either asc or desc (for ascending or decending order) of event_start
28 *
29 * Defaults:
30 * start: defaults to two hours prior to now
31 * finish: defaults to no limit
32 * direction: defaults to ascending (i.e. chronological order)
33 *
34 * Examples:
35 * /eventfinder/filter/582?finish=+1_year&sort=desc
36 * Show all events with tid 582 for the next year in descending order
37 * /eventfinder/filter/337+582?start=20050801&finish=20050831
38 * Show all events with tid 337 OR tid 582 for August 2005
39 */
40 function eventfinder_filter_page($str_tids = '', $depth = 0, $op = 'page') {
41 global $user;
42
43 //Setup defaults and parse time parameters
44 $starttime = 'AND e.event_start >= '._event_user_time(); // For two hours, we display "NOW"
45 $finishtime = ''; // No limit
46 if ($_GET['start']) {
47 $start = strtotime(str_replace('_', ' ', $_GET['start']));
48 if ($start != -1)
49 $starttime = 'AND e.event_start >= '.$start; // If we have a valid time, use it
50 }
51 if ($_GET['finish']) {
52 $finish = strtotime(str_replace('_', ' ', $_GET['finish']));
53 if ($finish != -1)
54 $finishtime = 'AND e.event_start <= '.$finish; // If we have a valid time, use it
55 }
56
57 if ($_GET['sort'] == 'desc') {
58 $order_sql = 'ORDER BY e.event_start DESC';
59 } else {
60 $order_sql = 'ORDER BY e.event_start ASC';
61 }
62
63 $title = t('Browsing ');
64 //Parse and test the tids, create title
65 if (preg_match('/^([0-9]+[+ ])*[0-9]+$/', $str_tids) || $str_tids == '') {
66 $tids = preg_split('/[+ ]/', $str_tids);
67 $term = null;
68 foreach ($tids as $tid) {
69 if ($term)
70 $title .= t(' and '); // If $term exists then we have multiple tids
71 $term = taxonomy_get_term($tid);
72 $title .= $term->name;
73 }
74 $str_tids = implode(',', $tids);
75 } else { // Prevent SQL injection
76 drupal_not_found();
77 }
78 if ($str_tids != '') { // Only look at tids if we need to (avoid join with zero set)
79 $wheretids = 'tn.tid IN ('.$str_tids.') AND ';
80 $jointids = 'INNER JOIN {term_node} tn ON n.nid = tn.nid ';
81 }
82 $title .= t(' Events');
83
84 // We have all the information we need - now we build the query and fire it off (pager style!)
85 $sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created, e.event_start FROM {node} n '.$jointids.'INNER JOIN {event} e ON n.nid = e.nid WHERE '.$wheretids.'n.status = 1 AND n.moderate = 0 '.$starttime.' '.$finishtime.' '.$order_sql;
86 //$output .= $sql; // Debug
87 $sql = db_rewrite_sql($sql);
88 $result = pager_query($sql, variable_get('default_nodes_main', 10), 0);
89
90 if (db_num_rows($result) > 0) {
91 while ($node = db_fetch_object($result)) {
92 //$output .= node_view(node_load(array('nid' => $node->nid)), 1); // This doesn't theme properly
93 $node = node_load(array ('nid' => $node->nid));
94 $output .= eventfinder_view($node);
95
96 }
97 $output .= theme('pager', NULL, variable_get('default_nodes_main', 10), 0, $_GET);
98 } else {
99 $output .= t('There are currently no events in this category.');
100 }
101
102 drupal_set_title($title);
103 print theme('page', $output);
104 }
105
106 /**
107 *
108 * Returns information for taxonomy searches
109 *
110 * @ingroup eventfinder_data
111 * @return data for drop down
112 *
113 */
114 function eventfinder_filter_taxonomy_tids () {
115 if (module_exist('taxonomy')) {
116 $types = event_get_types();
117 $vs = array();
118 foreach($types['all'] as $type) {
119 $results = taxonomy_get_vocabularies($type);
120 foreach($results as $vocab) {
121 $vs[$vocab->vid] = $vocab;
122 }
123 }
124 $results = null;
125 foreach($types['solo'] as $type) {
126 $results = taxonomy_get_vocabularies($type);
127 foreach($results as $vocab) {
128 $vs[$vocab->vid] = $vocab;
129 }
130 }
131 $items['all'] = '(all)';
132 foreach($vs as $vid => $vocab) {
133 $tree = taxonomy_get_tree($vid);
134 foreach ($tree as $term) {
135 $items[$term->tid] = $vocab->name.' - '.$term->name;
136 }
137 }
138 }
139 return $items;
140 }
141
142 /**
143 * Admin interface for eventfinder_filter - allows users to build and test an event filtering URL
144 */
145 function eventfinder_filter_admin() {
146 global $base_url;
147
148 drupal_set_html_head('<script language="javascript" src="'.drupal_get_path('module', 'eventfinder_filter').'/common.js"></script>');
149
150 $options = array ();
151 $items = array ();
152 $attributes = array ('onChange' => 'createurl()', 'onKeyUp' => 'createurl()');
153
154 $items = eventfinder_filter_taxonomy_tids();
155 $description = 'Choose the Taxonomy Vocabulary Term(s) for the filter (hold CTRL to select more than one)';
156 $group .= form_select('Terms', 'event_filter_terms', NULL, $items, $description, drupal_attributes($attributes), TRUE);
157 $output .= form_group('Taxonomy Terms', $group);
158
159 $description = 'Enter the date to show events <em>from</em> in the following format:
160 <ul><li>A regular date, in the format YYYYMMDD (e.g. 20051207)</li>
161 <li>A date relative to now (e.g. +1 day, -2 week, +5 month or -1 year)</li>
162 <li>Leave this blank to start listing events from now</li></ul>';
163 $group = form_textfield('From Date', 'event_filter_start', '', 10, 9, $description, $attributes);
164 $description = 'Enter the date to show events <em>until</em> in the following format:
165 <ul><li>A regular date, in the format YYYYMMDD (e.g. 20051207)</li>
166 <li>A date relative to now (e.g. +1 day, -2 week, +5 month or -1 year)</li>
167 <li>Leave this blank to list all events after the from date</li></ul>';
168 $group .= form_textfield('Until Date', 'event_filter_finish', '', 10, 9, $description, $attributes);
169
170 $group .= '<div class="form-item"><label>Sort Order:</label><br />
171 <label class="option"><input class="form-radio" name="edit[sort]" value="asc" checked="checked" onchange="createurl()" id="edit-eventfilter_asc" onkeyup="createurl()" type="radio"> Ascending Order</label><br />
172 <label class="option"><input class="form-radio" name="edit[sort]" value="desc" onchange="createurl()" onkeyup="createurl()" id="edit-eventfilter_desc" type="radio"> Descending Order</label></div>';
173 $output .= form_group('Filter and Sort by Date', $group);
174
175 $output .= '<input name="edit[eventfilter_filterurl]" id="edit-eventfilter_filterurl" value="'.$base_url.'/eventfinder/filter/" type="hidden">';
176
177 $description = t('This is the URL to the filter you specified above. Copy it and paste where you want the link.<br />(Note - you don\'t need to type in this box: use the form above to create the URL!)');
178 $group = form_textfield('Filter Link', 'event_filter_link', $base_url.'/eventfinder/filter', 60, '', $description);
179 $group .= '<input value="Test this URL" onClick="testurl()" type="button">';
180 $output .= form_group('Filter Link', $group);
181
182 print theme('page', $output);
183 }
184
185 /**
186 * Implementation of hook_menu().
187 */
188 function eventfinder_filter_menu($may_cache) {
189 $items = array();
190 if ($may_cache) {
191 $items[] = array('path' => 'admin/eventfinder/eventfinder_filter',
192 'title' => t('eventfinder filter admin'),
193 'callback' => 'eventfinder_filter_admin',
194 'access' => user_access('admin eventfinder')
195 );
196 $items[] = array('path' => 'eventfinder/filter',
197 'title' => t('filtered events'),
198 'callback' => 'eventfinder_filter_page',
199 'access' => user_access('search eventfinder'),
200 'type' => MENU_CALLBACK
201 );
202 }
203 drupal_set_html_head(eventfinder_html_head());
204 return $items;
205 }
206 ?>

  ViewVC Help
Powered by ViewVC 1.1.2