phpcs - Fix error, "Visibility must be declared on method"
[civicrm-core.git] / CRM / Report / Form / Contact / Log.php
CommitLineData
6a488035 1<?php
6a488035
TO
2
3/*
4 +--------------------------------------------------------------------+
39de6fd5 5 | CiviCRM version 4.6 |
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_Contact_Log extends CRM_Report_Form {
37
38 protected $_summary = NULL;
74cf4551
EM
39
40 /**
41 *
42 */
43 /**
44 *
45 */
00be9182 46 public function __construct() {
6a488035
TO
47
48 $this->activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE);
49 asort($this->activityTypes);
50
51 $this->_columns = array(
9d72cede 52 'civicrm_contact' => array(
6a488035 53 'dao' => 'CRM_Contact_DAO_Contact',
9d72cede
EM
54 'fields' => array(
55 'sort_name' => array(
56 'title' => ts('Modified By'),
6a488035
TO
57 'required' => TRUE,
58 ),
9d72cede 59 'id' => array(
6a488035
TO
60 'no_display' => TRUE,
61 'required' => TRUE,
62 ),
63 ),
9d72cede
EM
64 'filters' => array(
65 'sort_name' => array(
66 'title' => ts('Modified By'),
6a488035
TO
67 'type' => CRM_Utils_Type::T_STRING,
68 ),
69 ),
70 'grouping' => 'contact-fields',
71 ),
9d72cede 72 'civicrm_contact_touched' => array(
6a488035 73 'dao' => 'CRM_Contact_DAO_Contact',
9d72cede
EM
74 'fields' => array(
75 'sort_name_touched' => array(
76 'title' => ts('Touched Contact'),
6a488035
TO
77 'name' => 'sort_name',
78 'required' => TRUE,
79 ),
9d72cede 80 'id' => array(
6a488035
TO
81 'no_display' => TRUE,
82 'required' => TRUE,
83 ),
84 ),
9d72cede
EM
85 'filters' => array(
86 'sort_name_touched' => array(
87 'title' => ts('Touched Contact'),
6a488035
TO
88 'name' => 'sort_name',
89 'type' => CRM_Utils_Type::T_STRING,
90 ),
91 ),
92 'grouping' => 'contact-fields',
93 ),
9d72cede 94 'civicrm_activity' => array(
6a488035 95 'dao' => 'CRM_Activity_DAO_Activity',
9d72cede
EM
96 'fields' => array(
97 'id' => array(
98 'title' => ts('Activity ID'),
6a488035
TO
99 'no_display' => TRUE,
100 'required' => TRUE,
101 ),
9d72cede
EM
102 'subject' => array(
103 'title' => ts('Touched Activity'),
6a488035
TO
104 'required' => TRUE,
105 ),
9d72cede
EM
106 'activity_type_id' => array(
107 'title' => ts('Activity Type'),
6a488035
TO
108 'required' => TRUE,
109 ),
18133624
RN
110 ),
111 ),
9d72cede 112 'civicrm_activity_source' => array(
18133624 113 'dao' => 'CRM_Activity_DAO_ActivityContact',
9d72cede
EM
114 'fields' => array(
115 'contact_id' => array(
6a488035
TO
116 'no_display' => TRUE,
117 'required' => TRUE,
118 ),
119 ),
120 ),
9d72cede 121 'civicrm_log' => array(
6a488035 122 'dao' => 'CRM_Core_DAO_Log',
9d72cede
EM
123 'fields' => array(
124 'modified_date' => array(
125 'title' => ts('Modified Date'),
6a488035
TO
126 'required' => TRUE,
127 ),
9d72cede
EM
128 'data' => array(
129 'title' => ts('Description'),
6a488035
TO
130 ),
131 ),
9d72cede
EM
132 'filters' => array(
133 'modified_date' => array(
134 'title' => ts('Modified Date'),
6a488035
TO
135 'operatorType' => CRM_Report_Form::OP_DATE,
136 'type' => CRM_Utils_Type::T_DATE,
137 'default' => 'this.week',
138 ),
139 ),
140 ),
141 );
142
143 parent::__construct();
144 }
145
00be9182 146 public function preProcess() {
6a488035
TO
147 parent::preProcess();
148 }
149
00be9182 150 public function select() {
6a488035
TO
151 $select = array();
152 $this->_columnHeaders = array();
153 foreach ($this->_columns as $tableName => $table) {
154 if (array_key_exists('fields', $table)) {
155 foreach ($table['fields'] as $fieldName => $field) {
9d72cede
EM
156 if (!empty($field['required']) ||
157 !empty($this->_params['fields'][$fieldName])
158 ) {
6a488035
TO
159
160 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
161 $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
162 $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title'];
163 }
164 }
165 }
166 }
167
168 $this->_select = "SELECT " . implode(', ', $select) . " ";
169 }
170
74cf4551
EM
171 /**
172 * @param $fields
173 * @param $files
174 * @param $self
175 *
176 * @return array
177 */
00be9182 178 public static function formRule($fields, $files, $self) {
6a488035
TO
179 $errors = $grouping = array();
180 return $errors;
181 }
182
00be9182 183 public function from() {
18133624
RN
184 $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
185 $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
6a488035
TO
186 $this->_from = "
187 FROM civicrm_log {$this->_aliases['civicrm_log']}
188 inner join civicrm_contact {$this->_aliases['civicrm_contact']} on {$this->_aliases['civicrm_log']}.modified_id = {$this->_aliases['civicrm_contact']}.id
189 left join civicrm_contact {$this->_aliases['civicrm_contact_touched']} on ({$this->_aliases['civicrm_log']}.entity_table='civicrm_contact' AND {$this->_aliases['civicrm_log']}.entity_id = {$this->_aliases['civicrm_contact_touched']}.id)
190 left join civicrm_activity {$this->_aliases['civicrm_activity']} on ({$this->_aliases['civicrm_log']}.entity_table='civicrm_activity' AND {$this->_aliases['civicrm_log']}.entity_id = {$this->_aliases['civicrm_activity']}.id)
18133624
RN
191 LEFT JOIN civicrm_activity_contact {$this->_aliases['civicrm_activity_source']} ON
192 {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_source']}.activity_id AND
193 {$this->_aliases['civicrm_activity_source']}.record_type_id = {$sourceID}
6a488035
TO
194 ";
195 }
196
00be9182 197 public function where() {
6a488035
TO
198 $clauses = array();
199 $this->_having = '';
200 foreach ($this->_columns as $tableName => $table) {
201 if (array_key_exists('filters', $table)) {
202 foreach ($table['filters'] as $fieldName => $field) {
203 $clause = NULL;
9d72cede
EM
204 if (CRM_Utils_Array::value('operatorType', $field) &
205 CRM_Report_Form::OP_DATE
206 ) {
6a488035 207 $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params);
9d72cede
EM
208 $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params);
209 $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params);
6a488035
TO
210
211 $clause = $this->dateClause($field['dbAlias'], $relative, $from, $to);
212 }
213 else {
214 $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
215 if ($op) {
216 $clause = $this->whereClause($field,
217 $op,
218 CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
219 CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
220 CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
221 );
222 }
223 }
224
225 if (!empty($clause)) {
226 $clauses[] = $clause;
227 }
228 }
229 }
230 }
231
232 $clauses[] = "({$this->_aliases['civicrm_log']}.entity_table <> 'civicrm_domain')";
233 $this->_where = "WHERE " . implode(' AND ', $clauses);
234 }
235
00be9182 236 public function orderBy() {
6a488035
TO
237 $this->_orderBy = "
238ORDER BY {$this->_aliases['civicrm_log']}.modified_date DESC, {$this->_aliases['civicrm_contact']}.sort_name, {$this->_aliases['civicrm_contact_touched']}.sort_name
239";
240 }
241
74cf4551
EM
242 /**
243 * @param $rows
244 */
00be9182 245 public function alterDisplay(&$rows) {
6a488035
TO
246 // custom code to alter rows
247 $entryFound = FALSE;
248 foreach ($rows as $rowNum => $row) {
249 // convert display name to links
250 if (array_key_exists('civicrm_contact_sort_name', $row) &&
251 array_key_exists('civicrm_contact_id', $row)
252 ) {
253 $url = CRM_Utils_System::url('civicrm/contact/view',
254 'reset=1&cid=' . $row['civicrm_contact_id'],
255 $this->_absoluteUrl
256 );
257 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
258 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact details for this contact.");
259 $entryFound = TRUE;
260 }
261
262 if (array_key_exists('civicrm_contact_touched_sort_name_touched', $row) &&
263 array_key_exists('civicrm_contact_touched_id', $row) &&
264 $row['civicrm_contact_touched_sort_name_touched'] !== ''
265 ) {
266 $url = CRM_Utils_System::url('civicrm/contact/view',
267 'reset=1&cid=' . $row['civicrm_contact_touched_id'],
268 $this->_absoluteUrl
269 );
270 $rows[$rowNum]['civicrm_contact_touched_sort_name_touched_link'] = $url;
271 $rows[$rowNum]['civicrm_contact_touched_sort_name_touched_hover'] = ts("View Contact details for this contact.");
272 $entryFound = TRUE;
273 }
274
275 if (array_key_exists('civicrm_activity_subject', $row) &&
276 array_key_exists('civicrm_activity_id', $row) &&
277 $row['civicrm_activity_subject'] !== ''
278 ) {
279 $url = CRM_Utils_System::url('civicrm/contact/view/activity',
9d72cede
EM
280 'reset=1&action=view&id=' . $row['civicrm_activity_id'] . '&cid=' .
281 $row['civicrm_activity_source_contact_id'] . '&atype=' .
282 $row['civicrm_activity_activity_type_id'],
6a488035
TO
283 $this->_absoluteUrl
284 );
285 $rows[$rowNum]['civicrm_activity_subject_link'] = $url;
286 $rows[$rowNum]['civicrm_activity_subject_hover'] = ts("View Contact details for this contact.");
287 $entryFound = TRUE;
288 }
289
290 if (array_key_exists('civicrm_activity_activity_type_id', $row)) {
291 if ($value = $row['civicrm_activity_activity_type_id']) {
292 $rows[$rowNum]['civicrm_activity_activity_type_id'] = $this->activityTypes[$value];
293 }
294 $entryFound = TRUE;
295 }
296
297 // skip looking further in rows, if first row itself doesn't
298 // have the column we need
299 if (!$entryFound) {
300 break;
301 }
302 }
303 }
304}
305