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_Log
extends CRM_Report_Form
{
38 protected $_summary = NULL;
39 function __construct() {
41 $this->activityTypes
= CRM_Core_PseudoConstant
::activityType(TRUE, TRUE);
42 asort($this->activityTypes
);
44 $this->_columns
= array(
47 'dao' => 'CRM_Contact_DAO_Contact',
51 array('title' => ts('Modified By'),
63 array('title' => ts('Modified By'),
64 'type' => CRM_Utils_Type
::T_STRING
,
67 'grouping' => 'contact-fields',
69 'civicrm_contact_touched' =>
71 'dao' => 'CRM_Contact_DAO_Contact',
74 'sort_name_touched' =>
75 array('title' => ts('Touched Contact'),
76 'name' => 'sort_name',
87 'sort_name_touched' =>
88 array('title' => ts('Touched Contact'),
89 'name' => 'sort_name',
90 'type' => CRM_Utils_Type
::T_STRING
,
93 'grouping' => 'contact-fields',
97 'dao' => 'CRM_Activity_DAO_Activity',
99 array('id' => array('title' => ts('Activity ID'),
100 'no_display' => TRUE,
103 'subject' => array('title' => ts('Touched Activity'),
106 'activity_type_id' => array('title' => ts('Activity Type'),
109 'source_contact_id' => array(
110 'no_display' => TRUE,
117 'dao' => 'CRM_Core_DAO_Log',
121 array('title' => ts('Modified Date'),
125 array('title' => ts('Description'),
131 array('title' => ts('Modified Date'),
132 'operatorType' => CRM_Report_Form
::OP_DATE
,
133 'type' => CRM_Utils_Type
::T_DATE
,
134 'default' => 'this.week',
140 parent
::__construct();
143 function preProcess() {
144 parent
::preProcess();
149 $this->_columnHeaders
= array();
150 foreach ($this->_columns
as $tableName => $table) {
151 if (array_key_exists('fields', $table)) {
152 foreach ($table['fields'] as $fieldName => $field) {
153 if (CRM_Utils_Array
::value('required', $field) ||
154 CRM_Utils_Array
::value($fieldName, $this->_params
['fields'])
157 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
158 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
159 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = $field['title'];
165 $this->_select
= "SELECT " . implode(', ', $select) . " ";
168 static function formRule($fields, $files, $self) {
169 $errors = $grouping = array();
175 FROM civicrm_log {$this->_aliases['civicrm_log']}
176 inner join civicrm_contact {$this->_aliases['civicrm_contact']} on {$this->_aliases['civicrm_log']}.modified_id = {$this->_aliases['civicrm_contact']}.id
177 left join civicrm_contact {$this->_aliases['civicrm_contact_touched']} on ({$this->_aliases['civicrm_log']}.entity_table='civicrm_contact' AND {$this->_aliases['civicrm_log']}.entity_id = {$this->_aliases['civicrm_contact_touched']}.id)
178 left join civicrm_activity {$this->_aliases['civicrm_activity']} on ({$this->_aliases['civicrm_log']}.entity_table='civicrm_activity' AND {$this->_aliases['civicrm_log']}.entity_id = {$this->_aliases['civicrm_activity']}.id)
185 foreach ($this->_columns
as $tableName => $table) {
186 if (array_key_exists('filters', $table)) {
187 foreach ($table['filters'] as $fieldName => $field) {
189 if (CRM_Utils_Array
::value('operatorType', $field) & CRM_Report_Form
::OP_DATE
) {
190 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
191 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
192 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
194 $clause = $this->dateClause($field['dbAlias'], $relative, $from, $to);
197 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
199 $clause = $this->whereClause($field,
201 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
202 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
203 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
208 if (!empty($clause)) {
209 $clauses[] = $clause;
215 $clauses[] = "({$this->_aliases['civicrm_log']}.entity_table <> 'civicrm_domain')";
216 $this->_where
= "WHERE " . implode(' AND ', $clauses);
221 ORDER BY {$this->_aliases['civicrm_log']}.modified_date DESC, {$this->_aliases['civicrm_contact']}.sort_name, {$this->_aliases['civicrm_contact_touched']}.sort_name
225 function alterDisplay(&$rows) {
226 // custom code to alter rows
228 foreach ($rows as $rowNum => $row) {
229 // convert display name to links
230 if (array_key_exists('civicrm_contact_sort_name', $row) &&
231 array_key_exists('civicrm_contact_id', $row)
233 $url = CRM_Utils_System
::url('civicrm/contact/view',
234 'reset=1&cid=' . $row['civicrm_contact_id'],
237 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
238 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact details for this contact.");
242 if (array_key_exists('civicrm_contact_touched_sort_name_touched', $row) &&
243 array_key_exists('civicrm_contact_touched_id', $row) &&
244 $row['civicrm_contact_touched_sort_name_touched'] !== ''
246 $url = CRM_Utils_System
::url('civicrm/contact/view',
247 'reset=1&cid=' . $row['civicrm_contact_touched_id'],
250 $rows[$rowNum]['civicrm_contact_touched_sort_name_touched_link'] = $url;
251 $rows[$rowNum]['civicrm_contact_touched_sort_name_touched_hover'] = ts("View Contact details for this contact.");
255 if (array_key_exists('civicrm_activity_subject', $row) &&
256 array_key_exists('civicrm_activity_id', $row) &&
257 $row['civicrm_activity_subject'] !== ''
259 $url = CRM_Utils_System
::url('civicrm/contact/view/activity',
260 'reset=1&action=view&id=' . $row['civicrm_activity_id'] . '&cid=' . $row['civicrm_activity_source_contact_id'] . '&atype=' . $row['civicrm_activity_activity_type_id'],
263 $rows[$rowNum]['civicrm_activity_subject_link'] = $url;
264 $rows[$rowNum]['civicrm_activity_subject_hover'] = ts("View Contact details for this contact.");
268 if (array_key_exists('civicrm_activity_activity_type_id', $row)) {
269 if ($value = $row['civicrm_activity_activity_type_id']) {
270 $rows[$rowNum]['civicrm_activity_activity_type_id'] = $this->activityTypes
[$value];
275 // skip looking further in rows, if first row itself doesn't
276 // have the column we need