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
{
36 function __construct() {
37 parent
::__construct();
40 foreach ( array_keys($this->_logTables
) as $table ) {
41 $type = $this->getLogType($table);
42 $logTypes[$type] = $type;
46 $this->_columns
= array(
47 'log_civicrm_entity' => array(
48 'dao' => 'CRM_Contact_DAO_Contact',
49 'alias' => 'entity_log',
55 'log_action' => array(
57 'title' => ts('Action'),
61 'title' => ts('Log Type'),
63 'log_user_id' => array(
70 'type' => CRM_Utils_Type
::T_TIME
,
71 'title' => ts('When'),
73 'altered_contact' => array(
75 'name' => 'display_name',
76 'title' => ts('Altered Contact'),
77 'alias' => 'modified_contact_civireport',
79 'altered_contact_id' => array(
83 'alias' => 'modified_contact_civireport',
85 'log_conn_id' => array(
89 'is_deleted' => array(
92 'alias' => 'modified_contact_civireport',
97 'title' => ts('When'),
98 'operatorType' => CRM_Report_Form
::OP_DATE
,
99 'type' => CRM_Utils_Type
::T_DATE
,
101 'altered_contact' => array(
102 'name' => 'display_name',
103 'title' => ts('Altered Contact'),
104 'type' => CRM_Utils_Type
::T_STRING
,
105 'alias' => 'modified_contact_civireport',
107 'altered_contact_id' => array(
109 'type' => CRM_Utils_Type
::T_INT
,
110 'alias' => 'modified_contact_civireport',
111 'no_display' => TRUE,
114 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
115 'options' => $logTypes,
116 'title' => ts('Log Type'),
117 'type' => CRM_Utils_Type
::T_STRING
,
119 'log_type_table' => array(
120 'name' => 'log_type',
121 'title' => ts('Log Type Table'),
122 'type' => CRM_Utils_Type
::T_STRING
,
124 'log_action' => array(
125 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
126 'options' => array('Insert' => ts('Insert'), 'Update' => ts('Update'), 'Delete' => ts('Delete')),
127 'title' => ts('Action'),
128 'type' => CRM_Utils_Type
::T_STRING
,
131 'no_display' => TRUE,
132 'type' => CRM_Utils_Type
::T_INT
,
136 'altered_by_contact' => array(
137 'dao' => 'CRM_Contact_DAO_Contact',
138 'alias' => 'altered_by_contact',
140 'display_name' => array(
142 'name' => 'display_name',
143 'title' => ts('Altered By'),
147 'display_name' => array(
148 'name' => 'display_name',
149 'title' => ts('Altered By'),
150 'type' => CRM_Utils_Type
::T_STRING
,
157 function alterDisplay(&$rows) {
158 // cache for id → is_deleted mapping
159 $isDeleted = array();
162 foreach ($rows as $key => &$row) {
163 if (!isset($isDeleted[$row['log_civicrm_entity_altered_contact_id']])) {
164 $isDeleted[$row['log_civicrm_entity_altered_contact_id']] =
165 CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $row['log_civicrm_entity_altered_contact_id'], 'is_deleted') !== '0';
168 if (!empty($row['log_civicrm_entity_altered_contact']) &&
169 !$isDeleted[$row['log_civicrm_entity_altered_contact_id']]) {
170 $row['log_civicrm_entity_altered_contact_link'] =
171 CRM_Utils_System
::url('civicrm/contact/view', 'reset=1&cid=' . $row['log_civicrm_entity_altered_contact_id']);
172 $row['log_civicrm_entity_altered_contact_hover'] = ts("Go to contact summary");
173 $entity = $this->getEntityValue($row['log_civicrm_entity_id'], $row['log_civicrm_entity_log_type'], $row['log_civicrm_entity_log_date']);
175 $row['log_civicrm_entity_altered_contact'] = $row['log_civicrm_entity_altered_contact'] . " [{$entity}]";
177 $row['altered_by_contact_display_name_link'] = CRM_Utils_System
::url('civicrm/contact/view', 'reset=1&cid=' . $row['log_civicrm_entity_log_user_id']);
178 $row['altered_by_contact_display_name_hover'] = ts("Go to contact summary");
180 if ($row['log_civicrm_entity_is_deleted'] and 'Update' == CRM_Utils_Array
::value('log_civicrm_entity_log_action', $row)) {
181 $row['log_civicrm_entity_log_action'] = ts('Delete (to trash)');
184 if ('Contact' == CRM_Utils_Array
::value('log_type', $this->_logTables
[$row['log_civicrm_entity_log_type']]) &&
185 CRM_Utils_Array
::value('log_civicrm_entity_log_action', $row) == 'Insert' ) {
186 $row['log_civicrm_entity_log_action'] = ts('Update');
189 if ($newAction = $this->getEntityAction($row['log_civicrm_entity_id'],
190 $row['log_civicrm_entity_log_conn_id'],
191 $row['log_civicrm_entity_log_type'],
192 CRM_Utils_Array
::value('log_civicrm_entity_log_action', $row)))
193 $row['log_civicrm_entity_log_action'] = $newAction;
195 $row['log_civicrm_entity_log_type'] = $this->getLogType($row['log_civicrm_entity_log_type']);
197 $date = CRM_Utils_Date
::isoToMysql($row['log_civicrm_entity_log_date']);
199 if ('Update' == CRM_Utils_Array
::value('log_civicrm_entity_log_action', $row)) {
200 $q = "reset=1&log_conn_id={$row['log_civicrm_entity_log_conn_id']}&log_date=". $date;
202 $q .= '&cid=' . $this->cid
;
204 $q .= (!empty($row['log_civicrm_entity_altered_contact'])) ?
205 '&alteredName='.$row['log_civicrm_entity_altered_contact'] : '';
206 $q .= (!empty($row['altered_by_contact_display_name'])) ?
207 '&alteredBy='.$row['altered_by_contact_display_name'] : '';
208 $q .= (!empty($row['log_civicrm_entity_log_user_id'])) ?
209 '&alteredById='.$row['log_civicrm_entity_log_user_id'] : '';
211 $url1 = CRM_Report_Utils_Report
::getNextUrl('logging/contact/detail', "{$q}&snippet=4§ion=2&layout=overlay", FALSE, TRUE);
212 $url2 = CRM_Report_Utils_Report
::getNextUrl('logging/contact/detail', "{$q}§ion=2", FALSE, TRUE);
213 $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>';
217 $row['log_civicrm_entity_log_type'] . '_' .
218 $row['log_civicrm_entity_log_conn_id'] . '_' .
219 $row['log_civicrm_entity_log_user_id'] . '_' .
220 $row['log_civicrm_entity_altered_contact_id'];
221 $newRows[$key] = $row;
223 unset($row['log_civicrm_entity_log_user_id']);
224 unset($row['log_civicrm_entity_log_conn_id']);
231 function from( $logTable = null ) {
232 static $entity = null;
237 $detail = $this->_logTables
[$entity];
238 $tableName = CRM_Utils_Array
::value('table_name', $detail, $entity);
239 $clause = CRM_Utils_Array
::value('entity_table', $detail);
240 $clause = $clause ?
"AND entity_log_civireport.entity_table = 'civicrm_contact'" : null;
243 INNER JOIN civicrm_contact modified_contact_civireport
244 ON (entity_log_civireport.{$detail['fk']} = modified_contact_civireport.id {$clause})";
246 if (!empty($detail['joins'])) {
247 $clause = CRM_Utils_Array
::value('entity_table', $detail);
248 $clause = $clause ?
"AND fk_table.entity_table = 'civicrm_contact'" : null;
250 INNER JOIN `{$this->loggingDB}`.{$detail['joins']['table']} fk_table ON {$detail['joins']['join']}
251 INNER JOIN civicrm_contact modified_contact_civireport
252 ON (fk_table.{$detail['fk']} = modified_contact_civireport.id {$clause})";
256 FROM `{$this->loggingDB}`.$tableName entity_log_civireport
258 LEFT JOIN civicrm_contact altered_by_contact_civireport
259 ON (entity_log_civireport.log_user_id = altered_by_contact_civireport.id)";