4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.5 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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');
55 function __construct() {
56 $this->_autoIncludeIndexedFieldsAsOrderBys
= 1;
57 $this->_columns
= array(
60 'dao' => 'CRM_Contact_DAO_Contact',
64 array('title' => ts('Contact Name'),
68 'first_name' => array(
69 'title' => ts('First Name'),
72 'title' => ts('Last Name'),
81 'title' => ts('Contact Type'),
85 'title' => ts('Contact SubType'),
89 'title' => ts('Birth Date'),
95 array('title' => ts('Contact Name')),
97 array('title' => ts('Contact Source'),
98 'type' => CRM_Utils_Type
::T_STRING
,
101 array('title' => ts('Contact ID'),
102 'no_display' => TRUE,
106 'title' => ts('Birth Date'),
107 'operatorType' => CRM_Report_Form
::OP_DATE
,
110 'grouping' => 'contact-fields',
115 'title' => ts('Last Name, First Name'), 'default' => '1', 'default_weight' => '0', 'default_order' => 'ASC',
121 'dao' => 'CRM_Core_DAO_Email',
125 array('title' => ts('Email'),
129 'grouping' => 'contact-fields',
133 array('title' => ts('Email'),
139 'dao' => 'CRM_Core_DAO_Address',
140 'grouping' => 'contact-fields',
144 array('default' => TRUE),
146 array('default' => TRUE),
147 'postal_code' => NULL,
148 'state_province_id' =>
149 array('title' => ts('State/Province'),
155 array('title' => ts('Country'),
156 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
157 'options' => CRM_Core_PseudoConstant
::country(),
159 'state_province_id' =>
160 array('title' => ts('State / Province'),
161 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
162 'options' => CRM_Core_PseudoConstant
::stateProvince(),
166 array('state_province_id' => array('title' => 'State/Province'),
167 'city' => array('title' => 'City'),
168 'postal_code' => array('title' => 'Postal Code'),
173 'dao' => 'CRM_Core_DAO_Country',
177 array('title' => 'Country', 'default' => TRUE),
182 array('title' => 'Country'),
184 'grouping' => 'contact-fields',
188 'dao' => 'CRM_Core_DAO_Phone',
194 'title' => ts('Phone Extension')
197 'grouping' => 'contact-fields',
201 'dao' => 'CRM_Contact_DAO_Group',
207 'name' => 'group_id',
208 'title' => ts('Group'),
209 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
211 'options' => CRM_Core_PseudoConstant
::group(),
217 $this->_tagFilter
= TRUE;
218 parent
::__construct();
221 function preProcess() {
222 parent
::preProcess();
227 $this->_columnHeaders
= array();
228 foreach ($this->_columns
as $tableName => $table) {
229 if (array_key_exists('fields', $table)) {
230 foreach ($table['fields'] as $fieldName => $field) {
231 if (!empty($field['required']) ||
!empty($this->_params
['fields'][$fieldName])) {
232 if ($tableName == 'civicrm_email') {
233 $this->_emailField
= TRUE;
235 elseif ($tableName == 'civicrm_phone') {
236 $this->_phoneField
= TRUE;
238 elseif ($tableName == 'civicrm_country') {
239 $this->_countryField
= TRUE;
242 $alias = "{$tableName}_{$fieldName}";
243 $select[] = "{$field['dbAlias']} as {$alias}";
244 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
245 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = $field['title'];
246 $this->_selectAliases
[] = $alias;
252 $this->_select
= "SELECT " . implode(', ', $select) . " ";
262 static function formRule($fields, $files, $self) {
263 $errors = $grouping = array();
269 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}
270 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
271 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
272 {$this->_aliases['civicrm_address']}.is_primary = 1 ) ";
274 if ($this->isTableSelected('civicrm_email')) {
276 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
277 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND
278 {$this->_aliases['civicrm_email']}.is_primary = 1) ";
281 if ($this->_phoneField
) {
283 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
284 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
285 {$this->_aliases['civicrm_phone']}.is_primary = 1 ";
288 if ($this->isTableSelected('civicrm_country')) {
290 LEFT JOIN civicrm_country {$this->_aliases['civicrm_country']}
291 ON {$this->_aliases['civicrm_address']}.country_id = {$this->_aliases['civicrm_country']}.id AND
292 {$this->_aliases['civicrm_address']}.is_primary = 1 ";
296 function postProcess() {
298 $this->beginPostProcess();
300 // get the acl clauses built before we assemble the query
301 $this->buildACLClause($this->_aliases
['civicrm_contact']);
303 $sql = $this->buildQuery(TRUE);
305 $rows = $graphRows = array();
306 $this->buildRows($sql, $rows);
308 $this->formatDisplay($rows);
309 $this->doTemplateAssignment($rows);
310 $this->endPostProcess($rows);
316 function alterDisplay(&$rows) {
317 // custom code to alter rows
319 foreach ($rows as $rowNum => $row) {
320 // make count columns point to detail report
321 // convert sort name to links
322 if (array_key_exists('civicrm_contact_sort_name', $row) &&
323 array_key_exists('civicrm_contact_id', $row)
325 $url = CRM_Report_Utils_Report
::getNextUrl('contact/detail',
326 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id'],
327 $this->_absoluteUrl
, $this->_id
, $this->_drilldownReport
329 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
330 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Constituent Detail Report for this contact.");
334 if (array_key_exists('civicrm_address_state_province_id', $row)) {
335 if ($value = $row['civicrm_address_state_province_id']) {
336 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant
::stateProvince($value, FALSE);
342 // skip looking further in rows, if first row itself doesn't
343 // have the column we need