Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-04-07-15-32-51
[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 {
37 function __construct() {
38 $this->_columns = array(
39 'civicrm_contact_altered_contact' => array(
40 'dao' => 'CRM_Contact_DAO_Contact',
41 'fields' => array(
42 'id' => array(
43 'no_display' => TRUE,
44 'required' => TRUE,
45 ),
46 'display_name' => array(
47 'default' => TRUE,
48 'title' => ts('Altered Contact'),
49 ),
50 'is_deleted' => array(
51 'no_display' => TRUE,
52 'required' => TRUE,
53 ),
54 ),
55 'filters' => array(
56 'altered_contact' => array(
57 'name' => 'display_name',
58 'title' => ts('Altered Contact'),
59 'type' => CRM_Utils_Type::T_STRING,
60 ),
61 ),
62 ),
63 'log_civicrm_contribution' => array(
64 'dao' => 'CRM_Contribute_DAO_Contribution',
65 'fields' => array(
66 'id' => array(
67 'no_display' => TRUE,
68 'required' => TRUE,
69 ),
70 'contact_id' => array(
71 'no_display' => TRUE,
72 'required' => TRUE,
73 ),
74 'log_user_id' => array(
75 'no_display' => TRUE,
76 'required' => TRUE,
77 ),
78 'log_date' => array(
79 'default' => TRUE,
80 'required' => TRUE,
81 'type' => CRM_Utils_Type::T_TIME,
82 'title' => ts('When'),
83 ),
84 'log_conn_id' => array(
85 'no_display' => TRUE,
86 'required' => TRUE,
87 ),
88 'log_action' => array(
89 'default' => TRUE,
90 'title' => ts('Action'),
91 ),
b914f4e8 92 'financial_type_id' => array(
6a488035
TO
93 'no_display' => TRUE,
94 'required' => TRUE,
95 ),
96 'contribution_status_id' => array(
97 'no_display' => TRUE,
98 'required' => TRUE,
99 ),
100 'aggregate_amount' => array(
101 'default' => TRUE,
102 'name' => 'total_amount',
103 'title' => ts('Aggregate Amount'),
104 'type' => CRM_Utils_Type::T_MONEY,
105 ),
106 ),
107 'filters' => array(
108 'log_date' => array(
109 'title' => ts('When'),
110 'operatorType' => CRM_Report_Form::OP_DATE,
111 'type' => CRM_Utils_Type::T_DATE,
112 ),
113 'log_action' => array(
114 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
115 'options' => array('Insert' => ts('Insert'), 'Update' => ts('Update'), 'Delete' => ts('Delete')),
116 'title' => ts('Action'),
117 'type' => CRM_Utils_Type::T_STRING,
118 ),
119 'id' => array(
120 'no_display' => TRUE,
121 'type' => CRM_Utils_Type::T_INT,
122 ),
123 ),
124 ),
b914f4e8
PN
125 'civicrm_financial_type' => array(
126 'dao' => 'CRM_Financial_DAO_FinancialType',
6a488035
TO
127 'fields' => array(
128 'id' => array(
129 'no_display' => TRUE,
130 'required' => TRUE,
131 ),
132 'name' => array(
b914f4e8 133 'title' => ts('Financial Type'),
6a488035
TO
134 'type' => CRM_Utils_Type::T_STRING,
135 ),
136 ),
137 ),
138 'civicrm_contribution_status' => array(
139 'dao' => 'CRM_Core_DAO_OptionValue',
140 'fields' => array(
141 'id' => array(
142 'no_display' => TRUE,
143 'required' => TRUE,
144 ),
145 'label' => array(
146 'title' => ts('Contribution Status'),
147 'type' => CRM_Utils_Type::T_STRING,
148 ),
149 ),
150 ),
151 'civicrm_contact_altered_by' => array(
152 'dao' => 'CRM_Contact_DAO_Contact',
153 'fields' => array(
154 'id' => array(
155 'no_display' => TRUE,
156 'required' => TRUE,
157 ),
158 'display_name' => array(
159 'default' => TRUE,
160 'title' => ts('Altered By'),
161 ),
162 ),
163 'filters' => array(
164 'altered_by' => array(
165 'name' => 'display_name',
166 'title' => ts('Altered By'),
167 'type' => CRM_Utils_Type::T_STRING,
168 ),
169 ),
170 ),
171 );
172 parent::__construct();
173 }
174
175 function alterDisplay(&$rows) {
176 // cache for id → is_deleted mapping
177 $isDeleted = array();
178
179 foreach ($rows as & $row) {
180 if (!isset($isDeleted[$row['civicrm_contact_is_deleted']])) {
181 $isDeleted[$row['civicrm_contact_is_deleted']] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $row['civicrm_contact_altered_contact_id'], 'is_deleted') !== '0';
182 }
183
184 if (!$isDeleted[$row['civicrm_contact_is_deleted']]) {
185 $row['civicrm_contact_altered_contact_display_name_link'] = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $row['log_civicrm_contribution_contact_id']);
186 $row['civicrm_contact_altered_contact_display_name_hover'] = ts('Go to contact summary');
187 }
188
189 $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']);
190 $row['civicrm_contact_altered_by_display_name_hover'] = ts('Go to contact summary');
191
192 if ($row['civicrm_contact_altered_contact_is_deleted'] and ($row['log_civicrm_contribution_log_action'] == 'Update')) {
193 $row['log_civicrm_contribution_log_action'] = ts('Delete');
194 }
195
196 if ($row['log_civicrm_contribution_log_action'] == 'Update') {
197 $q = "reset=1&log_conn_id={$row['log_civicrm_contribution_log_conn_id']}&log_date={$row['log_civicrm_contribution_log_date']}";
198 if ($this->cid) {
199 $q .= '&cid=' . $this->cid;
200 }
201
202 $url = CRM_Report_Utils_Report::getNextUrl('logging/contribute/detail', $q, FALSE, TRUE);
203 $row['log_civicrm_contribution_log_action_link'] = $url;
204 $row['log_civicrm_contribution_log_action_hover'] = ts('View details for this update');
205 $row['log_civicrm_contribution_log_action'] = '<div class="icon details-icon"></div> ' . ts('Update');
206 }
207
208 unset($row['log_civicrm_contribute_log_user_id']);
209 unset($row['log_civicrm_contribute_log_conn_id']);
210 }
211 }
212
213 function from() {
214 $this->_from = "
215 FROM `{$this->loggingDB}`.log_civicrm_contribution {$this->_aliases['log_civicrm_contribution']}
216 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact_altered_by']}
217 ON ({$this->_aliases['log_civicrm_contribution']}.log_user_id = {$this->_aliases['civicrm_contact_altered_by']}.id)
218 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact_altered_contact']}
219 ON ({$this->_aliases['log_civicrm_contribution']}.contact_id = {$this->_aliases['civicrm_contact_altered_contact']}.id)
220 LEFT JOIN civicrm_financial_type {$this->_aliases['civicrm_financial_type']}
221 ON ({$this->_aliases['log_civicrm_contribution']}.financial_type_id = {$this->_aliases['civicrm_financial_type']}.id)
222 LEFT JOIN civicrm_option_value {$this->_aliases['civicrm_contribution_status']}
223 ON ({$this->_aliases['log_civicrm_contribution']}.contribution_status_id = {$this->_aliases['civicrm_contribution_status']}.value)
224 INNER JOIN civicrm_option_group
225 ON ({$this->_aliases['civicrm_contribution_status']}.option_group_id = civicrm_option_group.id
226 AND civicrm_option_group.name = 'contribution_status')
227 ";
228 }
229}
230