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