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'),
85 array('title' => ts('Contact Name')),
87 array('title' => ts('Contact Source'),
88 'type' => CRM_Utils_Type
::T_STRING
,
91 array('title' => ts('Contact ID'),
95 'grouping' => 'contact-fields',
100 'title' => ts('Last Name, First Name'), 'default' => '1', 'default_weight' => '0', 'default_order' => 'ASC',
106 'dao' => 'CRM_Core_DAO_Email',
110 array('title' => ts('Email'),
114 'grouping' => 'contact-fields',
118 array('title' => ts('Email'),
124 'dao' => 'CRM_Core_DAO_Address',
125 'grouping' => 'contact-fields',
129 array('default' => TRUE),
131 array('default' => TRUE),
132 'postal_code' => NULL,
133 'state_province_id' =>
134 array('title' => ts('State/Province'),
140 array('title' => ts('Country'),
141 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
142 'options' => CRM_Core_PseudoConstant
::country(),
144 'state_province_id' =>
145 array('title' => ts('State / Province'),
146 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
147 'options' => CRM_Core_PseudoConstant
::stateProvince(),
151 array('state_province_id' => array('title' => 'State/Province'),
152 'city' => array('title' => 'City'),
153 'postal_code' => array('title' => 'Postal Code'),
158 'dao' => 'CRM_Core_DAO_Country',
162 array('title' => 'Country', 'default' => TRUE),
167 array('title' => 'Country'),
169 'grouping' => 'contact-fields',
173 'dao' => 'CRM_Core_DAO_Phone',
179 'title' => ts('Phone Extension')
182 'grouping' => 'contact-fields',
186 'dao' => 'CRM_Contact_DAO_Group',
192 'name' => 'group_id',
193 'title' => ts('Group'),
194 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
196 'options' => CRM_Core_PseudoConstant
::group(),
202 $this->_tagFilter
= TRUE;
203 parent
::__construct();
206 function preProcess() {
207 parent
::preProcess();
212 $this->_columnHeaders
= array();
213 foreach ($this->_columns
as $tableName => $table) {
214 if (array_key_exists('fields', $table)) {
215 foreach ($table['fields'] as $fieldName => $field) {
216 if (CRM_Utils_Array
::value('required', $field) ||
217 CRM_Utils_Array
::value($fieldName, $this->_params
['fields'])
219 if ($tableName == 'civicrm_email') {
220 $this->_emailField
= TRUE;
222 elseif ($tableName == 'civicrm_phone') {
223 $this->_phoneField
= TRUE;
225 elseif ($tableName == 'civicrm_country') {
226 $this->_countryField
= TRUE;
229 $alias = "{$tableName}_{$fieldName}";
230 $select[] = "{$field['dbAlias']} as {$alias}";
231 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
232 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = $field['title'];
233 $this->_selectAliases
[] = $alias;
239 $this->_select
= "SELECT " . implode(', ', $select) . " ";
242 static function formRule($fields, $files, $self) {
243 $errors = $grouping = array();
249 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}
250 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
251 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
252 {$this->_aliases['civicrm_address']}.is_primary = 1 ) ";
254 if ($this->isTableSelected('civicrm_email')) {
256 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
257 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND
258 {$this->_aliases['civicrm_email']}.is_primary = 1) ";
261 if ($this->_phoneField
) {
263 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
264 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
265 {$this->_aliases['civicrm_phone']}.is_primary = 1 ";
268 if ($this->isTableSelected('civicrm_country')) {
270 LEFT JOIN civicrm_country {$this->_aliases['civicrm_country']}
271 ON {$this->_aliases['civicrm_address']}.country_id = {$this->_aliases['civicrm_country']}.id AND
272 {$this->_aliases['civicrm_address']}.is_primary = 1 ";
276 function postProcess() {
278 $this->beginPostProcess();
280 // get the acl clauses built before we assemble the query
281 $this->buildACLClause($this->_aliases
['civicrm_contact']);
283 $sql = $this->buildQuery(TRUE);
285 $rows = $graphRows = array();
286 $this->buildRows($sql, $rows);
288 $this->formatDisplay($rows);
289 $this->doTemplateAssignment($rows);
290 $this->endPostProcess($rows);
293 function alterDisplay(&$rows) {
294 // custom code to alter rows
296 foreach ($rows as $rowNum => $row) {
297 // make count columns point to detail report
298 // convert sort name to links
299 if (array_key_exists('civicrm_contact_sort_name', $row) &&
300 array_key_exists('civicrm_contact_id', $row)
302 $url = CRM_Report_Utils_Report
::getNextUrl('contact/detail',
303 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id'],
304 $this->_absoluteUrl
, $this->_id
, $this->_drilldownReport
306 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
307 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Constituent Detail Report for this contact.");
311 if (array_key_exists('civicrm_address_state_province_id', $row)) {
312 if ($value = $row['civicrm_address_state_province_id']) {
313 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant
::stateProvince($value, FALSE);
319 // skip looking further in rows, if first row itself doesn't
320 // have the column we need