3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2017
33 class CRM_Report_Form_Contact_Summary
extends CRM_Report_Form
{
35 public $_summary = NULL;
37 protected $_emailField = FALSE;
39 protected $_phoneField = FALSE;
41 protected $_customGroupExtends = array(
48 public $_drilldownReport = array('contact/detail' => 'Link to Detail Report');
51 * This report has not been optimised for group filtering.
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.
61 protected $groupFilterNotOptimised = TRUE;
66 public function __construct() {
67 $this->_autoIncludeIndexedFieldsAsOrderBys
= 1;
68 $this->_columns
= array(
69 'civicrm_contact' => array(
70 'dao' => 'CRM_Contact_DAO_Contact',
71 'fields' => array_merge(
72 $this->getBasicContactFields(),
74 'modified_date' => array(
75 'title' => ts('Modified Date'),
80 'filters' => $this->getBasicContactFilters(),
81 'grouping' => 'contact-fields',
84 'title' => ts('Last Name, First Name'),
86 'default_weight' => '0',
87 'default_order' => 'ASC',
89 'first_name' => array(
90 'name' => 'first_name',
91 'title' => ts('First Name'),
94 'name' => 'gender_id',
95 'title' => ts('Gender'),
97 'birth_date' => array(
98 'name' => 'birth_date',
99 'title' => ts('Birth Date'),
101 'contact_type' => array(
102 'title' => ts('Contact Type'),
104 'contact_sub_type' => array(
105 'title' => ts('Contact Subtype'),
109 'civicrm_email' => array(
110 'dao' => 'CRM_Core_DAO_Email',
113 'title' => ts('Email'),
117 'grouping' => 'contact-fields',
118 'order_bys' => array(
120 'title' => ts('Email'),
124 'civicrm_phone' => array(
125 'dao' => 'CRM_Core_DAO_Phone',
128 'phone_ext' => array(
129 'title' => ts('Phone Extension'),
132 'grouping' => 'contact-fields',
134 ) +
$this->getAddressColumns(array('group_by' => FALSE));
136 $this->_groupFilter
= TRUE;
137 $this->_tagFilter
= TRUE;
138 parent
::__construct();
141 public function preProcess() {
142 parent
::preProcess();
145 public function select() {
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) {
151 if (!empty($field['required']) ||
152 !empty($this->_params
['fields'][$fieldName])
154 if ($tableName == 'civicrm_email') {
155 $this->_emailField
= TRUE;
157 elseif ($tableName == 'civicrm_phone') {
158 $this->_phoneField
= TRUE;
160 elseif ($tableName == 'civicrm_country') {
161 $this->_countryField
= TRUE;
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;
174 $this->_select
= "SELECT " . implode(', ', $select) . " ";
184 public static function formRule($fields, $files, $self) {
185 $errors = $grouping = array();
189 public function from() {
191 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}
192 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
193 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
194 {$this->_aliases['civicrm_address']}.is_primary = 1 ) ";
196 if ($this->isTableSelected('civicrm_email')) {
198 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
199 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND
200 {$this->_aliases['civicrm_email']}.is_primary = 1) ";
203 if ($this->_phoneField
) {
205 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
206 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
207 {$this->_aliases['civicrm_phone']}.is_primary = 1 ";
210 if ($this->isTableSelected('civicrm_country')) {
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 ";
218 public function postProcess() {
220 $this->beginPostProcess();
222 // get the acl clauses built before we assemble the query
223 $this->buildACLClause($this->_aliases
['civicrm_contact']);
225 $sql = $this->buildQuery(TRUE);
227 $rows = $graphRows = array();
228 $this->buildRows($sql, $rows);
230 $this->formatDisplay($rows);
231 $this->doTemplateAssignment($rows);
232 $this->endPostProcess($rows);
236 * Alter display of rows.
238 * Iterate through the rows retrieved via SQL and make changes for display purposes,
239 * such as rendering contacts as links.
242 * Rows generated by SQL, with an array for each row.
244 public function alterDisplay(&$rows) {
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)
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
257 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
258 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts('View Contact Detail Report for this contact');
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);
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);
276 // Handle ID to label conversion for contact fields
277 $entryFound = $this->alterDisplayContactFields($row, $rows, $rowNum, 'contact/summary', 'View Contact Summary') ?
TRUE : $entryFound;
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'];
283 $rows[$rowNum]['civicrm_contact_birth_date'] = CRM_Utils_Date
::customFormat($birthDate, '%Y%m%d');
288 // skip looking further in rows, if first row itself doesn't
289 // have the column we need