Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
0f03f337 | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
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 | |
0f03f337 | 31 | * @copyright CiviCRM LLC (c) 2004-2017 |
6a488035 TO |
32 | */ |
33 | class CRM_Report_Form_Contact_Summary extends CRM_Report_Form { | |
34 | ||
adda1ff2 | 35 | public $_summary = NULL; |
6a488035 TO |
36 | |
37 | protected $_emailField = FALSE; | |
38 | ||
39 | protected $_phoneField = FALSE; | |
40 | ||
41 | protected $_customGroupExtends = array( | |
9d72cede EM |
42 | 'Contact', |
43 | 'Individual', | |
44 | 'Household', | |
21dfd5f5 | 45 | 'Organization', |
9d72cede | 46 | ); |
6a488035 TO |
47 | |
48 | public $_drilldownReport = array('contact/detail' => 'Link to Detail Report'); | |
49 | ||
74cf4551 | 50 | /** |
1728e9a0 | 51 | * This report has not been optimised for group filtering. |
52 | * | |
53 | * The functionality for group filtering has been improved but not | |
54 | * all reports have been adjusted to take care of it. This report has not | |
55 | * and will run an inefficient query until fixed. | |
56 | * | |
57 | * CRM-19170 | |
58 | * | |
59 | * @var bool | |
60 | */ | |
61 | protected $groupFilterNotOptimised = TRUE; | |
62 | ||
63 | /** | |
64 | * Class constructor. | |
74cf4551 | 65 | */ |
00be9182 | 66 | public function __construct() { |
6a488035 TO |
67 | $this->_autoIncludeIndexedFieldsAsOrderBys = 1; |
68 | $this->_columns = array( | |
7c550ca0 WA |
69 | 'civicrm_contact' => array( |
70 | 'dao' => 'CRM_Contact_DAO_Contact', | |
0e2388dc J |
71 | 'fields' => array_merge( |
72 | $this->getBasicContactFields(), | |
73 | array( | |
74 | 'modified_date' => array( | |
75 | 'title' => ts('Modified Date'), | |
76 | 'default' => FALSE, | |
77 | ), | |
78 | ) | |
6a488035 | 79 | ), |
aceb083a | 80 | 'filters' => $this->getBasicContactFilters(), |
7c550ca0 WA |
81 | 'grouping' => 'contact-fields', |
82 | 'order_bys' => array( | |
83 | 'sort_name' => array( | |
84 | 'title' => ts('Last Name, First Name'), | |
85 | 'default' => '1', | |
86 | 'default_weight' => '0', | |
87 | 'default_order' => 'ASC', | |
88 | ), | |
70bea8e2 | 89 | 'first_name' => array( |
90 | 'name' => 'first_name', | |
91 | 'title' => ts('First Name'), | |
92 | ), | |
7c550ca0 WA |
93 | 'gender_id' => array( |
94 | 'name' => 'gender_id', | |
95 | 'title' => ts('Gender'), | |
96 | ), | |
97 | 'birth_date' => array( | |
98 | 'name' => 'birth_date', | |
99 | 'title' => ts('Birth Date'), | |
6a488035 | 100 | ), |
70bea8e2 | 101 | 'contact_type' => array( |
102 | 'title' => ts('Contact Type'), | |
103 | ), | |
104 | 'contact_sub_type' => array( | |
105 | 'title' => ts('Contact Subtype'), | |
106 | ), | |
6a488035 | 107 | ), |
7c550ca0 WA |
108 | ), |
109 | 'civicrm_email' => array( | |
110 | 'dao' => 'CRM_Core_DAO_Email', | |
111 | 'fields' => array( | |
112 | 'email' => array( | |
113 | 'title' => ts('Email'), | |
114 | 'no_repeat' => TRUE, | |
115 | ), | |
116 | ), | |
117 | 'grouping' => 'contact-fields', | |
118 | 'order_bys' => array( | |
119 | 'email' => array( | |
120 | 'title' => ts('Email'), | |
121 | ), | |
122 | ), | |
123 | ), | |
124 | 'civicrm_phone' => array( | |
125 | 'dao' => 'CRM_Core_DAO_Phone', | |
126 | 'fields' => array( | |
127 | 'phone' => NULL, | |
128 | 'phone_ext' => array( | |
129 | 'title' => ts('Phone Extension'), | |
130 | ), | |
6a488035 | 131 | ), |
7c550ca0 WA |
132 | 'grouping' => 'contact-fields', |
133 | ), | |
134 | ) + $this->getAddressColumns(array('group_by' => FALSE)); | |
6a488035 | 135 | |
16e2e80c | 136 | $this->_groupFilter = TRUE; |
6a488035 TO |
137 | $this->_tagFilter = TRUE; |
138 | parent::__construct(); | |
139 | } | |
140 | ||
00be9182 | 141 | public function preProcess() { |
6a488035 TO |
142 | parent::preProcess(); |
143 | } | |
144 | ||
00be9182 | 145 | public function select() { |
6a488035 TO |
146 | $select = array(); |
147 | $this->_columnHeaders = array(); | |
148 | foreach ($this->_columns as $tableName => $table) { | |
149 | if (array_key_exists('fields', $table)) { | |
150 | foreach ($table['fields'] as $fieldName => $field) { | |
9d72cede EM |
151 | if (!empty($field['required']) || |
152 | !empty($this->_params['fields'][$fieldName]) | |
153 | ) { | |
6a488035 TO |
154 | if ($tableName == 'civicrm_email') { |
155 | $this->_emailField = TRUE; | |
156 | } | |
157 | elseif ($tableName == 'civicrm_phone') { | |
158 | $this->_phoneField = TRUE; | |
159 | } | |
160 | elseif ($tableName == 'civicrm_country') { | |
161 | $this->_countryField = TRUE; | |
162 | } | |
163 | ||
164 | $alias = "{$tableName}_{$fieldName}"; | |
165 | $select[] = "{$field['dbAlias']} as {$alias}"; | |
166 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field); | |
167 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title']; | |
168 | $this->_selectAliases[] = $alias; | |
169 | } | |
170 | } | |
171 | } | |
172 | } | |
173 | ||
174 | $this->_select = "SELECT " . implode(', ', $select) . " "; | |
175 | } | |
176 | ||
74cf4551 EM |
177 | /** |
178 | * @param $fields | |
179 | * @param $files | |
180 | * @param $self | |
181 | * | |
182 | * @return array | |
183 | */ | |
00be9182 | 184 | public static function formRule($fields, $files, $self) { |
6a488035 TO |
185 | $errors = $grouping = array(); |
186 | return $errors; | |
187 | } | |
188 | ||
00be9182 | 189 | public function from() { |
6a488035 TO |
190 | $this->_from = " |
191 | FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom} | |
2f4c2f5d | 192 | LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']} |
193 | ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND | |
6a488035 TO |
194 | {$this->_aliases['civicrm_address']}.is_primary = 1 ) "; |
195 | ||
196 | if ($this->isTableSelected('civicrm_email')) { | |
197 | $this->_from .= " | |
2f4c2f5d | 198 | LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']} |
6a488035 TO |
199 | ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND |
200 | {$this->_aliases['civicrm_email']}.is_primary = 1) "; | |
201 | } | |
202 | ||
203 | if ($this->_phoneField) { | |
204 | $this->_from .= " | |
2f4c2f5d | 205 | LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']} |
206 | ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND | |
6a488035 TO |
207 | {$this->_aliases['civicrm_phone']}.is_primary = 1 "; |
208 | } | |
209 | ||
210 | if ($this->isTableSelected('civicrm_country')) { | |
211 | $this->_from .= " | |
212 | LEFT JOIN civicrm_country {$this->_aliases['civicrm_country']} | |
213 | ON {$this->_aliases['civicrm_address']}.country_id = {$this->_aliases['civicrm_country']}.id AND | |
214 | {$this->_aliases['civicrm_address']}.is_primary = 1 "; | |
215 | } | |
216 | } | |
217 | ||
00be9182 | 218 | public function postProcess() { |
6a488035 TO |
219 | |
220 | $this->beginPostProcess(); | |
221 | ||
222 | // get the acl clauses built before we assemble the query | |
223 | $this->buildACLClause($this->_aliases['civicrm_contact']); | |
224 | ||
225 | $sql = $this->buildQuery(TRUE); | |
226 | ||
227 | $rows = $graphRows = array(); | |
228 | $this->buildRows($sql, $rows); | |
229 | ||
230 | $this->formatDisplay($rows); | |
231 | $this->doTemplateAssignment($rows); | |
232 | $this->endPostProcess($rows); | |
233 | } | |
234 | ||
ced9bfed EM |
235 | /** |
236 | * Alter display of rows. | |
237 | * | |
238 | * Iterate through the rows retrieved via SQL and make changes for display purposes, | |
239 | * such as rendering contacts as links. | |
240 | * | |
241 | * @param array $rows | |
242 | * Rows generated by SQL, with an array for each row. | |
243 | */ | |
00be9182 | 244 | public function alterDisplay(&$rows) { |
6a488035 | 245 | $entryFound = FALSE; |
1fd5431f | 246 | |
6a488035 TO |
247 | foreach ($rows as $rowNum => $row) { |
248 | // make count columns point to detail report | |
249 | // convert sort name to links | |
250 | if (array_key_exists('civicrm_contact_sort_name', $row) && | |
251 | array_key_exists('civicrm_contact_id', $row) | |
252 | ) { | |
253 | $url = CRM_Report_Utils_Report::getNextUrl('contact/detail', | |
254 | 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id'], | |
255 | $this->_absoluteUrl, $this->_id, $this->_drilldownReport | |
256 | ); | |
257 | $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url; | |
37935ea7 | 258 | $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts('View Contact Detail Report for this contact'); |
6a488035 TO |
259 | $entryFound = TRUE; |
260 | } | |
261 | ||
262 | if (array_key_exists('civicrm_address_state_province_id', $row)) { | |
263 | if ($value = $row['civicrm_address_state_province_id']) { | |
264 | $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value, FALSE); | |
265 | } | |
266 | $entryFound = TRUE; | |
267 | } | |
268 | ||
cb1dc4f3 | 269 | if (array_key_exists('civicrm_address_country_id', $row)) { |
270 | if ($value = $row['civicrm_address_country_id']) { | |
271 | $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value, FALSE); | |
272 | } | |
273 | $entryFound = TRUE; | |
274 | } | |
275 | ||
0e2388dc J |
276 | // Handle ID to label conversion for contact fields |
277 | $entryFound = $this->alterDisplayContactFields($row, $rows, $rowNum, 'contact/summary', 'View Contact Summary') ? TRUE : $entryFound; | |
1fd5431f | 278 | |
279 | // display birthday in the configured custom format | |
280 | if (array_key_exists('civicrm_contact_birth_date', $row)) { | |
281 | $birthDate = $row['civicrm_contact_birth_date']; | |
282 | if ($birthDate) { | |
283 | $rows[$rowNum]['civicrm_contact_birth_date'] = CRM_Utils_Date::customFormat($birthDate, '%Y%m%d'); | |
284 | } | |
285 | $entryFound = TRUE; | |
286 | } | |
6a488035 TO |
287 | |
288 | // skip looking further in rows, if first row itself doesn't | |
289 | // have the column we need | |
290 | if (!$entryFound) { | |
291 | break; | |
292 | } | |
293 | } | |
294 | } | |
96025800 | 295 | |
6a488035 | 296 | } |