commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / drupal / modules / views / civicrm.views.inc
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | This file is a part of CiviCRM. |
7 | |
8 | CiviCRM is free software; you can copy, modify, and distribute it |
9 | under the terms of the GNU Affero General Public License |
10 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
11 | |
12 | CiviCRM is distributed in the hope that it will be useful, but |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
15 | See the GNU Affero General Public License for more details. |
16 | |
17 | You should have received a copy of the GNU Affero General Public |
18 | License and the CiviCRM Licensing Exception along |
19 | with this program; if not, contact CiviCRM LLC |
20 | at info[AT]civicrm[DOT]org. If you have questions about the |
21 | GNU Affero General Public License or the licensing of CiviCRM, |
22 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
23 +--------------------------------------------------------------------+
24 */
25
26 /*
27 * Copyright (C) 2009 James Rakich
28 * Licensed to CiviCRM under the Academic Free License version 3.0.
29 *
30 */
31
32
33 /*
34 * civicrm.views.inc Called from civicrm.module, gives the views cache all information it needs
35 * to access CiviCRM's database for use in Views, as well as referencing the
36 * custom handlers for displaying, sorting, filtering and accepting arguments
37 * for this data.
38 *
39 // Defines tables, joins and relationships
40 * function civicrm_views_data() {
41 * CiviCRM Contacts Base Table
42 * CiviCRM Activities Base Table
43 * CiviCRM Relationships Base Table
44 * Custom Data Cache Query and Calls
45 *
46 * function civicrm_views_href( $text, $path, $query )
47 * Generates a link for CiviCRM Paths - unchanged from previous code (anonymous donation)
48 *
49 * function civicrm_views_custom_data_cache($data, $entity_type, $groupID, $subType, $style)
50 * Collects the data from Custom Data Groups and assigns them to base tables.
51 *
52 * function civicrm_views_get_field ($type)
53 * function civicrm_views_get_argument ($type)
54 * function civicrm_views_get_filter ($type)
55 * function civicrm_views_get_sort ($type)
56 * Assign handlers to custom fields based on the data type (from the database records)
57 *
58 * function civicrm_date_api_tables()
59 * function civicrm_date_api_fields()
60 * Tells Views which fields to expose as Date API fields
61 */
62
63 /**
64 * Implements of hook_views_data().
65 * Run hook_views_data for active CiviCRM components
66 */
67 function civicrm_views_data_alter(&$data) {
68 if (!civicrm_initialize() || CRM_Utils_System::isInUpgradeMode()) {
69 return;
70 }
71
72 require_once 'CRM/Core/Config.php';
73 require_once 'CRM/Core/BAO/CustomGroup.php';
74 require_once 'CRM/Core/DAO.php';
75 require_once 'CRM/Core/Error.php';
76 require_once 'CRM/Contact/BAO/Contact.php';
77 require_once 'CRM/Event/BAO/Query.php';
78 require_once 'CRM/Case/BAO/Case.php';
79 require_once 'components/civicrm.core.inc';
80
81 // Get list of enabled CiviCRM components
82 $enabled = CRM_Core_Component::getEnabledComponents();
83
84 // $data = array();
85 // Load Core CiviCRM data
86 _civicrm_core_data($data, $enabled);
87
88 // Load enabled optional components
89 if (isset($enabled['CiviCampaign'])) {
90 include_once 'components/civicrm.campaign.inc';
91 _civicrm_campaign_data($data, $enabled);
92 }
93 // Though not explicitly effectively CiviPledge depends on CiviContribute
94 // so they share an include file
95 if (isset($enabled['CiviContribute']) ||
96 isset($enabled['CiviPledge'])
97 ) {
98 include_once 'components/civicrm.contribute.inc';
99 _civicrm_contribute_data($data, $enabled);
100 }
101 if (isset($enabled['CiviEvent'])) {
102 include_once 'components/civicrm.event.inc';
103 _civicrm_event_data($data, $enabled);
104 }
105 if (isset($enabled['CiviGrant'])) {
106 include_once 'components/civicrm.grant.inc';
107 _civicrm_grant_data($data, $enabled);
108 }
109 if (isset($enabled['CiviMail'])) {
110 include_once 'components/civicrm.mail.inc';
111 _civicrm_mail_data($data, $enabled);
112 }
113 if (isset($enabled['CiviMember'])) {
114 include_once 'components/civicrm.member.inc';
115 _civicrm_member_data($data, $enabled);
116 }
117 if (isset($enabled['CiviCase'])) {
118 include_once 'components/civicrm.case.inc';
119 _civicrm_case_data($data, $enabled);
120 }
121 if (isset($enabled['CiviContribute']) ||
122 isset($enabled['CiviEvent']) ||
123 isset($enabled['CiviMember'])) {
124 include_once 'components/civicrm.price_set.inc';
125 _civicrm_price_set_data($data, $enabled);
126 }
127
128 return $data;
129 }
130
131 /**
132 * Return link to CiviCRM path
133 *
134 * @param $text
135 *
136 * @param $path
137 *
138 * @param $query
139 *
140 * @return String path to CiviCRM
141 */
142 function civicrm_views_href($text, $path, $query) {
143 civicrm_initialize();
144 require_once 'CRM/Utils/System.php';
145 return CRM_Utils_System::href($text, $path, $query);
146 }
147
148 /**
149 * Return url to CiviCRM path
150 *
151 * @param $path string The path being linked to, such as "civicrm/add"
152 * @param $query string A query string to append to the link.
153 * @param $absolute boolean Whether to force the output to be an absolute link (beginning with http:).
154 * Useful for links that will be displayed outside the site, such as in an
155 * RSS feed.
156 *
157 * @return string an HTML string containing a link to the given path.
158 */
159 function civicrm_views_url($path, $query, $absolute = FALSE) {
160 civicrm_initialize();
161 require_once 'CRM/Utils/System.php';
162 return CRM_Utils_System::url($path, $query, $absolute);
163 }
164
165 /**
166 * Creates new View fields from CiviCRM fields
167 *
168 * @param $fields
169 * Array of fields in a table obtained from a DAO fields method for $tableName
170 *
171 * @param $data
172 * Array returned to hook_views_data
173 *
174 * @param $tableName
175 * String tabled nam of field whose DAO is returned in $fields
176 *
177 * @param $skipFields
178 * (optional) Array of fields not to add form the $fields table
179 */
180 function civicrm_views_add_fields(&$fields, &$data, $tableName, &$skipFields = NULL) {
181 foreach ($fields as $name => $value) {
182 // Only add fields not in $data or $skipFields and has a ['title']
183 if (isset($value['custom_field_id']) ||
184 CRM_Utils_Array::value($name, $skipFields) ||
185 CRM_Utils_Array::value($name, $data) ||
186 !isset($value['title']) ||
187 (isset($value['where']) &&
188 substr($value['where'], 0, strlen($tableName) + 1) != "{$tableName}."
189 )
190 ) {
191 continue;
192 }
193
194 // Ensure the field isn't alredy defined in $data using $data[$xyz]['real field'] where $xyz is a field name passed in $data
195 foreach ($data as $field => $current) {
196 if (isset($current['real field']) and $current['real field'] == $name) {
197 continue 2;
198 }
199 }
200
201 $type = CRM_Utils_Array::value('type', $value, 'String');
202 $data[$value['name']] = array(
203 'title' => $value['title'],
204 'help' => $value['title'],
205 'field' => civicrm_views_get_field($type),
206 'sort' => civicrm_views_get_sort($type),
207 'filter' => civicrm_views_get_filter($type),
208 'argument' => civicrm_views_get_argument($type),
209 );
210
211 // For date fields add in 6 arguments
212 // not sure how its numeric here, but leaving it as is for now
213 if ($type == 4) {
214 civicrm_views_add_date_arguments($data, $value);
215 }
216 }
217 }
218
219 /**
220 * Function adds 6 date arguments to a date field
221 *
222 * @param $data
223 * Array passed back to hook_views_data()
224 *
225 * @param $value
226 * Array contains meta data about field from DAO fields function
227 *
228 */
229 function civicrm_views_add_date_arguments(&$data, $value) {
230
231 $data[$value['name']]['argument'] = array(
232 'handler' => 'date_views_argument_handler',
233 'empty field name' => t('Undated'),
234 'is date' => TRUE,
235 );
236 $data[$value['name'] . '_full'] = array(
237 'title' => $value['title'],
238 'help' => t('In the form of CCYYMMDD.'),
239 'argument' => array(
240 'field' => $value['name'],
241 'handler' => 'views_handler_argument_civicrm_fulldate',
242 ),
243 );
244 $data[$value['name'] . '_year_month'] = array(
245 'title' => t('%title year + month', array('%title' => $value['title'])),
246 'help' => t('In the form of YYYYMM.'),
247 'argument' => array(
248 'field' => $value['name'],
249 'handler' => 'views_handler_argument_civicrm_year_month',
250 ),
251 );
252 $data[$value['name'] . '_year'] = array(
253 'title' => t('%title year', array('%title' => $value['title'])),
254 'help' => t('In the form of YYYY.'),
255 'argument' => array(
256 'field' => $value['name'],
257 'handler' => 'views_handler_argument_civicrm_year',
258 ),
259 );
260 $data[$value['name'] . '_month'] = array(
261 'title' => t('%title month', array('%title' => $value['title'])),
262 'help' => t('In the form of MM (01 - 12).'),
263 'argument' => array(
264 'field' => $value['name'],
265 'handler' => 'views_handler_argument_civicrm_month',
266 ),
267 );
268 $data[$value['name'] . '_day'] = array(
269 'title' => t('%title day', array('%title' => $value['title'])),
270 'help' => t('In the form of DD (01 - 31).'),
271 'argument' => array(
272 'field' => $value['name'],
273 'handler' => 'views_handler_argument_civicrm_day',
274 ),
275 );
276 $data[$value['name'] . '_week'] = array(
277 'title' => t('%title week', array('%title' => $value['title'])),
278 'help' => t('In the form of WW (01 - 53).'),
279 'argument' => array(
280 'field' => $value['name'],
281 'handler' => 'views_handler_argument_civicrm_week',
282 ),
283 );
284 }
285
286 /**
287 * Add Custom Fields to $data array
288 *
289 * @param $data
290 * Array of fields passed to hook_views_data()
291 *
292 * @param $entity_type
293 * String CivicRM entity Type ie "Contact"
294 *
295 * @param $group_id
296 * Integer Id of the Custom Field Group
297 *
298 * @param $sub_type
299 * (optional) Integer Id of the Sub-Type, ie Contact Sub Type
300 *
301 * @return $data
302 * Array with the new custom field appended
303 */
304 function civicrm_views_custom_data_cache(&$data, $entity_type, $group_id, $sub_type) {
305 // From http://forum.civicrm.org/index.php/topic,17658.msg73901.html#msg73901, CRM-7860.
306 $tree = CRM_Core_BAO_CustomGroup::getTree($entity_type, CRM_Core_DAO::$_nullObject, NULL, $group_id, $sub_type, NULL);
307
308 $join_table = civicrm_views_get_join_table($entity_type);
309 foreach ($tree as $groupkey => $current_group) {
310 // Ignore 'info' key as it is not a real field.
311 if ($groupkey == 'info') {
312 continue;
313 }
314
315 // Provide custom table data, including group title and implicit table join.
316 $data[$current_group['table_name']]['table'] = array(
317 'group' => t('CiviCRM Custom: !title', array('!title' => $current_group['title'])),
318 'join' => array(
319 $join_table => array(
320 'left_field' => 'id',
321 'field' => 'entity_id',
322 ),
323 ),
324 );
325
326 // Provide implicit joins in the other direction.
327 // Skip 'contribution', activity' and 'event' as these are not directly related to users.
328 if ($join_table != 'civicrm_event' && $join_table != 'civicrm_activity' && $join_table != 'civicrm_contribution') {
329 // Expose custom data to users view.
330 $data[$current_group['table_name']]['table']['join']['users'] = array(
331 'left_table' => $join_table,
332 'left_field' => 'id',
333 'field' => 'entity_id',
334 );
335
336 // Expose custom data to contact view.
337 if ($join_table != 'civicrm_contact') {
338 $data[$current_group['table_name']]['table']['join']['civicrm_contact'] = array(
339 'left_table' => $join_table,
340 'left_field' => 'id',
341 'field' => 'entity_id',
342 );
343 }
344 }
345
346 foreach ($current_group['fields'] as $key => $current_field) {
347 //Create the Views Field
348 $option_group_id = isset($current_field['option_group_id']) ? $current_field['option_group_id'] : NULL;
349 $data[$current_group['table_name']][$current_field['column_name']] = array(
350 'title' => $current_field['label'],
351 'help' => empty($current_field['help_post']) ? t('Custom Data Field') : $current_field['help_post'],
352 'field' => civicrm_views_get_field($current_field['data_type'], $current_field['html_type']),
353 'argument' => civicrm_views_get_argument($current_field['data_type']),
354 'filter' => civicrm_views_get_filter($current_field['data_type'], $current_field['html_type'], $option_group_id),
355 'sort' => civicrm_views_get_sort($current_field['data_type']),
356 'relationship' => civicrm_views_get_relationship($current_field['data_type']),
357 );
358
359 //For date fields add in 6 arguments
360 if ($current_field['data_type'] == 'Date') {
361 //@TODO Still need to get the field under it's respecitve group, I may e able to set the civicrm_views_add_date_arguments() function with a group variable and default it to null
362 $value = array();
363 $value['title'] = $current_field['label'];
364 $value['name'] = $current_field['column_name'];
365 civicrm_views_add_date_arguments($data[$current_group['table_name']], $value);
366 }
367 }
368 }
369 return $data;
370 }
371
372 /**
373 * Return the implicit join table for a custom group table based on its entity type.
374 */
375 function civicrm_views_get_join_table($entity_type) {
376 switch ($entity_type) {
377 case "Contact":
378 case "Individual":
379 case "Household":
380 case "Organization":
381 return 'civicrm_contact';
382 case "Group":
383 return 'civicrm_group';
384 case "Address":
385 return 'civicrm_address';
386 case "Event":
387 return 'civicrm_event';
388 case "Participant":
389 return 'civicrm_participant';
390 case "Contribution":
391 return 'civicrm_contribution';
392 case "Activity":
393 return 'civicrm_activity';
394 case "Relationship":
395 return 'civicrm_relationship';
396 case "Membership":
397 return 'civicrm_membership';
398 case "Grant":
399 return 'civicrm_grant';
400 case "Campaign":
401 case "Survey":
402 return 'civicrm_campaign';
403 case "Case":
404 return 'civicrm_case';
405 default:
406 return NULL;
407 }
408 }
409
410 /**
411 * Acquire the proper field handler by checking against the field's data_type as defined by CRM_Utils_Type.
412 *
413 * @param $data_type
414 * A String containing the field data type
415 * @param $html_type
416 * A String containing the field html type
417 *
418 * @return
419 * An array containing the handler name and any extra settings
420 */
421 function civicrm_views_get_field($data_type, $html_type = NULL) {
422 // Relying on html types as opposed to data types seems like a code smell.
423 // Would love to be able to remove this logic.
424 $customHTMLTypes = array(
425 'Select', 'Multi-Select', 'AdvMulti-Select', 'Radio', 'CheckBox',
426 'Select State/Province', 'Select Country', 'Multi-Select Country',
427 'Multi-Select State/Province', 'Autocomplete-Select',
428 );
429 if (in_array($html_type, $customHTMLTypes)) {
430 return array(
431 'handler' => 'civicrm_handler_field_custom',
432 'click sortable' => TRUE,
433 );
434 }
435 if ($html_type == 'File') {
436 return array(
437 'handler' => 'civicrm_handler_field_custom_file',
438 'click sortable' => TRUE,
439 );
440 }
441
442 switch ($data_type) {
443 case "String":
444 case "Memo":
445 return array(
446 'handler' => 'civicrm_handler_field_markup',
447 'click sortable' => TRUE,
448 );
449 case "Float":
450 return array(
451 'handler' => 'views_handler_field_numeric',
452 'click sortable' => TRUE,
453 'float' => TRUE,
454 );
455 case "Int":
456 return array(
457 'handler' => 'civicrm_handler_field_custom',
458 'click sortable' => TRUE,
459 );
460 case "Date":
461 return array(
462 'handler' => 'civicrm_handler_field_datetime',
463 'click sortable' => TRUE,
464 );
465 case "Boolean":
466 return array(
467 'handler' => 'views_handler_field_boolean',
468 'click sortable' => TRUE,
469 );
470 case "StateProvince":
471 return array(
472 'handler' => 'civicrm_handler_field_state',
473 'click sortable' => TRUE,
474 );
475 case "Country":
476 return array(
477 'handler' => 'civicrm_handler_field_country',
478 'click sortable' => TRUE,
479 );
480 case "County":
481 return array(
482 'handler' => 'civicrm_handler_field_pseudo_constant',
483 'click sortable' => TRUE,
484 'pseudo class' => 'CRM_Core_PseudoConstant',
485 'pseudo method' => 'county',
486 );
487 default:
488 return array(
489 'views_handler_field',
490 'click sortable' => TRUE,
491 );
492 }
493 }
494
495 /**
496 * Acquire the proper argument handler by checking against the field's data_type as defined by CRM_Utils_Type.
497 *
498 * @param $type
499 * A String containing the field type
500 *
501 * @return
502 * An array containing the handler name and any extra settings
503 */
504 function civicrm_views_get_argument($type) {
505 switch ($type) {
506 case "String":
507 case "Memo":
508 return array(
509 'handler' => 'views_handler_argument',
510 );
511 case "Float":
512 case "Int":
513 return array(
514 'handler' => 'views_handler_argument_numeric',
515 );
516 case "Date":
517 return array(
518 'handler' => 'views_handler_argument_date',
519 );
520 case "Boolean":
521 return array(
522 'handler' => 'views_handler_argument',
523 );
524 case "StateProvince":
525 return array(
526 'handler' => 'views_handler_argument',
527 );
528 case "Country":
529 return array(
530 'handler' => 'views_handler_argument',
531 );
532 case "County":
533 return array(
534 'handler' => 'views_handler_argument',
535 );
536 default:
537 return array(
538 'handler' => 'views_handler_argument',
539 );
540 }
541 }
542
543 /**
544 * Acquire the proper filter handler by checking against the field's data_type as defined by CRM_Utils_Type.
545 *
546 * @param $data_type
547 * A String containing the field data type
548 * @param $html_type
549 * A string containing the field html type
550 *
551 * @return
552 * An array containing the handler name and any extra settings
553 */
554 function civicrm_views_get_filter($data_type, $html_type = NULL, $option_group_id = NULL) {
555 // Relying on html types as opposed to data types seems like a code smell.
556 // Would love to be able to remove this logic.
557 $customMultiValueHTMLTypes = array(
558 'Multi-Select', 'AdvMulti-Select', 'CheckBox', 'Multi-Select Country',
559 'Multi-Select State/Province',
560 );
561 if ($html_type == 'Multi-Select Country') {
562 return array(
563 'handler' => 'civicrm_handler_filter_country_multi',
564 );
565 }
566 elseif ($html_type == 'Multi-Select State/Province') {
567 return array(
568 'handler' => 'civicrm_handler_filter_state_multi',
569 );
570 }
571 elseif (!empty($option_group_id) && in_array($html_type, $customMultiValueHTMLTypes)) {
572 return array(
573 'handler' => 'civicrm_handler_filter_custom_option',
574 );
575 }
576 elseif (!empty($option_group_id)) {
577 return array(
578 'handler' => 'civicrm_handler_filter_custom_single_option',
579 );
580 }
581
582 switch ($data_type) {
583 case "String":
584 case "Memo":
585 return array(
586 'handler' => 'views_handler_filter_string',
587 'allow empty' => TRUE,
588 );
589
590 case "Float":
591 case "Int":
592 return array(
593 'handler' => 'views_handler_filter_numeric',
594 'allow empty' => TRUE,
595 );
596
597 case "Date":
598 return array('handler' => 'civicrm_handler_filter_datetime');
599
600 case "Boolean":
601 return array('handler' => 'views_handler_filter_boolean_operator');
602
603 case "StateProvince":
604 return array(
605 'handler' => 'civicrm_handler_filter_pseudo_constant',
606 'pseudo class' => 'CRM_Core_PseudoConstant',
607 'pseudo method' => 'stateProvince',
608 'allow empty' => TRUE,
609 );
610
611 case "Country":
612 return array(
613 'handler' => 'civicrm_handler_filter_pseudo_constant',
614 'pseudo class' => 'CRM_Core_PseudoConstant',
615 'pseudo method' => 'country',
616 'allow empty' => TRUE,
617 );
618
619 case "County":
620 return array(
621 'handler' => 'civicrm_handler_filter_pseudo_constant',
622 'pseudo class' => 'CRM_Core_PseudoConstant',
623 'pseudo method' => 'county',
624 'allow empty' => TRUE,
625 );
626
627 default:
628 return array(
629 'handler' => 'views_handler_filter_string',
630 'allow empty' => TRUE,
631 );
632 }
633 }
634
635 /**
636 * Acquire the proper sort handler by checking against the field's data_type as defined by CRM_Utils_Type.
637 *
638 * @param $type
639 * A String containing the field type
640 *
641 * @return
642 * An array containing the handler name and any extra settings
643 */
644 function civicrm_views_get_sort($type) {
645 switch ($type) {
646 case "String":
647 case "Memo":
648 case "Float":
649 case "Int":
650 return array(
651 'handler' => 'views_handler_sort',
652 );
653 case "Date":
654 return array(
655 'handler' => 'views_handler_sort_date',
656 );
657 case "Boolean":
658 return array(
659 'handler' => 'views_handler_sort',
660 );
661 case "StateProvince":
662 return array(
663 'handler' => 'views_handler_sort',
664 );
665 case "Country":
666 return array(
667 'handler' => 'views_handler_sort',
668 );
669 case "County":
670 return array(
671 'handler' => 'views_handler_sort',
672 );
673 default:
674 return array(
675 'handler' => 'views_handler_sort',
676 );
677 }
678 }
679
680 /**
681 * Acquire the proper relationship handler by checking against the field's data_type as defined by CRM_Utils_Type.
682 *
683 * @param $type
684 * A String containing the field type
685 *
686 * @return
687 * An array containing the handler name and any extra settings
688 */
689 function civicrm_views_get_relationship($type) {
690 switch ($type) {
691 case "ContactReference":
692 return array(
693 'handler' => 'views_handler_relationship',
694 'base' => 'civicrm_contact',
695 'base field' => 'id',
696 );
697 default:
698 return array();
699 }
700 }
701
702 /**
703 * Implements hook_date_views_fields().
704 */
705 function civicrm_date_views_fields($field) {
706 $values = array(
707 // The type of date: DATE_UNIX, DATE_ISO, DATE_DATETIME.
708 'sql_type' => DATE_DATETIME,
709 // Timezone handling options: 'none', 'site', 'date', 'utc'.
710 'tz_handling' => 'none',
711 // Needed only for dates that use 'date' tz_handling.
712 'timezone_field' => '',
713 // Needed only for dates that use 'date' tz_handling.
714 'offset_field' => '',
715 // Array of "table.field" values for related fields that should be
716 // loaded automatically in the Views SQL.
717 'related_fields' => array(),
718 // Granularity of this date field's db data.
719 'granularity' => array('year', 'month', 'day', 'hour', 'minute', 'second'),
720 );
721
722 switch ($field) {
723 case 'civicrm_event.start_date':
724 case 'civicrm_event.end_date':
725 case 'civicrm_event.registration_start_date':
726 case 'civicrm_event.registration_end_date':
727 case 'civicrm_mailing_job.scheduled_date':
728 case 'civicrm_mailing_job.start_date':
729 case 'civicrm_mailing_job.end_date':
730 case 'civicrm_activity.activity_date_time':
731 case 'civicrm_campaign.start_date':
732 case 'civicrm_campaign.end_date':
733 case 'civicrm_case.start_date':
734 case 'civicrm_case.end_date':
735 return $values;
736 }
737 }
738
739 /**
740 * Implements hook_date_api_tables().
741 */
742 function civicrm_date_views_tables() {
743 return array(
744 'civicrm_mailing_job',
745 'civicrm_event',
746 'civicrm_case',
747 'civicrm_activity',
748 'civicrm_campaign',
749 );
750 }
751
752 /**
753 * Implements hook_views_plugins().
754 */
755 function civicrm_views_plugins() {
756 $data = array();
757
758 // This just tells us that the themes are elsewhere
759 $data['module'] = 'civicrm';
760
761 // Default argument to pull CiviCRM IDs from the URL
762 $data['argument default']['civicrm_id'] = array(
763 'title' => t('CiviCRM ID from URL'),
764 'handler' => 'civicrm_plugin_argument_default_civicrm_id'
765 );
766
767 // Calendar module integration
768 if (module_exists('calendar')) {
769 $civicrm_module_path = drupal_get_path('module', 'civicrm');
770 $data['row'] = array(
771 'civicrm_event_calendar' => array(
772 'title' => t('Calendar Items'),
773 'help' => t('Displays each selected event as a Calendar item.'),
774 'handler' => 'calendar_plugin_row_civicrm',
775 'path' => "$civicrm_module_path/modules/views/plugins",
776 'base' => array('civicrm_event'),
777 'uses options' => TRUE,
778 'uses fields' => TRUE,
779 'type' => 'normal',
780 'dao class' => 'CRM_Event_DAO_Event',
781 'title field' => 'title',
782 ),
783 'civicrm_activity_calendar' => array(
784 'title' => t('Calendar Items'),
785 'help' => t('Displays each selected activity as a Calendar item.'),
786 'handler' => 'calendar_plugin_row_civicrm',
787 'path' => "$civicrm_module_path/modules/views/plugins",
788 'base' => array('civicrm_activity'),
789 'uses options' => TRUE,
790 'uses fields' => TRUE,
791 'type' => 'normal',
792 'dao class' => 'CRM_Activity_DAO_Activity',
793 'title field' => 'subject',
794 ),
795 'civicrm_case_calendar' => array(
796 'title' => t('Case Items'),
797 'help' => t('Displays each selected case as a Calendar item.'),
798 'handler' => 'calendar_plugin_row_civicrm',
799 'path' => "$civicrm_module_path/modules/views/plugins",
800 'base' => array('civicrm_case'),
801 'uses options' => TRUE,
802 'uses fields' => TRUE,
803 'type' => 'normal',
804 'dao class' => 'CRM_Case_DAO_Case',
805 'title field' => 'subject',
806 ),
807 'civicrm_mail_calendar' => array(
808 'title' => t('Calendar Items'),
809 'help' => t('Displays each selected mailing as a Calendar item.'),
810 'handler' => 'calendar_plugin_row_civicrm',
811 'path' => "$civicrm_module_path/modules/views/plugins",
812 'base' => array('civicrm_mail'),
813 'uses options' => TRUE,
814 'uses fields' => TRUE,
815 'type' => 'normal',
816 'dao class' => 'CRM_Mailing_DAO_MailingJob',
817 // @TODO come up with a better title field
818 'title field' => 'mailing_id',
819 ),
820 'civicrm_campaign_calendar' => array(
821 'title' => t('Calendar Items'),
822 'help' => t('Displays each selected campaign as a Calendar item.'),
823 'handler' => 'calendar_plugin_row_civicrm',
824 'path' => "$civicrm_module_path/modules/views/plugins",
825 'base' => array('civicrm_campaign'),
826 'uses options' => TRUE,
827 'uses fields' => TRUE,
828 'type' => 'normal',
829 'dao class' => 'CRM_Campaign_DAO_Campaign',
830 'title field' => 'title',
831 ),
832 );
833 }
834
835 return $data;
836 }