3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
35 class CRM_Report_Form_Contact_Log
extends CRM_Report_Form
{
37 protected $_summary = NULL;
43 public function __construct() {
45 $this->activityTypes
= CRM_Core_PseudoConstant
::activityType(TRUE, TRUE);
46 asort($this->activityTypes
);
48 $this->_columns
= array(
49 'civicrm_contact' => array(
50 'dao' => 'CRM_Contact_DAO_Contact',
53 'title' => ts('Modified By'),
63 'title' => ts('Modified By'),
64 'type' => CRM_Utils_Type
::T_STRING
,
67 'grouping' => 'contact-fields',
69 'civicrm_contact_touched' => array(
70 'dao' => 'CRM_Contact_DAO_Contact',
72 'sort_name_touched' => array(
73 'title' => ts('Touched Contact'),
74 'name' => 'sort_name',
83 'sort_name_touched' => array(
84 'title' => ts('Touched Contact'),
85 'name' => 'sort_name',
86 'type' => CRM_Utils_Type
::T_STRING
,
89 'grouping' => 'contact-fields',
91 'civicrm_activity' => array(
92 'dao' => 'CRM_Activity_DAO_Activity',
95 'title' => ts('Activity ID'),
100 'title' => ts('Touched Activity'),
103 'activity_type_id' => array(
104 'title' => ts('Activity Type'),
109 'civicrm_activity_source' => array(
110 'dao' => 'CRM_Activity_DAO_ActivityContact',
112 'contact_id' => array(
113 'no_display' => TRUE,
118 'civicrm_log' => array(
119 'dao' => 'CRM_Core_DAO_Log',
121 'modified_date' => array(
122 'title' => ts('Modified Date'),
126 'title' => ts('Description'),
130 'modified_date' => array(
131 '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 public function preProcess() {
144 parent
::preProcess();
147 public function select() {
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 (!empty($field['required']) ||
154 !empty($this->_params
['fields'][$fieldName])
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) . " ";
175 public static function formRule($fields, $files, $self) {
176 $errors = $grouping = array();
180 public function from() {
181 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
182 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
184 FROM civicrm_log {$this->_aliases['civicrm_log']}
185 inner join civicrm_contact {$this->_aliases['civicrm_contact']} on {$this->_aliases['civicrm_log']}.modified_id = {$this->_aliases['civicrm_contact']}.id
186 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)
187 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)
188 LEFT JOIN civicrm_activity_contact {$this->_aliases['civicrm_activity_source']} ON
189 {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_source']}.activity_id AND
190 {$this->_aliases['civicrm_activity_source']}.record_type_id = {$sourceID}
194 public function where() {
197 foreach ($this->_columns
as $tableName => $table) {
198 if (array_key_exists('filters', $table)) {
199 foreach ($table['filters'] as $fieldName => $field) {
201 if (CRM_Utils_Array
::value('operatorType', $field) & CRM_Report_Form
::OP_DATE
203 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
204 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
205 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
207 $clause = $this->dateClause($field['dbAlias'], $relative, $from, $to);
210 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
212 $clause = $this->whereClause($field,
214 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
215 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
216 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
221 if (!empty($clause)) {
222 $clauses[] = $clause;
228 $clauses[] = "({$this->_aliases['civicrm_log']}.entity_table <> 'civicrm_domain')";
229 $this->_where
= "WHERE " . implode(' AND ', $clauses);
232 public function orderBy() {
234 ORDER BY {$this->_aliases['civicrm_log']}.modified_date DESC, {$this->_aliases['civicrm_contact']}.sort_name, {$this->_aliases['civicrm_contact_touched']}.sort_name
239 * Alter display of rows.
241 * Iterate through the rows retrieved via SQL and make changes for display purposes,
242 * such as rendering contacts as links.
245 * Rows generated by SQL, with an array for each row.
247 public function alterDisplay(&$rows) {
250 foreach ($rows as $rowNum => $row) {
251 // convert display name to links
252 if (array_key_exists('civicrm_contact_sort_name', $row) &&
253 array_key_exists('civicrm_contact_id', $row)
255 $url = CRM_Utils_System
::url('civicrm/contact/view',
256 'reset=1&cid=' . $row['civicrm_contact_id'],
259 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
260 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact details for this contact.");
264 if (array_key_exists('civicrm_contact_touched_sort_name_touched', $row) &&
265 array_key_exists('civicrm_contact_touched_id', $row) &&
266 $row['civicrm_contact_touched_sort_name_touched'] !== ''
268 $url = CRM_Utils_System
::url('civicrm/contact/view',
269 'reset=1&cid=' . $row['civicrm_contact_touched_id'],
272 $rows[$rowNum]['civicrm_contact_touched_sort_name_touched_link'] = $url;
273 $rows[$rowNum]['civicrm_contact_touched_sort_name_touched_hover'] = ts("View Contact details for this contact.");
277 if (array_key_exists('civicrm_activity_subject', $row) &&
278 array_key_exists('civicrm_activity_id', $row) &&
279 $row['civicrm_activity_subject'] !== ''
281 $url = CRM_Utils_System
::url('civicrm/contact/view/activity',
282 'reset=1&action=view&id=' . $row['civicrm_activity_id'] . '&cid=' .
283 $row['civicrm_activity_source_contact_id'] . '&atype=' .
284 $row['civicrm_activity_activity_type_id'],
287 $rows[$rowNum]['civicrm_activity_subject_link'] = $url;
288 $rows[$rowNum]['civicrm_activity_subject_hover'] = ts("View Contact details for this contact.");
292 if (array_key_exists('civicrm_activity_activity_type_id', $row)) {
293 if ($value = $row['civicrm_activity_activity_type_id']) {
294 $rows[$rowNum]['civicrm_activity_activity_type_id'] = $this->activityTypes
[$value];
299 // skip looking further in rows, if first row itself doesn't
300 // have the column we need