/[drupal]/contributions/modules/tapatio/comms_views.inc
ViewVC logotype

Contents of /contributions/modules/tapatio/comms_views.inc

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


Revision 1.1 - (show annotations) (download) (as text)
Sat Dec 6 00:37:32 2008 UTC (11 months, 2 weeks ago) by evoltech
Branch: MAIN
CVS Tags: DRUPAL-5--1-0, HEAD
Branch point for: DRUPAL-5, DRUPAL-5--2
File MIME type: text/x-php
This is the initial check in of the files for the tapatio project
1 <?php
2 // $Id$
3
4 /*
5 * @file
6 * implements all of the views for the comms module
7 *
8 * TODO: add (D:<time>) next to title if dispatched
9 * TODO: building views with views_ui needs to be tested
10 * TODO: create support for views2
11
12 */
13
14
15 /**
16 * Implementation of hook_views_arguments()
17 * This will allow the system to pass url arguments that will be handled by
18 * the comms system.
19 */
20 function comms_views_arguments() {
21 if (variable_get('comms_debuglevel', 0) > 0) {
22 drupal_set_message("comms_views_arguments()");
23 }
24
25 $arguments['comms_minutes'] = array(
26 'name' => t('Comms: minutes'),
27 'help' => t('The time frame (in minutes) to view comms nodes'),
28 'handler' => 'comms_handler_arg_minutes'
29 );
30
31 $arguments['comms_vote'] = array(
32 'name' => t('Comms: vote'),
33 'help' => t('The rating to filter Comms nodes by'),
34 'handler' => 'comms_handler_arg_vote'
35 );
36
37 $arguments['comms_dispatch'] = array(
38 'name' => t('Comms: dispatch'),
39 'help' => t('Weather or not the node has been disatched or not'),
40 'handler' => 'comms_handler_arg_dispatch'
41 );
42
43 $arguments['comms_priority'] = array(
44 'name' => t('Comms: priority'),
45 'help' => t('The priority assigned to the node'),
46 'handler' => 'comms_handler_arg_priority'
47 );
48
49 $arguments['comms_categorized'] = array(
50 'name' => t('Comms: categorized'),
51 'help' => t('Wether or not a comms node has been categorized yet'),
52 'handler' => 'comms_handler_arg_categorized'
53 );
54
55 return $arguments;
56 }
57
58 //the handler for the comms_group
59 function comms_handler_field_comms_group_nodelink($op, &$query, $a1, $a2 = NULL) {
60 if (variable_get('comms_debuglevel', 0) > 0) {
61 drupal_set_message("comms_handler_field_comms_group_nodelink()");
62 }
63
64 switch ($op) {
65 //TODO: how do I implement this? When is it used?
66 case 'sort':
67 return $fieldinfo;
68 break;
69
70 //TODO: how do I implement this? When is it used?
71 case 'summary':
72 return $fieldinfo;
73 break;
74
75 case 'filter':
76 if ($a2 != 'NULL' && strtolower($a2) != 'all') {
77 if ($a2 == 0) {
78 $query->add_where('{node}.nid not in (select nid from {comms_group_dispatch})');
79 }
80 else if ($a2 == 1) {
81 $query->add_where('{node}.nid in (select nid from {comms_group_dispatch})');
82 }
83 }
84 break;
85
86 //TODO: where does created get set from?
87 case 'link':
88 break;
89
90 case 'title':
91 if (strtolower($query) == 'all') {
92 $return = t('or have not ');
93 }
94 else if ($query == 0) {
95 $return = t('not ');
96 }
97 else {
98 $return = '';
99 }
100 return $return;
101 break;
102 }
103 }//comms_handler_field_comms_group_nodelink
104
105 //the handler for the comms_dispatched argument
106 function comms_handler_arg_dispatch($op, &$query, $a1, $a2 = NULL) {
107 if (variable_get('comms_debuglevel', 0) > 0) {
108 drupal_set_message("comms_handler_arg_dispatch()");
109 }
110
111 switch ($op) {
112 //TODO: how do I implement this? When is it used?
113 case 'sort':
114 return $fieldinfo;
115 break;
116
117 //TODO: how do I implement this? When is it used?
118 case 'summary':
119 return $fieldinfo;
120 break;
121
122 case 'filter':
123 if (!is_NULL($a2) && strcmp(strtolower($a2), 'all') != 0) {
124 //the 'not' here is a special situation we are using for "comms/search"
125 if ($a2 == 0 || strcmp($a2, 'not') == 0) {
126 $query->add_where('{node}.nid not in (select nid from {comms_group_dispatch})');
127 }
128 else if ($a2 == 1) {
129 $query->add_where('{node}.nid in (select nid from {comms_group_dispatch})');
130 }
131 }
132 break;
133
134 //TODO: where does created get set from?
135 case 'link':
136 break;
137
138 case 'title':
139 if (strtolower($query) === 'all') {
140 $return = t('or have not ');
141 }
142 else if ($query == 0) {
143 $return = 'not ';
144 //this is a special situation we are using for "comms/search"
145 }
146 else if (strcmp($query, 'not') == 0) {
147 $return = t('not ');
148 }
149 else {
150 $return = '';
151 }
152 return $return;
153 break;
154 }
155 }//comms_handler_arg_dispatch
156
157 function comms_handler_arg_categorized($op, &$query, $a1, $a2 = NULL) {
158 if (variable_get('comms_debuglevel', 0) > 0) {
159 drupal_set_message("comms_handler_arg_categorized()");
160 }
161
162 switch ($op) {
163 //TODO: how do I implement this? When is it used?
164 case 'sort':
165 return $fieldinfo;
166 break;
167
168 //TODO: how do I implement this? When is it used?
169 case 'summary':
170 return $fieldinfo;
171 break;
172
173 //we want to check here to see if any of the nodes have not been
174 //assigned to groups yet and that they have not been assigned
175 //priorities
176 case 'filter':
177 if ($a2 === 0 || strcmp($a2, 'not') == 0) {
178 $query->ensure_table('term_node');
179 $query->add_where('{term_node}.tid is NULL');
180
181 }
182 else if ($a2 == 1) {
183 $query->ensure_table('term_node');
184 $query->add_where('{term_node}.tid is not NULL');
185 }
186 break;
187
188 //TODO: where does created get set from?
189 case 'link':
190 break;
191
192 case 'title':
193 if (strtolower($query) == 'all') {
194 return t('has or has not been categorized');
195 }
196 else if ($query == 1) {
197 return t('has been categorized');
198 }
199 else {
200 return t('has not been categorized');
201 }
202 break;
203 }
204 }//comms_handler_arg_categorized
205
206 //the handler for the comms_priority argument
207 function comms_handler_arg_priority($op, &$query, $a1, $a2 = NULL) {
208 if (variable_get('comms_debuglevel', 0) > 0) {
209 drupal_set_message("comms_handler_arg_priority()");
210 }
211
212 switch ($op) {
213 //TODO: how do I implement this? When is it used?
214 case 'sort':
215 return $fieldinfo;
216 break;
217
218 //TODO: how do I implement this? When is it used?
219 case 'summary':
220 return $fieldinfo;
221 break;
222
223 case 'filter':
224 if ($a2 != 'NULL' && strtolower($a2) != 'all') {
225 $query->ensure_table('comms_priority');
226 $query->add_where('{term_data}.name = \'%s\'', $a2);
227 }
228 break;
229
230 //TODO: where does created get set from?
231 case 'link':
232 break;
233
234 case 'title':
235 if (strtolower($query) == 'all') {
236 return t('any priority');
237 }
238 else {
239 return t('a priority of @value', array('@value' => $query));
240 }
241 break;
242 }
243 }//comms_handler_arg_priority
244
245 function comms_handler_filter_vote_function($op, $filter, $filterinfo, &$query) {
246 if (variable_get('comms_debuglevel', 0) > 0) {
247 drupal_set_message("comms_handler_filter_vote_function()");
248 }
249
250 $table = $filterinfo['table'];
251 $column = $filterinfo['field'];
252 $field = "$table.$column";
253 $query->ensure_table($table);
254 $query->add_where("%s %s '%s' OR %s is NULL", $field, $filter['operator'], $filter['value'], $field);
255 }//comms_handler_filter_vote_function()
256
257 //TODO: test this
258 function comms_handler_filter_vote($op, $filter, $filterinfo, &$query) {
259 if (variable_get('comms_debuglevel', 0) > 0) {
260 drupal_set_message("comms_handler_filter_vote()");
261 }
262
263 $table = $filterinfo['table'];
264 $column = $filterinfo['field'];
265 $field = "$table.$column";
266 $query->ensure_table($table);
267 $query->add_where("%s %s %d", $field, $filter['operator'], $filter['value']);
268 }//comms_handler_filter_vote()
269
270 //the handler for the comms_vote argument
271 function comms_handler_arg_vote($op, &$query, $a1, $a2 = NULL) {
272 if (variable_get('comms_debuglevel', 0) > 0) {
273 drupal_set_message("comms_handler_arg_vote()");
274 }
275
276 //can we pass this off to votingapi_handler_filter_value?
277 switch ($op) {
278 //TODO: how do I implement this? When is it used?
279 case 'sort':
280 return $fieldinfo;
281 break;
282
283 //TODO: how do I implement this? When is it used?
284 case 'summary':
285 return $fieldinfo;
286 break;
287
288 case 'filter':
289 $query->ensure_table('comms_vote');
290
291 //there is a special case here when the value of $a2 is zero
292 //this means all nodes which have not recieved a vote yet
293 if ($a2 === 0) {
294 //we don't need to add function='sum' here because there will
295 //be no rows for this content_id if it has not been voted on
296 //yet
297 $query->add_where('comms_vote.value is NULL');
298 }
299 else if (strcmp(strtolower($a2), 'all') == 0) {
300 $query->add_where('comms_vote.function=\'sum\' OR comms_vote.value is NULL');
301 }
302 else {
303 $query->add_where('comms_vote.function=\'sum\' AND comms_vote.value = %d', $a2);
304 }
305 break;
306
307 //TODO: where does created get set from?
308 case 'link':
309 break;
310
311 case 'title':
312 if (strtolower($query) == 'all') {
313 return t('any vote');
314 }
315 else if ($query == 0) {
316 return t('no vote');
317 }
318 else {
319 return t('a vote of @value', array('@value' => $query));
320 }
321 break;
322 }
323 }//comms_handler_arg_vote
324
325 //the handler for the comms_minutes argument
326 function comms_handler_arg_minutes($op, &$query, $a1, $a2 = NULL) {
327 if (variable_get('comms_debuglevel', 0) > 0) {
328 drupal_set_message("comms_handler_arg_minutes()");
329 }
330
331 switch ($op) {
332 case 'sort':
333 //views will always be built against nodes right?
334 $query->ensure_table('node', TRUE);
335 $query->add_field('created', 'node');
336 $fieldinfo['field'] = 'created';
337 $query->add_orderby('node', 'created', $a1);
338 return $fieldinfo;
339 break;
340
341
342 case 'summary':
343 //views will always be built against nodes right?
344 $query->ensure_table('node', TRUE);
345 $query->add_field('created', 'node');
346 $fieldinfo['field'] = 'created';
347 $query->add_orderby('node', 'created', 'ASC');
348 return $fieldinfo;
349 break;
350
351 case 'filter':
352 if ($a2 != 'NULL' && strtolower($a2) != 'all')
353 $since = time()-($a2*60)-1;
354 $query->add_where("node.created > %d", $since);
355 break;
356
357 //TODO: where does created get set from?
358 case 'link':
359 if ($query->created)
360 return l($query->created, "$arg/$query->created");
361 else
362 return l('NULL', "$arg/NULL");
363 break;
364
365 case 'title':
366 if (strtolower($query) == 'all' || $query == '') {
367 return t("No restriction on the time frame");
368 }
369 else {
370 return t("Comms nodes recieved in the last @number minutes",
371 array('@number' => $query));
372 }
373 break;
374 }
375
376 }//comms_handler_arg_minutes
377
378 function views_handler_comms_field_group_stats_link($fieldinfo, $fielddata, $value, $data) {
379 if (variable_get('comms_debuglevel', 0) > 0) {
380 drupal_set_message("comms_handler_comms_field_group_edit_link()");
381 }
382
383 $data->type = $data->node_type;
384 $data->uid = $data->node_uid;
385 if (user_access('edit comms data')) {
386 $request_ct = 0;
387 $request_error_ct = 0;
388 $request_per_min = 0;
389 $request_per_hour = 0;
390 $request_per_day = 0;
391 //get the total number of requests for this group
392 switch ($GLOBALS['db_type']) {
393 case 'mysql':
394 case 'mysqli':
395 $sql = 'SELECT success, UNIX_TIMESTAMP(call_time) as call_time from {twitter_api_calls} WHERE gid=%d';
396 break;
397 case 'pgsql':
398 $sql = "SELECT success, date_part('epoch', call_time) as call_time from {twitter_api_calls} WHERE gid=%d";
399 break;
400 }//switch
401
402 if (!$result = db_query($query, $data->nid)) {
403 $message = t("Unable to select from the twitter_api_calls table with nid=@nid", array('@nid' => $data->nid));
404 watchdog("comms_group_views", $message);
405 drupal_set_message($message);
406 }
407 else if (db_num_rows($result) != 0) {
408 while ($row = db_fetch_array($result)) {
409 $request_ct++;
410 if ($row['success'] == 0) {
411 $request_error_ct++;
412 }
413
414 //get the total number of failed requests for this group
415 if ($row['call_time'] > time()-60) {
416 $request_per_min++;
417 }
418 else if ($row['call_time'] > time()-(60*60)) {
419 $request_per_hour++;
420 }
421 else if ($row['call_time'] > time()-(60*60*24)) {
422 $request_per_day++;
423 }
424 }//while
425 }//else if
426
427 //create links with stats per interval (min/hour/day)
428 $return = '';
429 if ($request_ct) {
430 $return .= l(
431 t("Total: @request_ct", array('@request_ct' => $request_ct)),
432 'comms/tapi/'. $data->nid
433 );
434
435 }
436 else {
437 $return .= t("Total: @ct", array('@ct' => $request_ct));
438 }
439
440 $return .=
441 l(
442 t("Failed: @ct", array('@ct' => $request_error_ct)),
443 'comms/tapi/'. $data->nid .'/failed'
444 );
445
446 $return .= t("Failed: @ct, Rate(@rm/min, @rh/hour, @rd/day)",
447 array('@ct' => $request_error_ct, '@rm' => $request_per_min,
448 '@rh' => $request_per_hour, '@rd' => $request_per_day));
449
450 return $return;
451 }
452 else {
453 return $value;
454 }
455 }
456
457 function views_handler_comms_tapi_field_success($fieldinfo, $fielddata, $value, $data) {
458 if (variable_get('comms_debuglevel', 0) > 0) {
459 drupal_set_message("comms_handler_comms_tapi_field_success()");
460 }
461
462 return $value ? t('Yes') : t('No');
463 }
464
465 function views_handler_comms_tapi_field_call_time($fieldinfo, $fielddata, $value, $data) {
466 if (variable_get('comms_debuglevel', 0) > 0) {
467 drupal_set_message("comms_handler_comms_tapi_field_call_time()");
468 }
469
470 return $value;
471 }
472
473 function views_handler_comms_tapi_field_message($fieldinfo, $fielddata, $value, $data) {
474 if (variable_get('comms_debuglevel', 0) > 0) {
475 drupal_set_message("comms_handler_comms_tapi_field_message()");
476 }
477
478 return $value ? $value : t('N/A');
479 }
480
481 function views_handler_comms_tapi_field_function_link($fieldinfo, $fielddata, $value, $data) {
482 if (variable_get('comms_debuglevel', 0) > 0) {
483 drupal_set_message("comms_handler_comms_tapi_field_function_link()");
484 }
485
486 return l($value,
487 "http://www.arc90.com/_assets/Arc90_Service_Twitter/docs/Arc90_Service/Twitter/Arc90_Service_Twitter.html".
488 '#'. $value);
489 }
490
491 function views_handler_comms_field_group_edit_link($fieldinfo, $fielddata, $value, $data) {
492 if (variable_get('comms_debuglevel', 0) > 0) {
493 drupal_set_message("comms_handler_comms_field_group_edit_link()");
494 }
495
496 $data->type = $data->node_type;
497 $data->uid = $data->node_uid;
498 if (user_access('edit comms data')) {
499 return l($value, "node/$data->nid/edit", NULL, drupal_get_destination());
500 }
501 else {
502 return $value;
503 }
504 }
505
506 //this is special in that it incorporates the functionality of the following handlers:
507 //views_handler_field_nodelink_with_mark
508 //views_handler_node_edit_destination
509 function views_handler_comms_field_node_edit_mark_link($fieldinfo, $fielddata, $value, $data) {
510 if (variable_get('comms_debuglevel', 0) > 0) {
511 drupal_set_message("comms_handler_comms_field_node_edit_mark_link()");
512 }
513
514 $data->type = $data->node_type;
515 $data->uid = $data->node_uid;
516 if (user_access('edit comms data')) {
517 return l($value, "node/$data->nid/edit", NULL, drupal_get_destination());
518 }
519 else {
520 return $value;
521 }
522 }
523
524 //this handler extends the functionality of
525 //views_handler_field_since()
526 function views_handler_comms_field_since($fieldinfo, $fielddata, $value, $data) {
527 if (variable_get('comms_debuglevel', 0) > 0) {
528 drupal_set_message("comms_handler_comms_field_since()");
529 }
530 return $value ?
531 t('%time min ago', array( '%time' => floor((time() - $value) / 60))) :
532 theme('views_nodate');
533 }
534
535 function views_handler_comms_edit_userpoints_link($fieldinfo, $fielddata, $value, $data) {
536 if (variable_get('comms_debuglevel', 0) > 0) {
537 drupal_set_message("comms_handler_comms_edit_userpoints_link()");
538 }
539 return l(
540 $value,
541 'admin/user/userpoints/add/'. $data->users_uid,
542 array(),
543 'destination=comms/slim');
544 }
545
546 function views_handler_comms_vote_priority($fieldinfo, $fielddata, $value, $data ) {
547 if (variable_get('comms_debuglevel', 0) > 0) {
548 drupal_set_message("comms_handler_comms_vote_priority()");
549 }
550 return $data->comms_vote_name ? $data->comms_vote_name : '';
551 }
552
553 function views_handler_comms_vote_value($fieldinfo, $fielddata, $value, $data ) {
554 if (variable_get('comms_debuglevel', 0) > 0) {
555 drupal_set_message("comms_handler_comms_vote_value()");
556 }
557 return $data->comms_vote_value ? $data->comms_vote_value : 0;
558 }
559
560 function views_handler_comms_vote_sort($op, &$query, $sortinfo = NULL, $sortdata = NULL) {
561 if (variable_get('comms_debuglevel', 0) > 0) {
562 drupal_set_message("comms_handler_comms_vote_sort()");
563 }
564 return "comms_vote.value";
565 }
566
567 function views_handler_comms_group_value($fieldinfo, $fielddata, $value, $data ) {
568 if (variable_get('comms_debuglevel', 0) > 0) {
569 drupal_set_message("comms_handler_comms_group_value()");
570 }
571 return $data->description ? $data->description : 0;
572 }
573
574 function views_handler_comms_group_sort($op, &$query, $sortinfo = NULL, $sortdata = NULL) {
575 if (variable_get('comms_debuglevel', 0) > 0) {
576 drupal_set_message("views_handler_comms_group_sort()");
577 }
578 return "comms_group.description";
579 }
580
581 function views_handler_comms_tapi_function($fieldinfo, $fielddata, $value, $data ) {
582 if (variable_get('comms_debuglevel', 0) > 0) {
583 drupal_set_message("views_handler_comms_tapi_function()");
584 }
585 return $data->function;
586 }
587
588 function views_handler_comms_tapi_success($fieldinfo, $fielddata, $value, $data ) {
589 if (variable_get('comms_debuglevel', 0) > 0) {
590 drupal_set_message("views_handler_comms_tapi_success()");
591 }
592 return $data->success;
593 }
594
595 function views_handler_comms_tapi_message($fieldinfo, $fielddata, $value, $data ) {
596 if (variable_get('comms_debuglevel', 0) > 0) {
597 drupal_set_message("views_handler_comms_tapi_message()");
598 }
599 return $data->message;
600 }
601
602 function views_handler_comms_tapi_call_time_sort($op, &$query, $sortinfo = NULL, $sortdata = NULL) {
603 if (variable_get('comms_debuglevel', 0) > 0) {
604 drupal_set_message("views_handler_comms_tapi_call_time_sort()");
605 }
606 return "twitter_api_calls.call_time";
607 }
608
609
610 //This will provide the default views for the module
611 //we want to have a tabbed list of default views for comms:
612 //last x min (this should use an argument)
613 //dispatched (with vote and time filter)
614 //not dispatched (with vote and time filter)
615 //variable by vote (this should use an argument)
616 //
617
618 function comms_views_default_views() {
619 if (variable_get('comms_debuglevel', 0) > 0) {
620 drupal_set_message("comms_views_default_views()");
621 }
622 // avoid miscellaneous problems by forcing the cache to clear before creating a default view
623 views_invalidate_cache();
624
625 //some default values for all default views
626 $page_empty = t('Your query did not return any values. Its possible there are no comms nodes, or if you specified url arguments for time frame or vote value that there are no nodes that satisfy those values.');
627 $page_header_format = '2';
628 $use_pager = TRUE;
629 $nodes_per_page = 100;
630 $argument = array(
631 array(
632 'type' => 'comms_minutes',
633 'argdefault' => 'All',
634 'title' => t('%1'),
635 'options' => '',
636 ),
637 array(
638 'type' => 'comms_vote',
639 'argdefault' => 'All',
640 'title' => t('Comms nodes with %2'),
641 'options' => '',
642 ),
643 array(
644 'type' => 'comms_dispatch',
645 'argdefault' => 'All',
646 'title' => t('Comms nodes that have %3'.'been dispatched'),
647 'options' => '',
648 ),
649 array(
650 'type' => 'comms_categorized',
651 'argdefault' => 'All',
652 'title' => '%4',
653 'options' => '0',
654 ),
655 array(
656 'type' => 'taxletter',
657 'argdefault' => 'All',
658 'title' => t('Comms nodes with %5'),
659 'options' => '0',
660 ),
661 );
662
663 //we arn't going to filter by status = 1 for now, because the
664 //workflow won't really entail unpublishing nodes.
665 $filter = array(
666 array(
667 'tablename' => 'node',
668 'field' => 'type',
669 'operator' => '=',
670 'options' => '',
671 'value' => 'comms',
672 ),
673 array(
674 'tablename' => 'node',
675 'field' => 'status',
676 'operator' => '=',
677 'options' => '',
678 'value' => '1',
679 ),
680 );
681
682 $access = array();
683
684 $comms_slim = comms_views_default_view_comms_slim();
685 $comms_slim->page_empty = $page_empty;
686 $comms_slim->page_header_format = $page_header_format;
687 $comms_slim->use_pager = $use_pager;
688 $comms_slim->nodes_per_page = $nodes_per_page;
689 $comms_slim->argument = $argument;
690 $comms_slim->filter = $filter;
691 $comms_slim->access = $access;
692 $views[$comms_slim->name] = $comms_slim;
693
694 $comms_full = comms_views_default_view_comms_full();
695 $comms_full->page_empty = $page_empty;
696 $comms_full->page_header_format = $page_header_format;
697 $comms_full->use_pager = $use_pager;
698
699 //2008-08-26, evoltech: we are turning this down on full pages because
700 //we started running into memory errors
701 $comms_full->nodes_per_page = 25;
702 $comms_full->argument = $argument;
703 $comms_full->filter = $filter;
704 $comms_full->access = $access;
705 $views[$comms_full->name] = $comms_full;
706
707 $comms_tapi = comms_views_default_view_comms_tapi();
708 $comms_tapi->page_empty = $page_empty;
709 $comms_tapi->page_header_format = $page_header_format;
710 $comms_tapi->use_pager = $use_pager;
711 $comms_tapi->nodes_per_page = $nodes_per_page;
712 $comms_tapi->argument = array();
713 $comms_tapi->filter = array();
714 $comms_tapi->access = $access;
715 $views[$comms_tapi->name] = $comms_tapi;
716
717 $comms_tapidetails = comms_views_default_view_comms_tapidetails();
718 $comms_tapidetails->page_empty = $page_empty;
719 $comms_tapidetails->page_header_format = $page_header_format;
720 $comms_tapidetails->use_pager = $use_pager;
721 $comms_tapidetails->nodes_per_page = $nodes_per_page;
722 $comms_tapidetails->filter = array();
723 $comms_tapidetails->access = $access;
724 $views[$comms_tapidetails->name] = $comms_tapidetails;
725
726 return $views;
727 }
728
729
730 function comms_views_default_view_comms_full() {
731 if (variable_get('comms_debuglevel', 0) > 0) {
732 drupal_set_message("comms_views_default_view_comms_full()");
733 }
734 global $base_url;
735 $view = new stdClass();
736 $view->name = 'comms_full';
737 $view->description = t('Full comms view');
738 $view->page = TRUE;
739 $view->page_title = t('All Comms Nodes (Full)');
740
741 $view->page_type = 'node';
742 $view->url = 'comms/full';
743
744 //There is an example of this in the views module: modules/views_comment.inc
745 //I imagine this is similar to stuff here: http://drupal.org/node/99793
746 $view->sort = array(
747 array(
748 'tablename' => 'node',
749 'field' => 'created',
750 'sortorder' => 'DESC',
751 'options' => '',
752 ),
753 );
754
755 $view->field = array();
756 $view->requires = array(node);
757
758 return $view;
759 }
760
761 //we want to have a default view for twitter api usage:
762 //group name (link to page), total requests made(link to breakdown by request),
763 //total failures (link to failure messages for group), request rate
764 //(min/hour/day)
765 //Is there a $views->page_footer that we can add data to?
766 function comms_views_default_view_comms_tapi() {
767 if (variable_get('comms_debuglevel', 0) > 0) {
768 drupal_set_message("comms_views_default_view_comms_tapi()");
769 }
770 global $base_url;
771 $view = new stdClass();
772 $view->name = 'comms_tapi';
773 $view->description = t('Table view of comms twitter API calls');
774 $view->page = TRUE;
775 $view->page_title = t('Twitter API Calls');
776 $view->page_footer = comms_get_default_tapi_view_page_footer();
777 $view->page_footer_format = 2;
778
779 $view->page_type = 'table';
780 $view->url = 'comms/tapi';
781
782 //TODO: figure out how to use this
783 $view->sort = array();
784
785 $view->field = array(
786 //the organic groups list here
787 //this uses a table alias and I have no ideal if it will work
788 array(
789 'tablename' => 'og',
790 'field' => 'description',
791 'label' => t('Groups'),
792 'handler' => 'views_handler_comms_field_group_edit_link',
793 'sortable' => '0',
794 ),
795 array(
796 'tablename' => 'twitter_api_calls',
797 'field' => 'gid',
798 'label' => t('Stats<br />Total: #, Failed: #, Rate(#/second, #/minute, #/day)'),
799 'handler' => 'views_handler_comms_field_group_stats_link',
800 'sortable' => '0',
801 ),
802
803 );
804 $view->requires = array(node, og, twitter_api_calls);
805
806 return $view;
807 }
808
809 function comms_views_default_view_comms_tapidetails() {
810 if (variable_get('comms_debuglevel', 0) > 0) {
811 drupal_set_message("comms_views_default_view_comms_tapidetails()");
812 }
813 global $base_url;
814 $view = new stdClass();
815 $view->name = 'comms_tapidetails';
816 $view->description = t('Detailed table view of comms twitter API calls');
817 $view->page = TRUE;
818 $view->page_title = t('Detailed Twitter API Calls');
819
820 $view->page_type = 'table';
821 $view->url = 'comms/tapidetails';
822
823 //TODO: figure out how to use this
824 $view->sort = array();
825
826 $view->field = array(
827 //the organic groups list here
828 //this uses a table alias and I have no ideal if it will work
829 array(
830 'tablename' => 'og',
831 'field' => 'description',
832 'label' => t('Group'),
833 'handler' => 'views_handler_comms_field_group_edit_link',
834 'sortable' => '0',
835 ),
836 array(
837 'tablename' => 'twitter_api_calls',
838 'field' => 'function',
839 'label' => t('Function'),
840 'handler' => 'views_handler_comms_tapi_field_function_link',
841 'sortable' => '0',
842 ),
843 array(
844 'tablename' => 'twitter_api_calls',
845 'field' => 'message',
846 'label' => t('Message'),
847 //do we need to have a handler for this?
848 'handler' => 'views_handler_comms_tapi_field_message',
849 'sortable' => '0',
850 ),
851 array(
852 'tablename' => 'twitter_api_calls',
853 'field' => 'call_time',
854 'label' => t('Call Time'),
855 'handler' => 'views_handler_comms_tapi_field_call_time',
856 'sortable' => '1',
857 ),
858 array(
859 'tablename' => 'twitter_api_calls',
860 'field' => 'success',
861 'label' => t('Success?'),
862 //do we need to have ahandler for this?
863 'handler' => 'views_handler_comms_tapi_field_success',
864 'sortable' => '0',
865 ),
866
867 );
868
869 $view->requires = array(node, og, twitter_api_calls);
870
871 return $view;
872 }
873
874 //TODO: add a delete field
875 //get sorting by vote working
876 function comms_views_default_view_comms_slim() {
877 if (variable_get('comms_debuglevel', 0) > 0) {
878 drupal_set_message("comms_views_default_view_comms_slim()");
879 }
880 global $base_url;
881 $view = new stdClass();
882 $view->name = 'comms_slim';
883 $view->description = t('Table view of comms nodes');
884 $view->page = TRUE;
885 $view->page_title = t('All Comms Nodes (Slim)');
886
887 $view->page_type = 'table';
888 $view->url = 'comms/slim';
889
890 //TODO: figure out how to use this
891 $view->sort = array();
892
893 $view->field = array(
894 array(
895 'tablename' => 'node',
896 'field' => 'title',
897 'label' => t('Title'),
898 'handler' => 'views_handler_comms_field_node_edit_mark_link',
899 'sortable' => '0',
900 ),
901
902 //we want a handler here that will link directly to the userpoints
903 //edit page
904 array(
905 'tablename' => 'users',
906 'field' => 'name',
907 'label' => t('Author'),
908 'sortable' => '1',
909 'handler' => 'views_handler_comms_edit_userpoints_link',
910 'sortable' => 1,
911 ),
912
913 //the organic groups list here
914 //this uses a table alias and I have no ideal if it will work
915 array(
916 'tablename' => 'og_node_data',
917 'field' => 'title',
918 'label' => t('Groups'),
919 'handler' => 'og_handler_field_nodelink',
920 'sortable' => '0',
921 ),
922
923 //we going to want something here for the time created as well
924 array(
925 'tablename' => 'node',
926 'field' => 'created',
927 'label' => t('Recieved'),
928 'handler' => 'views_handler_comms_field_since',
929 'sortable' => '1',
930 'defaultsort' => 'DESC',
931 ),
932
933 array(
934 'tablename' => 'comms_vote',
935 'field' => 'value',
936 'label' => t('Vote'),
937 'sortable' => '1',
938 ),
939
940 //finally we would like a delete field
941 array(
942 'tablename' => 'node',
943 'field' => 'delete',
944 'label' => t('Delete'),
945 'handler' => 'views_handler_node_delete_destination'
946 ),
947
948 );
949
950 //We include the
951 //votinapi_cache.function = 'sum' because the query is much slower
952 //if we include it in the join clause.
953 $view->filter[] = array(
954 'tablename' => 'comms_vote',
955 'field' => 'function',
956 'operator' => '=',
957 'options' => '',
958 'value' => 'sum',
959 );
960
961 $view->requires = array(node, comms_vote);
962
963 return $view;
964 }
965
966 //describe comms to views
967 function comms_views_tables() {
968 if (variable_get('comms_debuglevel', 0) > 0) {
969 drupal_set_message("comms_views_tables()");
970 }
971
972 //but this only joins when the type is comms
973 //TODO: filter by rows with no sms message?
974 $tables['comms_additions'] = array(
975 'name' => 'comms_additions',
976 'fields' => array(
977 'sms_message' => array(
978 'name' => 'Comms: SMS Message',
979 'help' => t('Display the comms SMS message.'),
980 'sortable' => FALSE
981 )
982 ),
983
984 'join' => array(
985 'type' => 'inner',
986 'left' => array(
987 'table' => 'node',
988 'field' => 'nid'
989 ),
990 'right' => array(
991 'field' => 'nid'
992 )
993 )
994 );
995
996 //TODO:
997 //this only joins when the type is group
998 //this should be sortable by dispatch time
999 //we should provide logic to dsplay statistics like: dispatches per
1000 //min/hour/day
1001 $tables['comms_group_dispatch'] = array(
1002 'name' => 'comms_group_dispatch',
1003 'fields' => array(
1004 'dispatch_time' => array(
1005 'name' => t('Comms: Dispatch Time'),
1006 'help' => t('Display the dispatch time for the node.'),
1007 'sortable' => FALSE
1008 )
1009 )
1010 );
1011
1012 //this only joins when the type is group
1013 $tables['group_twitter_account'] = array(
1014 'name' => 'group_twitter_account',
1015 'join' => array(
1016 'type' => 'inner',
1017 'left' => array(
1018 'table' => 'node',
1019 'field' => 'nid'
1020 ),
1021 'right' => 'nid'
1022 )
1023 );
1024
1025 //This may not be associated with any node, or
1026 //it may be associated with a comms node only or
1027 //a comms node and a group node
1028 //Note: this may not be possible to implement correctly, because there is no
1029 //right join support: http://drupal.org/node/99564#right-join
1030 $tables['twitter_api_calls'] = array(
1031 'name' => 'twitter_api_calls',
1032 'fields' => array(
1033 'gid' => array(
1034 'name' => t('Comms TAPI: Group Id'),
1035 'help' => t('TAPI Group Id.'),
1036 'sortable' => FALSE,
1037 'handler' => 'views_handler_comms_group_value',
1038 ),
1039 'function' => array(
1040 'name' => t('Comms TAPI: function'),
1041 'help' => t('TAPI function called.'),
1042 'sortable' => FALSE,
1043 'handler' => 'views_handler_comms_tapi_function',
1044 ),
1045 'message' => array(
1046 'name' => t('Comms TAPI: message'),
1047 'help' => t('TAPI message'),
1048 'sortable' => FALSE,
1049 'handler' => 'views_handler_comms_tapi_message',
1050 ),
1051 'success' => array(
1052 'name' => t('Comms TAPI: success'),
1053 'help' => t('TAPI success boolean'),
1054 'sortable' => FALSE,
1055 'handler' => 'views_handler_comms_tapi_success',
1056 ),
1057 'call_time' => array(
1058 'name' => t('Comms TAPI: call time'),
1059 'help' => t('TAPI call time'),
1060 'sortable' => TRUE,
1061 'handler' => 'views_handler_field_date',
1062 'sort_handler' => 'views_handler_comms_tapi_call_time_sort'
1063 )
1064 ),
1065 'join' => array(
1066 'type' => 'inner',
1067 'left' => array(
1068 'table' => 'og',
1069 'field' => 'nid'
1070 ),
1071 'right' => array(
1072 'table' => 'twitter_api_calls',
1073 'field' => 'gid'
1074 ),
1075 )
1076 );
1077
1078 $tables['comms_group'] = array(
1079 'name' => 'og',
1080 'fields' => array(
1081 'description' => array(
1082 'name' => t('Comms: Group Description'),
1083 'help' => t('Display a comms group.'),
1084 'sortable' => TRUE,
1085 'handler' => 'views_handler_comms_group_value',
1086 'sort_handler' => 'views_handler_comms_group_sort'
1087 )
1088 ),
1089 /*
1090 'join' => array(
1091 'type' => 'inner',
1092 'left' => array(
1093 'table' => 'node',
1094 'field' => 'nid'
1095 ),
1096 'right' => array(
1097 'table' => 'og',
1098 'field' => 'nid'
1099 )
1100 )
1101 */
1102 );
1103
1104 $tables['comms_vote'] = array(
1105 'name' => 'votingapi_cache',
1106 'fields' => array(
1107 'value' => array(
1108 'name' => t('Comms: Vote Value'),
1109 'help' => t('Display the comms vote value.'),
1110 'sortable' => TRUE,
1111 'handler' => 'views_handler_comms_vote_value',
1112 'sort_handler' => 'views_handler_comms_vote_sort'
1113 )
1114 ),
1115 'join' => array(
1116 //'type' => 'inner',
1117 'left' => array(
1118 'table' => 'node',
1119 'field' => 'nid'
1120 ),
1121 'right' => array(
1122 //'field' => 'content_id AND {comms_vote}.function=\'sum\''
1123 'field' => 'content_id'
1124 )
1125 ),
1126 'filters' => array(
1127 'value' => array(
1128 'name' => t("Comms rating"),
1129 'operator' => 'views_handler_operator_eqneq',
1130 'handler' => 'comms_handler_filter_vote',
1131 'value-type' => 'string',
1132 'help' => t('Filter intel by its current rating.'),
1133 ),
1134 'function' => array(
1135 'name' => t("Comms vote function"),
1136 'operator' => '=',
1137 'handler' => 'comms_handler_filter_vote_function',
1138 'value-type' => 'string',
1139 'value' => array(
1140 '#type' => 'select',
1141 '#multiple' => '0',
1142 '#options' => array(
1143 'count',
1144 'sum',
1145 'average')
1146 ),
1147 'help' => t('Filter intel votes by the votingapi function.'),
1148 )
1149 )
1150 );
1151
1152 $tables['comms_priority'] = array(
1153 'name' => 'term_node',
1154 'fields' => array(
1155 'name' => array(
1156 'name' => t('Comms: Priority'),
1157 'help' => t('The associated priority of the comms node.'),
1158 'sortable' => FALSE,
1159 'handler' => 'views_handler_comms_vote_priority',
1160 )
1161 ),
1162 'join' => array(
1163 'type' => 'inner',
1164 'left' => array(
1165 'table' => 'node',
1166 'field' => 'nid'
1167 ),
1168 'right' => array(
1169 'field' => 'nid inner join {term_data} on {term_data}.tid = {comms_priority}.tid'
1170 )
1171 )
1172 );
1173 return $tables;
1174 }
1175
1176 //TODO: this will start the section collapsed, but will not re-collapse
1177 //after it has been clicked.
1178 //I can't figure out a better way to include this js file, can you?
1179 //since this function is not called everytime the view is generated
1180 //a simple drupal_add_js() is not sufficient.
1181 function comms_get_default_view_page_header($url) {
1182 $return = '<script type="text/javascript" '.
1183 'src="/misc/collapse.js"></script>'.
1184 '<form><fieldset class="collapsible collapsed">'.
1185 '<legend>'. t('Filtering help') .'</legend><div>'.
1186 t('You can refine the search results here by passing arguments for the time frame and vote value in the url. The format is !base. examples: <br />All nodes in the past 10 minutes: !e1<br />All nodes with a vote of 2: !e2<br />All nodes with a in the past 10 min, with a vote of 3, that have not been dispatched: !e3<br />All nodes with with a vote of 0 (aka no votes), that have been dispatched, with a priority of "Info": !e4', array(
1187 '!base' => l($base_url ."$url/<time_frame>/<vote>/<dispatched>/<urgency>", $url .'/All/All/All/'),
1188 '!e1' => l($base_url ."$url/10", $url .'/10'),
1189 '!e2' => l($base_url ."$url/All/2", $url .'/All/2'),
1190 '!e3' => l($base_url ."$url/10/3/0", $url .'/10/3/0'),
1191 '!e4' => l($base_url ."$url/All/0/1/Info", $url .'/All/0/1/Info'))) .
1192 '</div></fieldset></form>';
1193
1194 return $return;
1195 }
1196