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
33 class CRM_Report_Form_Contact_LoggingSummary
extends CRM_Logging_ReportSummary
{
37 public function __construct() {
38 parent
::__construct();
41 foreach (array_keys($this->_logTables
) as $table) {
42 $type = $this->getLogType($table);
43 $logTypes[$type] = $type;
47 $this->_columns
= array(
48 'log_civicrm_entity' => array(
49 'dao' => 'CRM_Contact_DAO_Contact',
50 'alias' => 'entity_log',
56 'log_action' => array(
58 'title' => ts('Action'),
62 'title' => ts('Log Type'),
64 'log_user_id' => array(
71 'type' => CRM_Utils_Type
::T_TIME
,
72 'title' => ts('When'),
74 'altered_contact' => array(
76 'name' => 'display_name',
77 'title' => ts('Altered Contact'),
78 'alias' => 'modified_contact_civireport',
80 'altered_contact_id' => array(
84 'alias' => 'modified_contact_civireport',
86 'log_conn_id' => array(
90 'is_deleted' => array(
93 'alias' => 'modified_contact_civireport',
98 'title' => ts('When'),
99 'operatorType' => CRM_Report_Form
::OP_DATE
,
100 'type' => CRM_Utils_Type
::T_DATE
,
102 'altered_contact' => array(
103 'name' => 'display_name',
104 'title' => ts('Altered Contact'),
105 'type' => CRM_Utils_Type
::T_STRING
,
106 'alias' => 'modified_contact_civireport',
108 'altered_contact_id' => array(
110 'type' => CRM_Utils_Type
::T_INT
,
111 'alias' => 'modified_contact_civireport',
112 'no_display' => TRUE,
115 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
116 'options' => $logTypes,
117 'title' => ts('Log Type'),
118 'type' => CRM_Utils_Type
::T_STRING
,
120 'log_type_table' => array(
121 'name' => 'log_type',
122 'title' => ts('Log Type Table'),
123 'type' => CRM_Utils_Type
::T_STRING
,
125 'log_action' => array(
126 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
128 'Insert' => ts('Insert'),
129 'Update' => ts('Update'),
130 'Delete' => ts('Delete'),
132 'title' => ts('Action'),
133 'type' => CRM_Utils_Type
::T_STRING
,
136 'no_display' => TRUE,
137 'type' => CRM_Utils_Type
::T_INT
,
141 'altered_by_contact' => array(
142 'dao' => 'CRM_Contact_DAO_Contact',
143 'alias' => 'altered_by_contact',
145 'display_name' => array(
147 'name' => 'display_name',
148 'title' => ts('Altered By'),
152 'display_name' => array(
153 'name' => 'display_name',
154 'title' => ts('Altered By'),
155 'type' => CRM_Utils_Type
::T_STRING
,
163 * Alter display of rows.
165 * Iterate through the rows retrieved via SQL and make changes for display purposes,
166 * such as rendering contacts as links.
169 * Rows generated by SQL, with an array for each row.
171 public function alterDisplay(&$rows) {
172 // cache for id → is_deleted mapping
173 $isDeleted = array();
176 foreach ($rows as $key => &$row) {
177 if (!isset($isDeleted[$row['log_civicrm_entity_altered_contact_id']])) {
178 $isDeleted[$row['log_civicrm_entity_altered_contact_id']] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
179 $row['log_civicrm_entity_altered_contact_id'], 'is_deleted') !== '0';
182 if (!empty($row['log_civicrm_entity_altered_contact']) &&
183 !$isDeleted[$row['log_civicrm_entity_altered_contact_id']]
185 $row['log_civicrm_entity_altered_contact_link'] = CRM_Utils_System
::url('civicrm/contact/view',
186 'reset=1&cid=' . $row['log_civicrm_entity_altered_contact_id']);
187 $row['log_civicrm_entity_altered_contact_hover'] = ts("Go to contact summary");
188 $entity = $this->getEntityValue($row['log_civicrm_entity_id'], $row['log_civicrm_entity_log_type'], $row['log_civicrm_entity_log_date']);
190 $row['log_civicrm_entity_altered_contact'] = $row['log_civicrm_entity_altered_contact'] . " [{$entity}]";
193 $row['altered_by_contact_display_name_link'] = CRM_Utils_System
::url('civicrm/contact/view', 'reset=1&cid=' . $row['log_civicrm_entity_log_user_id']);
194 $row['altered_by_contact_display_name_hover'] = ts("Go to contact summary");
196 if ($row['log_civicrm_entity_is_deleted'] and 'Update' == CRM_Utils_Array
::value('log_civicrm_entity_log_action', $row)) {
197 $row['log_civicrm_entity_log_action'] = ts('Delete (to trash)');
200 if ('Contact' == CRM_Utils_Array
::value('log_type', $this->_logTables
[$row['log_civicrm_entity_log_type']]) &&
201 CRM_Utils_Array
::value('log_civicrm_entity_log_action', $row) == 'Insert'
203 $row['log_civicrm_entity_log_action'] = ts('Update');
206 if ($newAction = $this->getEntityAction($row['log_civicrm_entity_id'],
207 $row['log_civicrm_entity_log_conn_id'],
208 $row['log_civicrm_entity_log_type'],
209 CRM_Utils_Array
::value('log_civicrm_entity_log_action', $row))
211 $row['log_civicrm_entity_log_action'] = $newAction;
214 $row['log_civicrm_entity_log_type'] = $this->getLogType($row['log_civicrm_entity_log_type']);
216 $date = CRM_Utils_Date
::isoToMysql($row['log_civicrm_entity_log_date']);
218 if ('Update' == CRM_Utils_Array
::value('log_civicrm_entity_log_action', $row)) {
219 $q = "reset=1&log_conn_id={$row['log_civicrm_entity_log_conn_id']}&log_date=" . $date;
221 $q .= '&cid=' . $this->cid
;
223 $q .= (!empty($row['log_civicrm_entity_altered_contact'])) ?
'&alteredName=' . $row['log_civicrm_entity_altered_contact'] : '';
224 $q .= (!empty($row['altered_by_contact_display_name'])) ?
'&alteredBy=' . $row['altered_by_contact_display_name'] : '';
225 $q .= (!empty($row['log_civicrm_entity_log_user_id'])) ?
'&alteredById=' . $row['log_civicrm_entity_log_user_id'] : '';
227 $url1 = CRM_Report_Utils_Report
::getNextUrl('logging/contact/detail', "{$q}&snippet=4§ion=2&layout=overlay", FALSE, TRUE);
228 $url2 = CRM_Report_Utils_Report
::getNextUrl('logging/contact/detail', "{$q}§ion=2", FALSE, TRUE);
229 $hoverTitle = ts('View details for this update');
230 $row['log_civicrm_entity_log_action'] = "<a href='{$url1}' class='crm-summary-link'><i class=\"crm-i fa-list-alt\"></i></a> <a title='{$hoverTitle}' href='{$url2}'>" . ts('Update') . '</a>';
234 $row['log_civicrm_entity_log_type'] . '_' .
235 $row['log_civicrm_entity_log_conn_id'] . '_' .
236 $row['log_civicrm_entity_log_user_id'] . '_' .
237 $row['log_civicrm_entity_altered_contact_id'];
238 $newRows[$key] = $row;
240 unset($row['log_civicrm_entity_log_user_id']);
241 unset($row['log_civicrm_entity_log_conn_id']);
249 * Generate From Clause.
251 * @param string $logTable
253 public function from($logTable = NULL) {
254 static $entity = NULL;
259 $detail = $this->_logTables
[$entity];
260 $tableName = CRM_Utils_Array
::value('table_name', $detail, $entity);
261 $clause = CRM_Utils_Array
::value('entity_table', $detail);
262 $clause = $clause ?
"AND entity_log_civireport.entity_table = 'civicrm_contact'" : NULL;
265 INNER JOIN civicrm_contact modified_contact_civireport
266 ON (entity_log_civireport.{$detail['fk']} = modified_contact_civireport.id {$clause})";
268 if (!empty($detail['joins'])) {
269 $clause = CRM_Utils_Array
::value('entity_table', $detail);
270 $clause = $clause ?
"AND fk_table.entity_table = 'civicrm_contact'" : NULL;
272 INNER JOIN `{$this->loggingDB}`.{$detail['joins']['table']} fk_table ON {$detail['joins']['join']}
273 INNER JOIN civicrm_contact modified_contact_civireport
274 ON (fk_table.{$detail['fk']} = modified_contact_civireport.id {$clause})";
278 FROM `{$this->loggingDB}`.$tableName entity_log_civireport
280 LEFT JOIN civicrm_contact altered_by_contact_civireport
281 ON (entity_log_civireport.log_user_id = altered_by_contact_civireport.id)";