4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2013
36 class CRM_Report_Form_Contact_Summary
extends CRM_Report_Form
{
38 protected $_summary = NULL;
40 protected $_emailField = FALSE;
42 protected $_phoneField = FALSE;
44 protected $_customGroupExtends = array(
45 'Contact', 'Individual', 'Household', 'Organization');
47 public $_drilldownReport = array('contact/detail' => 'Link to Detail Report');
49 function __construct() {
50 $this->_autoIncludeIndexedFieldsAsOrderBys
= 1;
51 $this->_columns
= array(
54 'dao' => 'CRM_Contact_DAO_Contact',
58 array('title' => ts('Contact Name'),
62 'first_name' => array(
63 'title' => ts('First Name'),
66 'title' => ts('Last Name'),
75 'title' => ts('Contact Type'),
79 'title' => ts('Contact SubType'),
83 'title' => ts('Birth Date'),
89 array('title' => ts('Contact Name')),
91 array('title' => ts('Contact Source'),
92 'type' => CRM_Utils_Type
::T_STRING
,
95 array('title' => ts('Contact ID'),
100 'title' => ts('Birth Date'),
101 'operatorType' => CRM_Report_Form
::OP_DATE
,
104 'grouping' => 'contact-fields',
109 'title' => ts('Last Name, First Name'), 'default' => '1', 'default_weight' => '0', 'default_order' => 'ASC',
115 'dao' => 'CRM_Core_DAO_Email',
119 array('title' => ts('Email'),
123 'grouping' => 'contact-fields',
127 array('title' => ts('Email'),
133 'dao' => 'CRM_Core_DAO_Address',
134 'grouping' => 'contact-fields',
138 array('default' => TRUE),
140 array('default' => TRUE),
141 'postal_code' => NULL,
142 'state_province_id' =>
143 array('title' => ts('State/Province'),
149 array('title' => ts('Country'),
150 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
151 'options' => CRM_Core_PseudoConstant
::country(),
153 'state_province_id' =>
154 array('title' => ts('State / Province'),
155 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
156 'options' => CRM_Core_PseudoConstant
::stateProvince(),
160 array('state_province_id' => array('title' => 'State/Province'),
161 'city' => array('title' => 'City'),
162 'postal_code' => array('title' => 'Postal Code'),
167 'dao' => 'CRM_Core_DAO_Country',
171 array('title' => 'Country', 'default' => TRUE),
176 array('title' => 'Country'),
178 'grouping' => 'contact-fields',
182 'dao' => 'CRM_Core_DAO_Phone',
188 'title' => ts('Phone Extension')
191 'grouping' => 'contact-fields',
195 'dao' => 'CRM_Contact_DAO_Group',
201 'name' => 'group_id',
202 'title' => ts('Group'),
203 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
205 'options' => CRM_Core_PseudoConstant
::group(),
211 $this->_tagFilter
= TRUE;
212 parent
::__construct();
215 function preProcess() {
216 parent
::preProcess();
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) {
225 if (CRM_Utils_Array
::value('required', $field) ||
226 CRM_Utils_Array
::value($fieldName, $this->_params
['fields'])
228 if ($tableName == 'civicrm_email') {
229 $this->_emailField
= TRUE;
231 elseif ($tableName == 'civicrm_phone') {
232 $this->_phoneField
= TRUE;
234 elseif ($tableName == 'civicrm_country') {
235 $this->_countryField
= TRUE;
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;
248 $this->_select
= "SELECT " . implode(', ', $select) . " ";
251 static function formRule($fields, $files, $self) {
252 $errors = $grouping = array();
258 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}
259 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
260 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
261 {$this->_aliases['civicrm_address']}.is_primary = 1 ) ";
263 if ($this->isTableSelected('civicrm_email')) {
265 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
266 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND
267 {$this->_aliases['civicrm_email']}.is_primary = 1) ";
270 if ($this->_phoneField
) {
272 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
273 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
274 {$this->_aliases['civicrm_phone']}.is_primary = 1 ";
277 if ($this->isTableSelected('civicrm_country')) {
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 ";
285 function postProcess() {
287 $this->beginPostProcess();
289 // get the acl clauses built before we assemble the query
290 $this->buildACLClause($this->_aliases
['civicrm_contact']);
292 $sql = $this->buildQuery(TRUE);
294 $rows = $graphRows = array();
295 $this->buildRows($sql, $rows);
297 $this->formatDisplay($rows);
298 $this->doTemplateAssignment($rows);
299 $this->endPostProcess($rows);
302 function alterDisplay(&$rows) {
303 // custom code to alter rows
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)
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
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.");
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);
328 // skip looking further in rows, if first row itself doesn't
329 // have the column we need