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_Log
extends CRM_Report_Form
{
35 protected $_summary = NULL;
40 public function __construct() {
42 $this->activityTypes
= CRM_Core_PseudoConstant
::activityType(TRUE, TRUE);
43 asort($this->activityTypes
);
45 $this->_columns
= array(
46 'civicrm_contact' => array(
47 'dao' => 'CRM_Contact_DAO_Contact',
50 'title' => ts('Modified By'),
60 'title' => ts('Modified By'),
61 'type' => CRM_Utils_Type
::T_STRING
,
64 'grouping' => 'contact-fields',
66 'civicrm_contact_touched' => array(
67 'dao' => 'CRM_Contact_DAO_Contact',
69 'sort_name_touched' => array(
70 'title' => ts('Touched Contact'),
71 'name' => 'sort_name',
80 'sort_name_touched' => array(
81 'title' => ts('Touched Contact'),
82 'name' => 'sort_name',
83 'type' => CRM_Utils_Type
::T_STRING
,
86 'grouping' => 'contact-fields',
88 'civicrm_activity' => array(
89 'dao' => 'CRM_Activity_DAO_Activity',
92 'title' => ts('Activity ID'),
97 'title' => ts('Touched Activity'),
100 'activity_type_id' => array(
101 'title' => ts('Activity Type'),
106 'civicrm_activity_source' => array(
107 'dao' => 'CRM_Activity_DAO_ActivityContact',
109 'contact_id' => array(
110 'no_display' => TRUE,
115 'civicrm_log' => array(
116 'dao' => 'CRM_Core_DAO_Log',
118 'modified_date' => array(
119 'title' => ts('Modified Date'),
123 'title' => ts('Description'),
127 'modified_date' => array(
128 'title' => ts('Modified Date'),
129 'operatorType' => CRM_Report_Form
::OP_DATE
,
130 'type' => CRM_Utils_Type
::T_DATE
,
131 'default' => 'this.week',
137 parent
::__construct();
140 public function preProcess() {
141 parent
::preProcess();
144 public function select() {
146 $this->_columnHeaders
= array();
147 foreach ($this->_columns
as $tableName => $table) {
148 if (array_key_exists('fields', $table)) {
149 foreach ($table['fields'] as $fieldName => $field) {
150 if (!empty($field['required']) ||
151 !empty($this->_params
['fields'][$fieldName])
154 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
155 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
156 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = $field['title'];
162 $this->_select
= "SELECT " . implode(', ', $select) . " ";
172 public static function formRule($fields, $files, $self) {
173 $errors = $grouping = array();
177 public function from() {
178 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
179 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
181 FROM civicrm_log {$this->_aliases['civicrm_log']}
182 inner join civicrm_contact {$this->_aliases['civicrm_contact']} on {$this->_aliases['civicrm_log']}.modified_id = {$this->_aliases['civicrm_contact']}.id
183 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)
184 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 LEFT JOIN civicrm_activity_contact {$this->_aliases['civicrm_activity_source']} ON
186 {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_source']}.activity_id AND
187 {$this->_aliases['civicrm_activity_source']}.record_type_id = {$sourceID}
191 public function where() {
194 foreach ($this->_columns
as $tableName => $table) {
195 if (array_key_exists('filters', $table)) {
196 foreach ($table['filters'] as $fieldName => $field) {
198 if (CRM_Utils_Array
::value('operatorType', $field) & CRM_Report_Form
::OP_DATE
200 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
201 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
202 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
204 $clause = $this->dateClause($field['dbAlias'], $relative, $from, $to);
207 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
209 $clause = $this->whereClause($field,
211 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
212 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
213 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
218 if (!empty($clause)) {
219 $clauses[] = $clause;
225 $clauses[] = "({$this->_aliases['civicrm_log']}.entity_table <> 'civicrm_domain')";
226 $this->_where
= "WHERE " . implode(' AND ', $clauses);
229 public function orderBy() {
231 ORDER BY {$this->_aliases['civicrm_log']}.modified_date DESC, {$this->_aliases['civicrm_contact']}.sort_name, {$this->_aliases['civicrm_contact_touched']}.sort_name
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 // convert display name to links
249 if (array_key_exists('civicrm_contact_sort_name', $row) &&
250 array_key_exists('civicrm_contact_id', $row)
252 $url = CRM_Utils_System
::url('civicrm/contact/view',
253 'reset=1&cid=' . $row['civicrm_contact_id'],
256 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
257 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact details for this contact.");
261 if (array_key_exists('civicrm_contact_touched_sort_name_touched', $row) &&
262 array_key_exists('civicrm_contact_touched_id', $row) &&
263 $row['civicrm_contact_touched_sort_name_touched'] !== ''
265 $url = CRM_Utils_System
::url('civicrm/contact/view',
266 'reset=1&cid=' . $row['civicrm_contact_touched_id'],
269 $rows[$rowNum]['civicrm_contact_touched_sort_name_touched_link'] = $url;
270 $rows[$rowNum]['civicrm_contact_touched_sort_name_touched_hover'] = ts("View Contact details for this contact.");
274 if (array_key_exists('civicrm_activity_subject', $row) &&
275 array_key_exists('civicrm_activity_id', $row) &&
276 $row['civicrm_activity_subject'] !== ''
278 $url = CRM_Utils_System
::url('civicrm/contact/view/activity',
279 'reset=1&action=view&id=' . $row['civicrm_activity_id'] . '&cid=' .
280 $row['civicrm_activity_source_contact_id'] . '&atype=' .
281 $row['civicrm_activity_activity_type_id'],
284 $rows[$rowNum]['civicrm_activity_subject_link'] = $url;
285 $rows[$rowNum]['civicrm_activity_subject_hover'] = ts("View Contact details for this contact.");
289 if (array_key_exists('civicrm_activity_activity_type_id', $row)) {
290 if ($value = $row['civicrm_activity_activity_type_id']) {
291 $rows[$rowNum]['civicrm_activity_activity_type_id'] = $this->activityTypes
[$value];
296 // skip looking further in rows, if first row itself doesn't
297 // have the column we need