CRM-14106 - Regex targeting the first part of if statements
[civicrm-core.git] / CRM / Report / Form / Contact / Summary.php
CommitLineData
6a488035 1<?php
6a488035
TO
2
3/*
4 +--------------------------------------------------------------------+
232624b1 5 | CiviCRM version 4.4 |
6a488035
TO
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
27*/
28
29/**
30 *
31 * @package CRM
32 * @copyright CiviCRM LLC (c) 2004-2013
33 * $Id$
34 *
35 */
36class CRM_Report_Form_Contact_Summary extends CRM_Report_Form {
37
38 protected $_summary = NULL;
39
40 protected $_emailField = FALSE;
41
42 protected $_phoneField = FALSE;
43
44 protected $_customGroupExtends = array(
2f4c2f5d 45 'Contact', 'Individual', 'Household', 'Organization');
6a488035
TO
46
47 public $_drilldownReport = array('contact/detail' => 'Link to Detail Report');
48
49 function __construct() {
50 $this->_autoIncludeIndexedFieldsAsOrderBys = 1;
51 $this->_columns = array(
52 'civicrm_contact' =>
53 array(
54 'dao' => 'CRM_Contact_DAO_Contact',
55 'fields' =>
56 array(
57 'sort_name' =>
58 array('title' => ts('Contact Name'),
59 'required' => TRUE,
60 'no_repeat' => TRUE,
61 ),
30f85891
RN
62 'first_name' => array(
63 'title' => ts('First Name'),
6a488035 64 ),
30f85891
RN
65 'last_name' => array(
66 'title' => ts('Last Name'),
6a488035
TO
67 ),
68 'id' =>
69 array(
70 'no_display' => TRUE,
71 'required' => TRUE,
72 ),
30f85891
RN
73 'contact_type' =>
74 array(
75 'title' => ts('Contact Type'),
76 ),
77 'contact_sub_type' =>
78 array(
79 'title' => ts('Contact SubType'),
80 ),
c0568199
RN
81 'birth_date' =>
82 array(
83 'title' => ts('Birth Date'),
84 ),
6a488035
TO
85 ),
86 'filters' =>
87 array(
88 'sort_name' =>
89 array('title' => ts('Contact Name')),
90 'source' =>
91 array('title' => ts('Contact Source'),
92 'type' => CRM_Utils_Type::T_STRING,
93 ),
94 'id' =>
95 array('title' => ts('Contact ID'),
96 'no_display' => TRUE,
97 ),
c0568199
RN
98 'birth_date' =>
99 array(
100 'title' => ts('Birth Date'),
101 'operatorType' => CRM_Report_Form::OP_DATE,
102 ),
6a488035
TO
103 ),
104 'grouping' => 'contact-fields',
105 'order_bys' =>
106 array(
107 'sort_name' =>
108 array(
109 'title' => ts('Last Name, First Name'), 'default' => '1', 'default_weight' => '0', 'default_order' => 'ASC',
110 ),
111 ),
112 ),
113 'civicrm_email' =>
114 array(
115 'dao' => 'CRM_Core_DAO_Email',
116 'fields' =>
117 array(
118 'email' =>
119 array('title' => ts('Email'),
120 'no_repeat' => TRUE,
121 ),
122 ),
123 'grouping' => 'contact-fields',
124 'order_bys' =>
125 array(
126 'email' =>
127 array('title' => ts('Email'),
128 ),
129 ),
130 ),
131 'civicrm_address' =>
132 array(
133 'dao' => 'CRM_Core_DAO_Address',
134 'grouping' => 'contact-fields',
135 'fields' =>
136 array(
137 'street_address' =>
138 array('default' => TRUE),
139 'city' =>
140 array('default' => TRUE),
141 'postal_code' => NULL,
142 'state_province_id' =>
143 array('title' => ts('State/Province'),
144 ),
145 ),
146 'filters' =>
147 array(
148 'country_id' =>
149 array('title' => ts('Country'),
150 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
151 'options' => CRM_Core_PseudoConstant::country(),
152 ),
153 'state_province_id' =>
154 array('title' => ts('State / Province'),
155 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
156 'options' => CRM_Core_PseudoConstant::stateProvince(),
157 ),
158 ),
159 'order_bys' =>
160 array('state_province_id' => array('title' => 'State/Province'),
161 'city' => array('title' => 'City'),
162 'postal_code' => array('title' => 'Postal Code'),
163 ),
164 ),
165 'civicrm_country' =>
166 array(
167 'dao' => 'CRM_Core_DAO_Country',
168 'fields' =>
169 array(
170 'name' =>
171 array('title' => 'Country', 'default' => TRUE),
172 ),
173 'order_bys' =>
174 array(
175 'name' =>
176 array('title' => 'Country'),
177 ),
178 'grouping' => 'contact-fields',
179 ),
180 'civicrm_phone' =>
181 array(
182 'dao' => 'CRM_Core_DAO_Phone',
183 'fields' =>
476c4ae5
JL
184 array(
185 'phone' => NULL,
186 'phone_ext' =>
187 array(
188 'title' => ts('Phone Extension')
189 )
190 ),
6a488035
TO
191 'grouping' => 'contact-fields',
192 ),
193 'civicrm_group' =>
194 array(
195 'dao' => 'CRM_Contact_DAO_Group',
196 'alias' => 'cgroup',
197 'filters' =>
198 array(
199 'gid' =>
200 array(
201 'name' => 'group_id',
202 'title' => ts('Group'),
203 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
204 'group' => TRUE,
205 'options' => CRM_Core_PseudoConstant::group(),
206 ),
207 ),
208 ),
209 );
210
211 $this->_tagFilter = TRUE;
212 parent::__construct();
213 }
214
215 function preProcess() {
216 parent::preProcess();
217 }
218
219 function select() {
220 $select = array();
221 $this->_columnHeaders = array();
222 foreach ($this->_columns as $tableName => $table) {
223 if (array_key_exists('fields', $table)) {
224 foreach ($table['fields'] as $fieldName => $field) {
a7488080 225 if (!empty($field['required']) ||
6a488035
TO
226 CRM_Utils_Array::value($fieldName, $this->_params['fields'])
227 ) {
228 if ($tableName == 'civicrm_email') {
229 $this->_emailField = TRUE;
230 }
231 elseif ($tableName == 'civicrm_phone') {
232 $this->_phoneField = TRUE;
233 }
234 elseif ($tableName == 'civicrm_country') {
235 $this->_countryField = TRUE;
236 }
237
238 $alias = "{$tableName}_{$fieldName}";
239 $select[] = "{$field['dbAlias']} as {$alias}";
240 $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
241 $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title'];
242 $this->_selectAliases[] = $alias;
243 }
244 }
245 }
246 }
247
248 $this->_select = "SELECT " . implode(', ', $select) . " ";
249 }
250
251 static function formRule($fields, $files, $self) {
252 $errors = $grouping = array();
253 return $errors;
254 }
255
256 function from() {
257 $this->_from = "
258 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}
2f4c2f5d 259 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
260 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
6a488035
TO
261 {$this->_aliases['civicrm_address']}.is_primary = 1 ) ";
262
263 if ($this->isTableSelected('civicrm_email')) {
264 $this->_from .= "
2f4c2f5d 265 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
6a488035
TO
266 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND
267 {$this->_aliases['civicrm_email']}.is_primary = 1) ";
268 }
269
270 if ($this->_phoneField) {
271 $this->_from .= "
2f4c2f5d 272 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
273 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
6a488035
TO
274 {$this->_aliases['civicrm_phone']}.is_primary = 1 ";
275 }
276
277 if ($this->isTableSelected('civicrm_country')) {
278 $this->_from .= "
279 LEFT JOIN civicrm_country {$this->_aliases['civicrm_country']}
280 ON {$this->_aliases['civicrm_address']}.country_id = {$this->_aliases['civicrm_country']}.id AND
281 {$this->_aliases['civicrm_address']}.is_primary = 1 ";
282 }
283 }
284
285 function postProcess() {
286
287 $this->beginPostProcess();
288
289 // get the acl clauses built before we assemble the query
290 $this->buildACLClause($this->_aliases['civicrm_contact']);
291
292 $sql = $this->buildQuery(TRUE);
293
294 $rows = $graphRows = array();
295 $this->buildRows($sql, $rows);
296
297 $this->formatDisplay($rows);
298 $this->doTemplateAssignment($rows);
299 $this->endPostProcess($rows);
300 }
301
302 function alterDisplay(&$rows) {
303 // custom code to alter rows
304 $entryFound = FALSE;
305 foreach ($rows as $rowNum => $row) {
306 // make count columns point to detail report
307 // convert sort name to links
308 if (array_key_exists('civicrm_contact_sort_name', $row) &&
309 array_key_exists('civicrm_contact_id', $row)
310 ) {
311 $url = CRM_Report_Utils_Report::getNextUrl('contact/detail',
312 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id'],
313 $this->_absoluteUrl, $this->_id, $this->_drilldownReport
314 );
315 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
316 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Constituent Detail Report for this contact.");
317 $entryFound = TRUE;
318 }
319
320 if (array_key_exists('civicrm_address_state_province_id', $row)) {
321 if ($value = $row['civicrm_address_state_province_id']) {
322 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value, FALSE);
323 }
324 $entryFound = TRUE;
325 }
326
327
328 // skip looking further in rows, if first row itself doesn't
329 // have the column we need
330 if (!$entryFound) {
331 break;
332 }
333 }
334 }
335}
336