3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Report_Form_Contact_Log
extends CRM_Report_Form
{
19 protected $_summary = NULL;
24 public function __construct() {
26 $this->activityTypes
= CRM_Core_PseudoConstant
::activityType(TRUE, TRUE);
27 asort($this->activityTypes
);
30 'civicrm_contact' => [
31 'dao' => 'CRM_Contact_DAO_Contact',
34 'title' => ts('Modified By'),
44 'title' => ts('Modified By'),
45 'type' => CRM_Utils_Type
::T_STRING
,
48 'grouping' => 'contact-fields',
50 'civicrm_contact_touched' => [
51 'dao' => 'CRM_Contact_DAO_Contact',
53 'sort_name_touched' => [
54 'title' => ts('Touched Contact'),
55 'name' => 'sort_name',
64 'sort_name_touched' => [
65 'title' => ts('Touched Contact'),
66 'name' => 'sort_name',
67 'type' => CRM_Utils_Type
::T_STRING
,
70 'grouping' => 'contact-fields',
72 'civicrm_activity' => [
73 'dao' => 'CRM_Activity_DAO_Activity',
76 'title' => ts('Activity ID'),
81 'title' => ts('Touched Activity'),
84 'activity_type_id' => [
85 'title' => ts('Activity Type'),
90 'civicrm_activity_source' => [
91 'dao' => 'CRM_Activity_DAO_ActivityContact',
100 'dao' => 'CRM_Core_DAO_Log',
103 'title' => ts('Modified Date'),
107 'title' => ts('Description'),
112 'title' => ts('Modified Date'),
113 'operatorType' => CRM_Report_Form
::OP_DATE
,
114 'type' => CRM_Utils_Type
::T_DATE
,
115 'default' => 'this.week',
121 parent
::__construct();
124 public function preProcess() {
125 parent
::preProcess();
128 public function select() {
130 $this->_columnHeaders
= [];
131 foreach ($this->_columns
as $tableName => $table) {
132 if (array_key_exists('fields', $table)) {
133 foreach ($table['fields'] as $fieldName => $field) {
134 if (!empty($field['required']) ||
135 !empty($this->_params
['fields'][$fieldName])
138 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
139 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = $field['type'] ??
NULL;
140 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = $field['title'];
146 $this->_select
= "SELECT " . implode(', ', $select) . " ";
156 public static function formRule($fields, $files, $self) {
157 $errors = $grouping = [];
161 public function from() {
162 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
163 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
165 FROM civicrm_log {$this->_aliases['civicrm_log']}
166 inner join civicrm_contact {$this->_aliases['civicrm_contact']} on {$this->_aliases['civicrm_log']}.modified_id = {$this->_aliases['civicrm_contact']}.id
167 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)
168 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)
169 LEFT JOIN civicrm_activity_contact {$this->_aliases['civicrm_activity_source']} ON
170 {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_source']}.activity_id AND
171 {$this->_aliases['civicrm_activity_source']}.record_type_id = {$sourceID}
175 public function where() {
178 foreach ($this->_columns
as $tableName => $table) {
179 if (array_key_exists('filters', $table)) {
180 foreach ($table['filters'] as $fieldName => $field) {
182 if (CRM_Utils_Array
::value('operatorType', $field) & CRM_Report_Form
::OP_DATE
184 $relative = $this->_params
["{$fieldName}_relative"] ??
NULL;
185 $from = $this->_params
["{$fieldName}_from"] ??
NULL;
186 $to = $this->_params
["{$fieldName}_to"] ??
NULL;
188 $clause = $this->dateClause($field['dbAlias'], $relative, $from, $to);
191 $op = $this->_params
["{$fieldName}_op"] ??
NULL;
193 $clause = $this->whereClause($field,
195 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
196 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
197 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
202 if (!empty($clause)) {
203 $clauses[] = $clause;
209 $clauses[] = "({$this->_aliases['civicrm_log']}.entity_table <> 'civicrm_domain')";
210 $this->_where
= "WHERE " . implode(' AND ', $clauses);
213 public function orderBy() {
215 ORDER BY {$this->_aliases['civicrm_log']}.modified_date DESC, {$this->_aliases['civicrm_contact']}.sort_name, {$this->_aliases['civicrm_contact_touched']}.sort_name
220 * Alter display of rows.
222 * Iterate through the rows retrieved via SQL and make changes for display purposes,
223 * such as rendering contacts as links.
226 * Rows generated by SQL, with an array for each row.
228 public function alterDisplay(&$rows) {
231 foreach ($rows as $rowNum => $row) {
232 // convert display name to links
233 if (array_key_exists('civicrm_contact_sort_name', $row) &&
234 array_key_exists('civicrm_contact_id', $row)
236 $url = CRM_Utils_System
::url('civicrm/contact/view',
237 'reset=1&cid=' . $row['civicrm_contact_id'],
240 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
241 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact details for this contact.");
245 if (array_key_exists('civicrm_contact_touched_sort_name_touched', $row) &&
246 array_key_exists('civicrm_contact_touched_id', $row) &&
247 $row['civicrm_contact_touched_sort_name_touched'] !== ''
249 $url = CRM_Utils_System
::url('civicrm/contact/view',
250 'reset=1&cid=' . $row['civicrm_contact_touched_id'],
253 $rows[$rowNum]['civicrm_contact_touched_sort_name_touched_link'] = $url;
254 $rows[$rowNum]['civicrm_contact_touched_sort_name_touched_hover'] = ts("View Contact details for this contact.");
258 if (array_key_exists('civicrm_activity_subject', $row) &&
259 array_key_exists('civicrm_activity_id', $row) &&
260 $row['civicrm_activity_subject'] !== ''
262 $url = CRM_Utils_System
::url('civicrm/contact/view/activity',
263 'reset=1&action=view&id=' . $row['civicrm_activity_id'] . '&cid=' .
264 $row['civicrm_activity_source_contact_id'] . '&atype=' .
265 $row['civicrm_activity_activity_type_id'],
268 $rows[$rowNum]['civicrm_activity_subject_link'] = $url;
269 $rows[$rowNum]['civicrm_activity_subject_hover'] = ts("View Contact details for this contact.");
273 if (array_key_exists('civicrm_activity_activity_type_id', $row)) {
274 if ($value = $row['civicrm_activity_activity_type_id']) {
275 $rows[$rowNum]['civicrm_activity_activity_type_id'] = $this->activityTypes
[$value];
280 // skip looking further in rows, if first row itself doesn't
281 // have the column we need