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