Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | class CRM_Report_Form_Walklist_Walklist extends CRM_Report_Form { | |
36 | protected $_addressField = FALSE; | |
37 | ||
38 | protected $_emailField = FALSE; | |
39 | ||
40 | protected $_phoneField = FALSE; | |
41 | ||
42 | protected $_summary = NULL; | |
43 | ||
44 | public $_drilldownReport = array('contact/detail' => 'Link to Detail Report'); | |
45 | ||
46 | protected $_customGroupExtends = array( | |
9d72cede EM |
47 | 'Contact', |
48 | 'Individual', | |
49 | 'Household', | |
21dfd5f5 | 50 | 'Organization', |
430ae6dd TO |
51 | ); |
52 | ||
74cf4551 | 53 | /** |
74cf4551 EM |
54 | */ |
55 | /** | |
74cf4551 | 56 | */ |
00be9182 | 57 | public function __construct() { |
6a488035 | 58 | $this->_columns = array( |
9d72cede | 59 | 'civicrm_contact' => array( |
6a488035 | 60 | 'dao' => 'CRM_Contact_DAO_Contact', |
9d72cede EM |
61 | 'fields' => array( |
62 | 'id' => array( | |
63 | 'title' => ts('Contact ID'), | |
6a488035 TO |
64 | 'no_display' => TRUE, |
65 | 'required' => TRUE, | |
66 | ), | |
9d72cede EM |
67 | 'sort_name' => array( |
68 | 'title' => ts('Contact Name'), | |
6a488035 TO |
69 | 'required' => TRUE, |
70 | 'no_repeat' => TRUE, | |
71 | ), | |
72 | ), | |
9d72cede EM |
73 | 'filters' => array( |
74 | 'sort_name' => array( | |
75 | 'title' => ts('Contact Name'), | |
6a488035 TO |
76 | 'operator' => 'like', |
77 | ), | |
78 | ), | |
79 | 'grouping' => 'contact-fields', | |
9d72cede EM |
80 | 'order_bys' => array( |
81 | 'sort_name' => array( | |
82 | 'title' => ts('Contact Name'), | |
6a488035 | 83 | 'required' => TRUE, |
21dfd5f5 | 84 | ), |
9d72cede | 85 | ), |
6a488035 | 86 | ), |
9d72cede | 87 | 'civicrm_address' => array( |
6a488035 | 88 | 'dao' => 'CRM_Core_DAO_Address', |
9d72cede EM |
89 | 'fields' => array( |
90 | 'street_number' => array( | |
91 | 'title' => ts('Street Number'), | |
6a488035 TO |
92 | 'type' => 1, |
93 | ), | |
94 | 'street_address' => NULL, | |
95 | 'city' => NULL, | |
96 | 'postal_code' => NULL, | |
9d72cede EM |
97 | 'state_province_id' => array( |
98 | 'title' => ts('State/Province'), | |
6a488035 TO |
99 | 'default' => TRUE, |
100 | ), | |
9d72cede EM |
101 | 'country_id' => array( |
102 | 'title' => ts('Country'), | |
6a488035 TO |
103 | ), |
104 | ), | |
9d72cede EM |
105 | 'filters' => array( |
106 | 'street_number' => array( | |
107 | 'title' => ts('Street Number'), | |
6a488035 TO |
108 | 'type' => 1, |
109 | 'name' => 'street_number', | |
110 | ), | |
111 | 'street_address' => NULL, | |
112 | 'city' => NULL, | |
113 | ), | |
114 | 'grouping' => 'location-fields', | |
115 | ), | |
9d72cede | 116 | 'civicrm_email' => array( |
6a488035 | 117 | 'dao' => 'CRM_Core_DAO_Email', |
9d72cede | 118 | 'fields' => array('email' => array('default' => TRUE)), |
6a488035 TO |
119 | 'grouping' => 'location-fields', |
120 | ), | |
9d72cede | 121 | 'civicrm_phone' => array( |
6a488035 | 122 | 'dao' => 'CRM_Core_DAO_Phone', |
9d72cede | 123 | 'fields' => array('phone' => NULL), |
6a488035 TO |
124 | 'grouping' => 'location-fields', |
125 | ), | |
126 | ); | |
127 | parent::__construct(); | |
128 | } | |
129 | ||
00be9182 | 130 | public function preProcess() { |
6a488035 TO |
131 | parent::preProcess(); |
132 | } | |
133 | ||
00be9182 | 134 | public function select() { |
6a488035 TO |
135 | $select = array(); |
136 | ||
137 | $this->_columnHeaders = array(); | |
138 | foreach ($this->_columns as $tableName => $table) { | |
139 | foreach ($table['fields'] as $fieldName => $field) { | |
9d72cede EM |
140 | if (!empty($field['required']) || |
141 | !empty($this->_params['fields'][$fieldName]) | |
142 | ) { | |
6a488035 TO |
143 | if ($tableName == 'civicrm_address') { |
144 | $this->_addressField = TRUE; | |
145 | } | |
146 | elseif ($tableName == 'civicrm_email') { | |
147 | $this->_emailField = TRUE; | |
148 | } | |
149 | elseif ($tableName == 'civicrm_phone') { | |
150 | $this->_phoneField = TRUE; | |
151 | } | |
152 | ||
153 | $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}"; | |
154 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title']; | |
155 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = $field['type']; | |
156 | } | |
157 | } | |
158 | } | |
159 | ||
160 | $this->_select = "SELECT " . implode(",\n", $select) . " "; | |
161 | } | |
162 | ||
00be9182 | 163 | public function from() { |
6a488035 TO |
164 | $this->_from = NULL; |
165 | ||
166 | $this->_from = " | |
167 | FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom} | |
168 | "; | |
169 | if ($this->_addressField) { | |
170 | $this->_from .= "LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']} ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND {$this->_aliases['civicrm_address']}.is_primary = 1\n"; | |
171 | } | |
172 | ||
173 | if ($this->_emailField) { | |
174 | $this->_from .= "LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']} ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND {$this->_aliases['civicrm_email']}.is_primary = 1\n"; | |
175 | } | |
176 | ||
177 | if ($this->_phoneField) { | |
178 | $this->_from .= "LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']} ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND {$this->_aliases['civicrm_phone']}.is_primary = 1\n"; | |
179 | } | |
180 | } | |
181 | ||
00be9182 | 182 | public function where() { |
6a488035 TO |
183 | $clauses = array(); |
184 | foreach ($this->_columns as $tableName => $table) { | |
185 | if (array_key_exists('filters', $table)) { | |
186 | foreach ($table['filters'] as $fieldName => $field) { | |
187 | $clause = NULL; | |
188 | ||
189 | if ($field['type'] & CRM_Utils_Type::T_DATE) { | |
190 | $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params); | |
9d72cede EM |
191 | $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params); |
192 | $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params); | |
6a488035 TO |
193 | |
194 | $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']); | |
195 | } | |
196 | else { | |
197 | $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params); | |
198 | if ($op) { | |
199 | $clause = $this->whereClause($field, | |
200 | $op, | |
201 | CRM_Utils_Array::value("{$fieldName}_value", $this->_params), | |
202 | CRM_Utils_Array::value("{$fieldName}_min", $this->_params), | |
203 | CRM_Utils_Array::value("{$fieldName}_max", $this->_params) | |
204 | ); | |
205 | } | |
206 | } | |
207 | ||
208 | if (!empty($clause)) { | |
209 | $clauses[] = $clause; | |
210 | } | |
211 | } | |
212 | } | |
213 | } | |
214 | ||
215 | if (empty($clauses)) { | |
216 | $this->_where = "WHERE ( 1 ) "; | |
217 | } | |
218 | else { | |
219 | $this->_where = "WHERE " . implode(' AND ', $clauses); | |
220 | } | |
221 | ||
222 | if ($this->_aclWhere) { | |
223 | $this->_where .= " AND {$this->_aclWhere} "; | |
224 | } | |
225 | } | |
226 | ||
00be9182 | 227 | public function orderBy() { |
6a488035 TO |
228 | $this->_orderBy = ""; |
229 | foreach ($this->_columns as $tableName => $table) { | |
230 | if (array_key_exists('order_bys', $table)) { | |
231 | foreach ($table['order_bys'] as $fieldName => $field) { | |
232 | $this->_orderBy[] = $field['dbAlias']; | |
233 | } | |
234 | } | |
235 | } | |
236 | $this->_orderBy = "ORDER BY " . implode(', ', $this->_orderBy) . " "; | |
237 | } | |
238 | ||
00be9182 | 239 | public function postProcess() { |
6a488035 TO |
240 | // get the acl clauses built before we assemble the query |
241 | $this->buildACLClause($this->_aliases['civicrm_contact']); | |
242 | parent::postProcess(); | |
243 | } | |
244 | ||
74cf4551 | 245 | /** |
ced9bfed EM |
246 | * Alter display of rows. |
247 | * | |
248 | * Iterate through the rows retrieved via SQL and make changes for display purposes, | |
249 | * such as rendering contacts as links. | |
250 | * | |
251 | * @param array $rows | |
252 | * Rows generated by SQL, with an array for each row. | |
74cf4551 | 253 | */ |
00be9182 | 254 | public function alterDisplay(&$rows) { |
6a488035 TO |
255 | $entryFound = FALSE; |
256 | foreach ($rows as $rowNum => $row) { | |
257 | // handle state province | |
258 | if (array_key_exists('civicrm_address_state_province_id', $row)) { | |
259 | if ($value = $row['civicrm_address_state_province_id']) { | |
260 | $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value); | |
261 | } | |
262 | $entryFound = TRUE; | |
263 | } | |
264 | ||
265 | // handle country | |
266 | if (array_key_exists('civicrm_address_country_id', $row)) { | |
267 | if ($value = $row['civicrm_address_country_id']) { | |
268 | $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value); | |
269 | } | |
270 | $entryFound = TRUE; | |
271 | } | |
272 | ||
273 | // convert display name to links | |
274 | if (array_key_exists('civicrm_contact_sort_name', $row) && | |
275 | array_key_exists('civicrm_contact_id', $row) | |
276 | ) { | |
277 | $url = CRM_Report_Utils_Report::getNextUrl('contact/detail', | |
278 | 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id'], | |
279 | $this->_absoluteUrl, $this->_id, $this->_drilldownReport | |
280 | ); | |
281 | $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url; | |
282 | $entryFound = TRUE; | |
283 | } | |
284 | ||
285 | // skip looking further in rows, if first row itself doesn't | |
286 | // have the column we need | |
287 | if (!$entryFound) { | |
288 | break; | |
289 | } | |
290 | } | |
291 | } | |
96025800 | 292 | |
6a488035 | 293 | } |