commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / drupal / modules / views / civicrm / civicrm_handler_filter_country_multi.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 * @file Provides Views integration for CiviCRM Multi-Select Country custom fields
27 *
28 * @author DaveJ
29 * based on civicrm_handler_filter_custom_option and civicrm_handler_filter_country
30 */
31 class civicrm_handler_filter_country_multi extends views_handler_filter_in_operator {
32 function construct() {
33 parent::construct();
34 if (!civicrm_initialize()) {
35 return;
36 }
37 }
38
39 function get_value_options() {
40 if (!isset($this->value_options)) {
41 $countries = CRM_Core_PseudoConstant::country();
42 $options = array();
43 if (is_array($countries)) {
44 foreach ($countries as $id => $name) {
45 $options[$id] = $name;
46 }
47 }
48 $this->value_options = $options;
49 }
50 }
51
52 function operators() {
53 $operators = parent::operators();
54 $operators += array(
55 'all' => array(
56 'title' => t('Is all of'),
57 'short' => t('all'),
58 'method' => 'op_simple',
59 'values' => 1,
60 ),
61 );
62
63 return $operators;
64 }
65
66 function op_simple() {
67 if (empty($this->value)) {
68 return;
69 }
70
71 $this->ensure_my_table();
72
73 // negated operator uses AND, positive uses OR
74 $op = $glue = null;
75 switch ($this->operator) {
76 case 'in':
77 $op = ' = ';
78 $glue = ' OR ';
79 break;
80 case 'not in':
81 $op = ' != ';
82 $glue = ' AND ';
83 break;
84 case 'all' :
85 $clause = "$this->table_alias.$this->real_field IN (" . implode(',', $this->value) . ")";
86 break;
87 }
88
89 if ($op) {
90 foreach ($this->value as $value) {
91 $clauses[] = "$this->table_alias.$this->real_field " . $op . $value;
92 }
93 $clause = implode($glue, $clauses);
94 }
95
96 $this->query->add_where_expression($this->options['group'], $clause);
97 }
98 }
99