3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
35 class CRM_Report_Form_Contact_LoggingSummary
extends CRM_Logging_ReportSummary
{
39 function __construct() {
40 parent
::__construct();
43 foreach ( array_keys($this->_logTables
) as $table ) {
44 $type = $this->getLogType($table);
45 $logTypes[$type] = $type;
49 $this->_columns
= array(
50 'log_civicrm_entity' => array(
51 'dao' => 'CRM_Contact_DAO_Contact',
52 'alias' => 'entity_log',
58 'log_action' => array(
60 'title' => ts('Action'),
64 'title' => ts('Log Type'),
66 'log_user_id' => array(
73 'type' => CRM_Utils_Type
::T_TIME
,
74 'title' => ts('When'),
76 'altered_contact' => array(
78 'name' => 'display_name',
79 'title' => ts('Altered Contact'),
80 'alias' => 'modified_contact_civireport',
82 'altered_contact_id' => array(
86 'alias' => 'modified_contact_civireport',
88 'log_conn_id' => array(
92 'is_deleted' => array(
95 'alias' => 'modified_contact_civireport',
100 'title' => ts('When'),
101 'operatorType' => CRM_Report_Form
::OP_DATE
,
102 'type' => CRM_Utils_Type
::T_DATE
,
104 'altered_contact' => array(
105 'name' => 'display_name',
106 'title' => ts('Altered Contact'),
107 'type' => CRM_Utils_Type
::T_STRING
,
108 'alias' => 'modified_contact_civireport',
110 'altered_contact_id' => array(
112 'type' => CRM_Utils_Type
::T_INT
,
113 'alias' => 'modified_contact_civireport',
114 'no_display' => TRUE,
117 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
118 'options' => $logTypes,
119 'title' => ts('Log Type'),
120 'type' => CRM_Utils_Type
::T_STRING
,
122 'log_type_table' => array(
123 'name' => 'log_type',
124 'title' => ts('Log Type Table'),
125 'type' => CRM_Utils_Type
::T_STRING
,
127 'log_action' => array(
128 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
129 'options' => array('Insert' => ts('Insert'), 'Update' => ts('Update'), 'Delete' => ts('Delete')),
130 'title' => ts('Action'),
131 'type' => CRM_Utils_Type
::T_STRING
,
134 'no_display' => TRUE,
135 'type' => CRM_Utils_Type
::T_INT
,
139 'altered_by_contact' => array(
140 'dao' => 'CRM_Contact_DAO_Contact',
141 'alias' => 'altered_by_contact',
143 'display_name' => array(
145 'name' => 'display_name',
146 'title' => ts('Altered By'),
150 'display_name' => array(
151 'name' => 'display_name',
152 'title' => ts('Altered By'),
153 'type' => CRM_Utils_Type
::T_STRING
,
163 function alterDisplay(&$rows) {
164 // cache for id → is_deleted mapping
165 $isDeleted = array();
168 foreach ($rows as $key => &$row) {
169 if (!isset($isDeleted[$row['log_civicrm_entity_altered_contact_id']])) {
170 $isDeleted[$row['log_civicrm_entity_altered_contact_id']] =
171 CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $row['log_civicrm_entity_altered_contact_id'], 'is_deleted') !== '0';
174 if (!empty($row['log_civicrm_entity_altered_contact']) &&
175 !$isDeleted[$row['log_civicrm_entity_altered_contact_id']]) {
176 $row['log_civicrm_entity_altered_contact_link'] =
177 CRM_Utils_System
::url('civicrm/contact/view', 'reset=1&cid=' . $row['log_civicrm_entity_altered_contact_id']);
178 $row['log_civicrm_entity_altered_contact_hover'] = ts("Go to contact summary");
179 $entity = $this->getEntityValue($row['log_civicrm_entity_id'], $row['log_civicrm_entity_log_type'], $row['log_civicrm_entity_log_date']);
181 $row['log_civicrm_entity_altered_contact'] = $row['log_civicrm_entity_altered_contact'] . " [{$entity}]";
183 $row['altered_by_contact_display_name_link'] = CRM_Utils_System
::url('civicrm/contact/view', 'reset=1&cid=' . $row['log_civicrm_entity_log_user_id']);
184 $row['altered_by_contact_display_name_hover'] = ts("Go to contact summary");
186 if ($row['log_civicrm_entity_is_deleted'] and 'Update' == CRM_Utils_Array
::value('log_civicrm_entity_log_action', $row)) {
187 $row['log_civicrm_entity_log_action'] = ts('Delete (to trash)');
190 if ('Contact' == CRM_Utils_Array
::value('log_type', $this->_logTables
[$row['log_civicrm_entity_log_type']]) &&
191 CRM_Utils_Array
::value('log_civicrm_entity_log_action', $row) == 'Insert' ) {
192 $row['log_civicrm_entity_log_action'] = ts('Update');
195 if ($newAction = $this->getEntityAction($row['log_civicrm_entity_id'],
196 $row['log_civicrm_entity_log_conn_id'],
197 $row['log_civicrm_entity_log_type'],
198 CRM_Utils_Array
::value('log_civicrm_entity_log_action', $row)))
199 $row['log_civicrm_entity_log_action'] = $newAction;
201 $row['log_civicrm_entity_log_type'] = $this->getLogType($row['log_civicrm_entity_log_type']);
203 $date = CRM_Utils_Date
::isoToMysql($row['log_civicrm_entity_log_date']);
205 if ('Update' == CRM_Utils_Array
::value('log_civicrm_entity_log_action', $row)) {
206 $q = "reset=1&log_conn_id={$row['log_civicrm_entity_log_conn_id']}&log_date=". $date;
208 $q .= '&cid=' . $this->cid
;
210 $q .= (!empty($row['log_civicrm_entity_altered_contact'])) ?
211 '&alteredName='.$row['log_civicrm_entity_altered_contact'] : '';
212 $q .= (!empty($row['altered_by_contact_display_name'])) ?
213 '&alteredBy='.$row['altered_by_contact_display_name'] : '';
214 $q .= (!empty($row['log_civicrm_entity_log_user_id'])) ?
215 '&alteredById='.$row['log_civicrm_entity_log_user_id'] : '';
217 $url1 = CRM_Report_Utils_Report
::getNextUrl('logging/contact/detail', "{$q}&snippet=4§ion=2&layout=overlay", FALSE, TRUE);
218 $url2 = CRM_Report_Utils_Report
::getNextUrl('logging/contact/detail', "{$q}§ion=2", FALSE, TRUE);
219 $row['log_civicrm_entity_log_action'] = "<a href='{$url1}' class='crm-summary-link'><div class='icon details-icon'></div></a> <a title='View details for this update' href='{$url2}'>" . ts('Update') . '</a>';
223 $row['log_civicrm_entity_log_type'] . '_' .
224 $row['log_civicrm_entity_log_conn_id'] . '_' .
225 $row['log_civicrm_entity_log_user_id'] . '_' .
226 $row['log_civicrm_entity_altered_contact_id'];
227 $newRows[$key] = $row;
229 unset($row['log_civicrm_entity_log_user_id']);
230 unset($row['log_civicrm_entity_log_conn_id']);
238 * @param null $logTable
240 function from( $logTable = null ) {
241 static $entity = null;
246 $detail = $this->_logTables
[$entity];
247 $tableName = CRM_Utils_Array
::value('table_name', $detail, $entity);
248 $clause = CRM_Utils_Array
::value('entity_table', $detail);
249 $clause = $clause ?
"AND entity_log_civireport.entity_table = 'civicrm_contact'" : null;
252 INNER JOIN civicrm_contact modified_contact_civireport
253 ON (entity_log_civireport.{$detail['fk']} = modified_contact_civireport.id {$clause})";
255 if (!empty($detail['joins'])) {
256 $clause = CRM_Utils_Array
::value('entity_table', $detail);
257 $clause = $clause ?
"AND fk_table.entity_table = 'civicrm_contact'" : null;
259 INNER JOIN `{$this->loggingDB}`.{$detail['joins']['table']} fk_table ON {$detail['joins']['join']}
260 INNER JOIN civicrm_contact modified_contact_civireport
261 ON (fk_table.{$detail['fk']} = modified_contact_civireport.id {$clause})";
265 FROM `{$this->loggingDB}`.$tableName entity_log_civireport
267 LEFT JOIN civicrm_contact altered_by_contact_civireport
268 ON (entity_log_civireport.log_user_id = altered_by_contact_civireport.id)";