Merge pull request #4764 from rohankatkar/CRM-15615
[civicrm-core.git] / CRM / Report / Form / Contribute / LoggingSummary.php
CommitLineData
6a488035 1<?php
6a488035
TO
2
3/*
4 +--------------------------------------------------------------------+
06b69b18 5 | CiviCRM version 4.5 |
6a488035 6 +--------------------------------------------------------------------+
06b69b18 7 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
27*/
28
29/**
30 *
31 * @package CRM
06b69b18 32 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
33 * $Id$
34 *
35 */
36class CRM_Report_Form_Contribute_LoggingSummary extends CRM_Logging_ReportSummary {
74cf4551
EM
37 /**
38 *
39 */
6a488035
TO
40 function __construct() {
41 $this->_columns = array(
42 'civicrm_contact_altered_contact' => array(
43 'dao' => 'CRM_Contact_DAO_Contact',
44 'fields' => array(
45 'id' => array(
46 'no_display' => TRUE,
47 'required' => TRUE,
48 ),
49 'display_name' => array(
50 'default' => TRUE,
51 'title' => ts('Altered Contact'),
52 ),
53 'is_deleted' => array(
54 'no_display' => TRUE,
55 'required' => TRUE,
56 ),
57 ),
58 'filters' => array(
59 'altered_contact' => array(
60 'name' => 'display_name',
61 'title' => ts('Altered Contact'),
62 'type' => CRM_Utils_Type::T_STRING,
63 ),
64 ),
65 ),
66 'log_civicrm_contribution' => array(
67 'dao' => 'CRM_Contribute_DAO_Contribution',
68 'fields' => array(
69 'id' => array(
70 'no_display' => TRUE,
71 'required' => TRUE,
72 ),
73 'contact_id' => array(
74 'no_display' => TRUE,
75 'required' => TRUE,
76 ),
77 'log_user_id' => array(
78 'no_display' => TRUE,
79 'required' => TRUE,
80 ),
81 'log_date' => array(
82 'default' => TRUE,
83 'required' => TRUE,
84 'type' => CRM_Utils_Type::T_TIME,
85 'title' => ts('When'),
86 ),
87 'log_conn_id' => array(
88 'no_display' => TRUE,
89 'required' => TRUE,
90 ),
91 'log_action' => array(
92 'default' => TRUE,
93 'title' => ts('Action'),
94 ),
b914f4e8 95 'financial_type_id' => array(
6a488035
TO
96 'no_display' => TRUE,
97 'required' => TRUE,
98 ),
99 'contribution_status_id' => array(
100 'no_display' => TRUE,
101 'required' => TRUE,
102 ),
103 'aggregate_amount' => array(
104 'default' => TRUE,
105 'name' => 'total_amount',
106 'title' => ts('Aggregate Amount'),
107 'type' => CRM_Utils_Type::T_MONEY,
108 ),
109 ),
110 'filters' => array(
111 'log_date' => array(
112 'title' => ts('When'),
113 'operatorType' => CRM_Report_Form::OP_DATE,
114 'type' => CRM_Utils_Type::T_DATE,
115 ),
116 'log_action' => array(
117 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
118 'options' => array('Insert' => ts('Insert'), 'Update' => ts('Update'), 'Delete' => ts('Delete')),
119 'title' => ts('Action'),
120 'type' => CRM_Utils_Type::T_STRING,
121 ),
122 'id' => array(
123 'no_display' => TRUE,
124 'type' => CRM_Utils_Type::T_INT,
125 ),
126 ),
127 ),
b914f4e8
PN
128 'civicrm_financial_type' => array(
129 'dao' => 'CRM_Financial_DAO_FinancialType',
6a488035
TO
130 'fields' => array(
131 'id' => array(
132 'no_display' => TRUE,
133 'required' => TRUE,
134 ),
135 'name' => array(
b914f4e8 136 'title' => ts('Financial Type'),
6a488035
TO
137 'type' => CRM_Utils_Type::T_STRING,
138 ),
139 ),
140 ),
141 'civicrm_contribution_status' => array(
142 'dao' => 'CRM_Core_DAO_OptionValue',
143 'fields' => array(
144 'id' => array(
145 'no_display' => TRUE,
146 'required' => TRUE,
147 ),
148 'label' => array(
149 'title' => ts('Contribution Status'),
150 'type' => CRM_Utils_Type::T_STRING,
151 ),
152 ),
153 ),
154 'civicrm_contact_altered_by' => array(
155 'dao' => 'CRM_Contact_DAO_Contact',
156 'fields' => array(
157 'id' => array(
158 'no_display' => TRUE,
159 'required' => TRUE,
160 ),
161 'display_name' => array(
162 'default' => TRUE,
163 'title' => ts('Altered By'),
164 ),
165 ),
166 'filters' => array(
167 'altered_by' => array(
168 'name' => 'display_name',
169 'title' => ts('Altered By'),
170 'type' => CRM_Utils_Type::T_STRING,
171 ),
172 ),
173 ),
174 );
175 parent::__construct();
176 }
177
74cf4551
EM
178 /**
179 * @param $rows
180 */
6a488035
TO
181 function alterDisplay(&$rows) {
182 // cache for id → is_deleted mapping
183 $isDeleted = array();
184
185 foreach ($rows as & $row) {
186 if (!isset($isDeleted[$row['civicrm_contact_is_deleted']])) {
187 $isDeleted[$row['civicrm_contact_is_deleted']] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $row['civicrm_contact_altered_contact_id'], 'is_deleted') !== '0';
188 }
189
190 if (!$isDeleted[$row['civicrm_contact_is_deleted']]) {
191 $row['civicrm_contact_altered_contact_display_name_link'] = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $row['log_civicrm_contribution_contact_id']);
192 $row['civicrm_contact_altered_contact_display_name_hover'] = ts('Go to contact summary');
193 }
194
195 $row['civicrm_contact_altered_by_display_name_link'] = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $row['log_civicrm_contribution_log_user_id']);
196 $row['civicrm_contact_altered_by_display_name_hover'] = ts('Go to contact summary');
197
198 if ($row['civicrm_contact_altered_contact_is_deleted'] and ($row['log_civicrm_contribution_log_action'] == 'Update')) {
199 $row['log_civicrm_contribution_log_action'] = ts('Delete');
200 }
201
202 if ($row['log_civicrm_contribution_log_action'] == 'Update') {
203 $q = "reset=1&log_conn_id={$row['log_civicrm_contribution_log_conn_id']}&log_date={$row['log_civicrm_contribution_log_date']}";
204 if ($this->cid) {
205 $q .= '&cid=' . $this->cid;
206 }
207
208 $url = CRM_Report_Utils_Report::getNextUrl('logging/contribute/detail', $q, FALSE, TRUE);
209 $row['log_civicrm_contribution_log_action_link'] = $url;
210 $row['log_civicrm_contribution_log_action_hover'] = ts('View details for this update');
211 $row['log_civicrm_contribution_log_action'] = '<div class="icon details-icon"></div> ' . ts('Update');
212 }
213
214 unset($row['log_civicrm_contribute_log_user_id']);
215 unset($row['log_civicrm_contribute_log_conn_id']);
216 }
217 }
218
219 function from() {
220 $this->_from = "
221 FROM `{$this->loggingDB}`.log_civicrm_contribution {$this->_aliases['log_civicrm_contribution']}
222 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact_altered_by']}
223 ON ({$this->_aliases['log_civicrm_contribution']}.log_user_id = {$this->_aliases['civicrm_contact_altered_by']}.id)
224 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact_altered_contact']}
225 ON ({$this->_aliases['log_civicrm_contribution']}.contact_id = {$this->_aliases['civicrm_contact_altered_contact']}.id)
226 LEFT JOIN civicrm_financial_type {$this->_aliases['civicrm_financial_type']}
227 ON ({$this->_aliases['log_civicrm_contribution']}.financial_type_id = {$this->_aliases['civicrm_financial_type']}.id)
228 LEFT JOIN civicrm_option_value {$this->_aliases['civicrm_contribution_status']}
229 ON ({$this->_aliases['log_civicrm_contribution']}.contribution_status_id = {$this->_aliases['civicrm_contribution_status']}.value)
230 INNER JOIN civicrm_option_group
231 ON ({$this->_aliases['civicrm_contribution_status']}.option_group_id = civicrm_option_group.id
232 AND civicrm_option_group.name = 'contribution_status')
233 ";
234 }
235}
236