5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
33 * @copyright CiviCRM LLC (c) 2004-2013
37 class CRM_Report_Form_Contact_Log
extends CRM_Report_Form
{
39 protected $_summary = NULL;
40 function __construct() {
42 $this->activityTypes
= CRM_Core_PseudoConstant
::activityType(TRUE, TRUE);
43 asort($this->activityTypes
);
45 $this->_columns
= array(
48 'dao' => 'CRM_Contact_DAO_Contact',
52 array('title' => ts('Modified By'),
64 array('title' => ts('Modified By'),
65 'type' => CRM_Utils_Type
::T_STRING
,
68 'grouping' => 'contact-fields',
70 'civicrm_contact_touched' =>
72 'dao' => 'CRM_Contact_DAO_Contact',
75 'sort_name_touched' =>
76 array('title' => ts('Touched Contact'),
77 'name' => 'sort_name',
88 'sort_name_touched' =>
89 array('title' => ts('Touched Contact'),
90 'name' => 'sort_name',
91 'type' => CRM_Utils_Type
::T_STRING
,
94 'grouping' => 'contact-fields',
98 'dao' => 'CRM_Activity_DAO_Activity',
100 array('id' => array('title' => ts('Activity ID'),
101 'no_display' => TRUE,
104 'subject' => array('title' => ts('Touched Activity'),
107 'activity_type_id' => array('title' => ts('Activity Type'),
110 'source_contact_id' => array(
111 'no_display' => TRUE,
118 'dao' => 'CRM_Core_DAO_Log',
122 array('title' => ts('Modified Date'),
126 array('title' => ts('Description'),
132 array('title' => ts('Modified Date'),
133 'operatorType' => CRM_Report_Form
::OP_DATE
,
134 'type' => CRM_Utils_Type
::T_DATE
,
135 'default' => 'this.week',
141 parent
::__construct();
144 function preProcess() {
145 parent
::preProcess();
150 $this->_columnHeaders
= array();
151 foreach ($this->_columns
as $tableName => $table) {
152 if (array_key_exists('fields', $table)) {
153 foreach ($table['fields'] as $fieldName => $field) {
154 if (CRM_Utils_Array
::value('required', $field) ||
155 CRM_Utils_Array
::value($fieldName, $this->_params
['fields'])
158 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
159 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
160 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = $field['title'];
166 $this->_select
= "SELECT " . implode(', ', $select) . " ";
169 static function formRule($fields, $files, $self) {
170 $errors = $grouping = array();
176 FROM civicrm_log {$this->_aliases['civicrm_log']}
177 inner join civicrm_contact {$this->_aliases['civicrm_contact']} on {$this->_aliases['civicrm_log']}.modified_id = {$this->_aliases['civicrm_contact']}.id
178 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)
179 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)
186 foreach ($this->_columns
as $tableName => $table) {
187 if (array_key_exists('filters', $table)) {
188 foreach ($table['filters'] as $fieldName => $field) {
190 if (CRM_Utils_Array
::value('operatorType', $field) & CRM_Report_Form
::OP_DATE
) {
191 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
192 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
193 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
195 $clause = $this->dateClause($field['dbAlias'], $relative, $from, $to);
198 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
200 $clause = $this->whereClause($field,
202 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
203 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
204 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
209 if (!empty($clause)) {
210 $clauses[] = $clause;
216 $clauses[] = "({$this->_aliases['civicrm_log']}.entity_table <> 'civicrm_domain')";
217 $this->_where
= "WHERE " . implode(' AND ', $clauses);
222 ORDER BY {$this->_aliases['civicrm_log']}.modified_date DESC, {$this->_aliases['civicrm_contact']}.sort_name, {$this->_aliases['civicrm_contact_touched']}.sort_name
226 function alterDisplay(&$rows) {
227 // custom code to alter rows
229 foreach ($rows as $rowNum => $row) {
230 // convert display name to links
231 if (array_key_exists('civicrm_contact_sort_name', $row) &&
232 array_key_exists('civicrm_contact_id', $row)
234 $url = CRM_Utils_System
::url('civicrm/contact/view',
235 'reset=1&cid=' . $row['civicrm_contact_id'],
238 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
239 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact details for this contact.");
243 if (array_key_exists('civicrm_contact_touched_sort_name_touched', $row) &&
244 array_key_exists('civicrm_contact_touched_id', $row) &&
245 $row['civicrm_contact_touched_sort_name_touched'] !== ''
247 $url = CRM_Utils_System
::url('civicrm/contact/view',
248 'reset=1&cid=' . $row['civicrm_contact_touched_id'],
251 $rows[$rowNum]['civicrm_contact_touched_sort_name_touched_link'] = $url;
252 $rows[$rowNum]['civicrm_contact_touched_sort_name_touched_hover'] = ts("View Contact details for this contact.");
256 if (array_key_exists('civicrm_activity_subject', $row) &&
257 array_key_exists('civicrm_activity_id', $row) &&
258 $row['civicrm_activity_subject'] !== ''
260 $url = CRM_Utils_System
::url('civicrm/contact/view/activity',
261 'reset=1&action=view&id=' . $row['civicrm_activity_id'] . '&cid=' . $row['civicrm_activity_source_contact_id'] . '&atype=' . $row['civicrm_activity_activity_type_id'],
264 $rows[$rowNum]['civicrm_activity_subject_link'] = $url;
265 $rows[$rowNum]['civicrm_activity_subject_hover'] = ts("View Contact details for this contact.");
269 if (array_key_exists('civicrm_activity_activity_type_id', $row)) {
270 if ($value = $row['civicrm_activity_activity_type_id']) {
271 $rows[$rowNum]['civicrm_activity_activity_type_id'] = $this->activityTypes
[$value];
276 // skip looking further in rows, if first row itself doesn't
277 // have the column we need