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_Log
extends CRM_Report_Form
{
38 protected $_summary = NULL;
46 function __construct() {
48 $this->activityTypes
= CRM_Core_PseudoConstant
::activityType(TRUE, TRUE);
49 asort($this->activityTypes
);
51 $this->_columns
= array(
54 'dao' => 'CRM_Contact_DAO_Contact',
58 array('title' => ts('Modified By'),
70 array('title' => ts('Modified By'),
71 'type' => CRM_Utils_Type
::T_STRING
,
74 'grouping' => 'contact-fields',
76 'civicrm_contact_touched' =>
78 'dao' => 'CRM_Contact_DAO_Contact',
81 'sort_name_touched' =>
82 array('title' => ts('Touched Contact'),
83 'name' => 'sort_name',
94 'sort_name_touched' =>
95 array('title' => ts('Touched Contact'),
96 'name' => 'sort_name',
97 'type' => CRM_Utils_Type
::T_STRING
,
100 'grouping' => 'contact-fields',
102 'civicrm_activity' =>
104 'dao' => 'CRM_Activity_DAO_Activity',
106 array('id' => array('title' => ts('Activity ID'),
107 'no_display' => TRUE,
110 'subject' => array('title' => ts('Touched Activity'),
113 'activity_type_id' => array('title' => ts('Activity Type'),
118 'civicrm_activity_source' =>
120 'dao' => 'CRM_Activity_DAO_ActivityContact',
125 'no_display' => TRUE,
132 'dao' => 'CRM_Core_DAO_Log',
136 array('title' => ts('Modified Date'),
140 array('title' => ts('Description'),
146 array('title' => ts('Modified Date'),
147 'operatorType' => CRM_Report_Form
::OP_DATE
,
148 'type' => CRM_Utils_Type
::T_DATE
,
149 'default' => 'this.week',
155 parent
::__construct();
158 function preProcess() {
159 parent
::preProcess();
164 $this->_columnHeaders
= array();
165 foreach ($this->_columns
as $tableName => $table) {
166 if (array_key_exists('fields', $table)) {
167 foreach ($table['fields'] as $fieldName => $field) {
168 if (!empty($field['required']) ||
!empty($this->_params
['fields'][$fieldName])) {
170 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
171 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
172 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = $field['title'];
178 $this->_select
= "SELECT " . implode(', ', $select) . " ";
188 static function formRule($fields, $files, $self) {
189 $errors = $grouping = array();
194 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
195 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
197 FROM civicrm_log {$this->_aliases['civicrm_log']}
198 inner join civicrm_contact {$this->_aliases['civicrm_contact']} on {$this->_aliases['civicrm_log']}.modified_id = {$this->_aliases['civicrm_contact']}.id
199 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)
200 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)
201 LEFT JOIN civicrm_activity_contact {$this->_aliases['civicrm_activity_source']} ON
202 {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_source']}.activity_id AND
203 {$this->_aliases['civicrm_activity_source']}.record_type_id = {$sourceID}
210 foreach ($this->_columns
as $tableName => $table) {
211 if (array_key_exists('filters', $table)) {
212 foreach ($table['filters'] as $fieldName => $field) {
214 if (CRM_Utils_Array
::value('operatorType', $field) & CRM_Report_Form
::OP_DATE
) {
215 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
216 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
217 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
219 $clause = $this->dateClause($field['dbAlias'], $relative, $from, $to);
222 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
224 $clause = $this->whereClause($field,
226 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
227 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
228 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
233 if (!empty($clause)) {
234 $clauses[] = $clause;
240 $clauses[] = "({$this->_aliases['civicrm_log']}.entity_table <> 'civicrm_domain')";
241 $this->_where
= "WHERE " . implode(' AND ', $clauses);
246 ORDER BY {$this->_aliases['civicrm_log']}.modified_date DESC, {$this->_aliases['civicrm_contact']}.sort_name, {$this->_aliases['civicrm_contact_touched']}.sort_name
253 function alterDisplay(&$rows) {
254 // custom code to alter rows
256 foreach ($rows as $rowNum => $row) {
257 // convert display name to links
258 if (array_key_exists('civicrm_contact_sort_name', $row) &&
259 array_key_exists('civicrm_contact_id', $row)
261 $url = CRM_Utils_System
::url('civicrm/contact/view',
262 'reset=1&cid=' . $row['civicrm_contact_id'],
265 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
266 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact details for this contact.");
270 if (array_key_exists('civicrm_contact_touched_sort_name_touched', $row) &&
271 array_key_exists('civicrm_contact_touched_id', $row) &&
272 $row['civicrm_contact_touched_sort_name_touched'] !== ''
274 $url = CRM_Utils_System
::url('civicrm/contact/view',
275 'reset=1&cid=' . $row['civicrm_contact_touched_id'],
278 $rows[$rowNum]['civicrm_contact_touched_sort_name_touched_link'] = $url;
279 $rows[$rowNum]['civicrm_contact_touched_sort_name_touched_hover'] = ts("View Contact details for this contact.");
283 if (array_key_exists('civicrm_activity_subject', $row) &&
284 array_key_exists('civicrm_activity_id', $row) &&
285 $row['civicrm_activity_subject'] !== ''
287 $url = CRM_Utils_System
::url('civicrm/contact/view/activity',
288 'reset=1&action=view&id=' . $row['civicrm_activity_id'] . '&cid=' . $row['civicrm_activity_source_contact_id'] . '&atype=' . $row['civicrm_activity_activity_type_id'],
291 $rows[$rowNum]['civicrm_activity_subject_link'] = $url;
292 $rows[$rowNum]['civicrm_activity_subject_hover'] = ts("View Contact details for this contact.");
296 if (array_key_exists('civicrm_activity_activity_type_id', $row)) {
297 if ($value = $row['civicrm_activity_activity_type_id']) {
298 $rows[$rowNum]['civicrm_activity_activity_type_id'] = $this->activityTypes
[$value];
303 // skip looking further in rows, if first row itself doesn't
304 // have the column we need