Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | |
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
06b69b18 | 5 | | CiviCRM version 4.5 | |
6a488035 | 6 | +--------------------------------------------------------------------+ |
06b69b18 | 7 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | |
06b69b18 | 32 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
33 | * $Id$ |
34 | * | |
35 | */ | |
36 | class 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) { | |
8cc574cf | 225 | if (!empty($field['required']) || !empty($this->_params['fields'][$fieldName])) { |
6a488035 TO |
226 | if ($tableName == 'civicrm_email') { |
227 | $this->_emailField = TRUE; | |
228 | } | |
229 | elseif ($tableName == 'civicrm_phone') { | |
230 | $this->_phoneField = TRUE; | |
231 | } | |
232 | elseif ($tableName == 'civicrm_country') { | |
233 | $this->_countryField = TRUE; | |
234 | } | |
235 | ||
236 | $alias = "{$tableName}_{$fieldName}"; | |
237 | $select[] = "{$field['dbAlias']} as {$alias}"; | |
238 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field); | |
239 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title']; | |
240 | $this->_selectAliases[] = $alias; | |
241 | } | |
242 | } | |
243 | } | |
244 | } | |
245 | ||
246 | $this->_select = "SELECT " . implode(', ', $select) . " "; | |
247 | } | |
248 | ||
249 | static function formRule($fields, $files, $self) { | |
250 | $errors = $grouping = array(); | |
251 | return $errors; | |
252 | } | |
253 | ||
254 | function from() { | |
255 | $this->_from = " | |
256 | FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom} | |
2f4c2f5d | 257 | LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']} |
258 | ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND | |
6a488035 TO |
259 | {$this->_aliases['civicrm_address']}.is_primary = 1 ) "; |
260 | ||
261 | if ($this->isTableSelected('civicrm_email')) { | |
262 | $this->_from .= " | |
2f4c2f5d | 263 | LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']} |
6a488035 TO |
264 | ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND |
265 | {$this->_aliases['civicrm_email']}.is_primary = 1) "; | |
266 | } | |
267 | ||
268 | if ($this->_phoneField) { | |
269 | $this->_from .= " | |
2f4c2f5d | 270 | LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']} |
271 | ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND | |
6a488035 TO |
272 | {$this->_aliases['civicrm_phone']}.is_primary = 1 "; |
273 | } | |
274 | ||
275 | if ($this->isTableSelected('civicrm_country')) { | |
276 | $this->_from .= " | |
277 | LEFT JOIN civicrm_country {$this->_aliases['civicrm_country']} | |
278 | ON {$this->_aliases['civicrm_address']}.country_id = {$this->_aliases['civicrm_country']}.id AND | |
279 | {$this->_aliases['civicrm_address']}.is_primary = 1 "; | |
280 | } | |
281 | } | |
282 | ||
283 | function postProcess() { | |
284 | ||
285 | $this->beginPostProcess(); | |
286 | ||
287 | // get the acl clauses built before we assemble the query | |
288 | $this->buildACLClause($this->_aliases['civicrm_contact']); | |
289 | ||
290 | $sql = $this->buildQuery(TRUE); | |
291 | ||
292 | $rows = $graphRows = array(); | |
293 | $this->buildRows($sql, $rows); | |
294 | ||
295 | $this->formatDisplay($rows); | |
296 | $this->doTemplateAssignment($rows); | |
297 | $this->endPostProcess($rows); | |
298 | } | |
299 | ||
300 | function alterDisplay(&$rows) { | |
301 | // custom code to alter rows | |
302 | $entryFound = FALSE; | |
303 | foreach ($rows as $rowNum => $row) { | |
304 | // make count columns point to detail report | |
305 | // convert sort name to links | |
306 | if (array_key_exists('civicrm_contact_sort_name', $row) && | |
307 | array_key_exists('civicrm_contact_id', $row) | |
308 | ) { | |
309 | $url = CRM_Report_Utils_Report::getNextUrl('contact/detail', | |
310 | 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id'], | |
311 | $this->_absoluteUrl, $this->_id, $this->_drilldownReport | |
312 | ); | |
313 | $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url; | |
314 | $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Constituent Detail Report for this contact."); | |
315 | $entryFound = TRUE; | |
316 | } | |
317 | ||
318 | if (array_key_exists('civicrm_address_state_province_id', $row)) { | |
319 | if ($value = $row['civicrm_address_state_province_id']) { | |
320 | $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value, FALSE); | |
321 | } | |
322 | $entryFound = TRUE; | |
323 | } | |
324 | ||
325 | ||
326 | // skip looking further in rows, if first row itself doesn't | |
327 | // have the column we need | |
328 | if (!$entryFound) { | |
329 | break; | |
330 | } | |
331 | } | |
332 | } | |
333 | } | |
334 |