Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | class CRM_Contact_Form_Search_Custom_Basic extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface { | |
36 | ||
430ae6dd TO |
37 | protected $_query; |
38 | ||
86538308 EM |
39 | /** |
40 | * @param $formValues | |
41 | */ | |
42 | /** | |
43 | * @param $formValues | |
44 | */ | |
430ae6dd | 45 | function __construct(&$formValues) { |
6a488035 TO |
46 | parent::__construct($formValues); |
47 | ||
48 | $this->normalize(); | |
49 | $this->_columns = array( | |
50 | ts('') => 'contact_type', | |
51 | ts('Name') => 'sort_name', | |
52 | ts('Address') => 'street_address', | |
53 | ts('City') => 'city', | |
54 | ts('State') => 'state_province', | |
55 | ts('Postal') => 'postal_code', | |
56 | ts('Country') => 'country', | |
57 | ts('Email') => 'email', | |
58 | ts('Phone') => 'phone', | |
59 | ); | |
60 | ||
61 | $params = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); | |
62 | $returnProperties = array(); | |
63 | $returnProperties['contact_sub_type'] = 1; | |
64 | ||
65 | $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, | |
66 | 'address_options', TRUE, NULL, TRUE | |
67 | ); | |
68 | ||
69 | foreach ($this->_columns as $name => $field) { | |
70 | if (in_array($field, array( | |
8cc574cf | 71 | 'street_address', 'city', 'state_province', 'postal_code', 'country')) && empty($addressOptions[$field])) { |
6a488035 TO |
72 | unset($this->_columns[$name]); |
73 | continue; | |
74 | } | |
75 | $returnProperties[$field] = 1; | |
76 | } | |
77 | ||
78 | $this->_query = new CRM_Contact_BAO_Query($params, $returnProperties, NULL, | |
79 | FALSE, FALSE, 1, FALSE, FALSE | |
80 | ); | |
81 | } | |
82 | ||
83 | /** | |
84 | * normalize the form values to make it look similar to the advanced form values | |
85 | * this prevents a ton of work downstream and allows us to use the same code for | |
86 | * multiple purposes (queries, save/edit etc) | |
87 | * | |
88 | * @return void | |
89 | * @access private | |
90 | */ | |
91 | function normalize() { | |
92 | $contactType = CRM_Utils_Array::value('contact_type', $this->_formValues); | |
93 | if ($contactType && !is_array($contactType)) { | |
94 | unset($this->_formValues['contact_type']); | |
95 | $this->_formValues['contact_type'][$contactType] = 1; | |
96 | } | |
97 | ||
98 | $group = CRM_Utils_Array::value('group', $this->_formValues); | |
99 | if ($group && !is_array($group)) { | |
100 | unset($this->_formValues['group']); | |
101 | $this->_formValues['group'][$group] = 1; | |
102 | } | |
103 | ||
104 | $tag = CRM_Utils_Array::value('tag', $this->_formValues); | |
105 | if ($tag && !is_array($tag)) { | |
106 | unset($this->_formValues['tag']); | |
107 | $this->_formValues['tag'][$tag] = 1; | |
108 | } | |
109 | ||
110 | return; | |
111 | } | |
112 | ||
86538308 EM |
113 | /** |
114 | * @param $form | |
115 | */ | |
6a488035 | 116 | function buildForm(&$form) { |
b500fbea EM |
117 | //@todo FIXME - using the CRM_Core_DAO::VALUE_SEPARATOR creates invalid html - if you can find the form |
118 | // this is loaded onto then replace with something like '__' & test | |
119 | $separator = CRM_Core_DAO::VALUE_SEPARATOR; | |
120 | $contactTypes = array('' => ts('- any contact type -')) + CRM_Contact_BAO_ContactType::getSelectElements(FALSE, TRUE, $separator); | |
24431f7b | 121 | $form->add('select', 'contact_type', ts('Find...'), $contactTypes, FALSE, array('class' => 'crm-select2 huge')); |
6a488035 TO |
122 | |
123 | // add select for groups | |
24431f7b CW |
124 | $group = array('' => ts('- any group -')) + CRM_Core_PseudoConstant::nestedGroup(); |
125 | $form->addElement('select', 'group', ts('in'), $group, array('class' => 'crm-select2 huge')); | |
6a488035 TO |
126 | |
127 | // add select for categories | |
cd43c5e3 | 128 | $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE)); |
24431f7b | 129 | $form->addElement('select', 'tag', ts('Tagged'), $tag, array('class' => 'crm-select2 huge')); |
6a488035 TO |
130 | |
131 | // text for sort_name | |
132 | $form->add('text', 'sort_name', ts('Name')); | |
133 | ||
134 | $form->assign('elements', array('sort_name', 'contact_type', 'group', 'tag')); | |
135 | } | |
136 | ||
86538308 EM |
137 | /** |
138 | * @return CRM_Contact_DAO_Contact | |
139 | */ | |
6a488035 TO |
140 | function count() { |
141 | return $this->_query->searchQuery(0, 0, NULL, TRUE); | |
142 | } | |
143 | ||
86538308 EM |
144 | /** |
145 | * @param int $offset | |
146 | * @param int $rowCount | |
147 | * @param null $sort | |
148 | * @param bool $includeContactIDs | |
149 | * @param bool $justIDs | |
150 | * | |
151 | * @return CRM_Contact_DAO_Contact | |
152 | */ | |
6a488035 TO |
153 | function all( |
154 | $offset = 0, | |
155 | $rowCount = 0, | |
156 | $sort = NULL, | |
157 | $includeContactIDs = FALSE, | |
158 | $justIDs = FALSE | |
159 | ) { | |
160 | return $this->_query->searchQuery( | |
161 | $offset, | |
162 | $rowCount, | |
163 | $sort, | |
164 | FALSE, | |
165 | $includeContactIDs, | |
166 | FALSE, | |
167 | $justIDs, | |
168 | TRUE | |
169 | ); | |
170 | } | |
171 | ||
86538308 EM |
172 | /** |
173 | * @return string | |
174 | */ | |
6a488035 TO |
175 | function from() { |
176 | return $this->_query->_fromClause; | |
177 | } | |
178 | ||
86538308 EM |
179 | /** |
180 | * @param bool $includeContactIDs | |
181 | * | |
182 | * @return string|void | |
183 | */ | |
6a488035 TO |
184 | function where($includeContactIDs = FALSE) { |
185 | if ($whereClause = $this->_query->whereClause()) { | |
186 | return $whereClause; | |
187 | } | |
188 | return ' (1) '; | |
189 | } | |
190 | ||
86538308 EM |
191 | /** |
192 | * @return string | |
193 | */ | |
6a488035 TO |
194 | function templateFile() { |
195 | return 'CRM/Contact/Form/Search/Basic.tpl'; | |
196 | } | |
6a488035 | 197 | |
86538308 EM |
198 | /** |
199 | * @return CRM_Contact_BAO_Query | |
200 | */ | |
d9ab802d PJ |
201 | function getQueryObj() { |
202 | return $this->_query; | |
203 | } | |
232624b1 | 204 | } |