Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
0f03f337 | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
0f03f337 | 31 | * @copyright CiviCRM LLC (c) 2004-2017 |
6a488035 TO |
32 | */ |
33 | class CRM_Report_Form_Contact_Log extends CRM_Report_Form { | |
34 | ||
35 | protected $_summary = NULL; | |
74cf4551 EM |
36 | |
37 | /** | |
73b448bf | 38 | * Class constructor. |
74cf4551 | 39 | */ |
00be9182 | 40 | public function __construct() { |
6a488035 TO |
41 | |
42 | $this->activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE); | |
43 | asort($this->activityTypes); | |
44 | ||
45 | $this->_columns = array( | |
9d72cede | 46 | 'civicrm_contact' => array( |
6a488035 | 47 | 'dao' => 'CRM_Contact_DAO_Contact', |
9d72cede EM |
48 | 'fields' => array( |
49 | 'sort_name' => array( | |
50 | 'title' => ts('Modified By'), | |
6a488035 TO |
51 | 'required' => TRUE, |
52 | ), | |
9d72cede | 53 | 'id' => array( |
6a488035 TO |
54 | 'no_display' => TRUE, |
55 | 'required' => TRUE, | |
56 | ), | |
57 | ), | |
9d72cede EM |
58 | 'filters' => array( |
59 | 'sort_name' => array( | |
60 | 'title' => ts('Modified By'), | |
6a488035 TO |
61 | 'type' => CRM_Utils_Type::T_STRING, |
62 | ), | |
63 | ), | |
64 | 'grouping' => 'contact-fields', | |
65 | ), | |
9d72cede | 66 | 'civicrm_contact_touched' => array( |
6a488035 | 67 | 'dao' => 'CRM_Contact_DAO_Contact', |
9d72cede EM |
68 | 'fields' => array( |
69 | 'sort_name_touched' => array( | |
70 | 'title' => ts('Touched Contact'), | |
6a488035 TO |
71 | 'name' => 'sort_name', |
72 | 'required' => TRUE, | |
73 | ), | |
9d72cede | 74 | 'id' => array( |
6a488035 TO |
75 | 'no_display' => TRUE, |
76 | 'required' => TRUE, | |
77 | ), | |
78 | ), | |
9d72cede EM |
79 | 'filters' => array( |
80 | 'sort_name_touched' => array( | |
81 | 'title' => ts('Touched Contact'), | |
6a488035 TO |
82 | 'name' => 'sort_name', |
83 | 'type' => CRM_Utils_Type::T_STRING, | |
84 | ), | |
85 | ), | |
86 | 'grouping' => 'contact-fields', | |
87 | ), | |
9d72cede | 88 | 'civicrm_activity' => array( |
6a488035 | 89 | 'dao' => 'CRM_Activity_DAO_Activity', |
9d72cede EM |
90 | 'fields' => array( |
91 | 'id' => array( | |
92 | 'title' => ts('Activity ID'), | |
6a488035 TO |
93 | 'no_display' => TRUE, |
94 | 'required' => TRUE, | |
95 | ), | |
9d72cede EM |
96 | 'subject' => array( |
97 | 'title' => ts('Touched Activity'), | |
6a488035 TO |
98 | 'required' => TRUE, |
99 | ), | |
9d72cede EM |
100 | 'activity_type_id' => array( |
101 | 'title' => ts('Activity Type'), | |
6a488035 TO |
102 | 'required' => TRUE, |
103 | ), | |
18133624 RN |
104 | ), |
105 | ), | |
9d72cede | 106 | 'civicrm_activity_source' => array( |
18133624 | 107 | 'dao' => 'CRM_Activity_DAO_ActivityContact', |
9d72cede EM |
108 | 'fields' => array( |
109 | 'contact_id' => array( | |
6a488035 TO |
110 | 'no_display' => TRUE, |
111 | 'required' => TRUE, | |
112 | ), | |
113 | ), | |
114 | ), | |
9d72cede | 115 | 'civicrm_log' => array( |
6a488035 | 116 | 'dao' => 'CRM_Core_DAO_Log', |
9d72cede EM |
117 | 'fields' => array( |
118 | 'modified_date' => array( | |
119 | 'title' => ts('Modified Date'), | |
6a488035 TO |
120 | 'required' => TRUE, |
121 | ), | |
9d72cede EM |
122 | 'data' => array( |
123 | 'title' => ts('Description'), | |
6a488035 TO |
124 | ), |
125 | ), | |
9d72cede EM |
126 | 'filters' => array( |
127 | 'modified_date' => array( | |
128 | 'title' => ts('Modified Date'), | |
6a488035 TO |
129 | 'operatorType' => CRM_Report_Form::OP_DATE, |
130 | 'type' => CRM_Utils_Type::T_DATE, | |
131 | 'default' => 'this.week', | |
132 | ), | |
133 | ), | |
134 | ), | |
135 | ); | |
136 | ||
137 | parent::__construct(); | |
138 | } | |
139 | ||
00be9182 | 140 | public function preProcess() { |
6a488035 TO |
141 | parent::preProcess(); |
142 | } | |
143 | ||
00be9182 | 144 | public function select() { |
6a488035 TO |
145 | $select = array(); |
146 | $this->_columnHeaders = array(); | |
147 | foreach ($this->_columns as $tableName => $table) { | |
148 | if (array_key_exists('fields', $table)) { | |
149 | foreach ($table['fields'] as $fieldName => $field) { | |
9d72cede EM |
150 | if (!empty($field['required']) || |
151 | !empty($this->_params['fields'][$fieldName]) | |
152 | ) { | |
6a488035 TO |
153 | |
154 | $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}"; | |
155 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field); | |
156 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title']; | |
157 | } | |
158 | } | |
159 | } | |
160 | } | |
161 | ||
162 | $this->_select = "SELECT " . implode(', ', $select) . " "; | |
163 | } | |
164 | ||
74cf4551 EM |
165 | /** |
166 | * @param $fields | |
167 | * @param $files | |
168 | * @param $self | |
169 | * | |
170 | * @return array | |
171 | */ | |
00be9182 | 172 | public static function formRule($fields, $files, $self) { |
6a488035 TO |
173 | $errors = $grouping = array(); |
174 | return $errors; | |
175 | } | |
176 | ||
00be9182 | 177 | public function from() { |
44f817d4 | 178 | $activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate'); |
18133624 | 179 | $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts); |
6a488035 TO |
180 | $this->_from = " |
181 | FROM civicrm_log {$this->_aliases['civicrm_log']} | |
182 | inner join civicrm_contact {$this->_aliases['civicrm_contact']} on {$this->_aliases['civicrm_log']}.modified_id = {$this->_aliases['civicrm_contact']}.id | |
183 | 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) | |
184 | 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 |
185 | LEFT JOIN civicrm_activity_contact {$this->_aliases['civicrm_activity_source']} ON |
186 | {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_source']}.activity_id AND | |
187 | {$this->_aliases['civicrm_activity_source']}.record_type_id = {$sourceID} | |
6a488035 TO |
188 | "; |
189 | } | |
190 | ||
00be9182 | 191 | public function where() { |
6a488035 TO |
192 | $clauses = array(); |
193 | $this->_having = ''; | |
194 | foreach ($this->_columns as $tableName => $table) { | |
195 | if (array_key_exists('filters', $table)) { | |
196 | foreach ($table['filters'] as $fieldName => $field) { | |
197 | $clause = NULL; | |
84178120 | 198 | if (CRM_Utils_Array::value('operatorType', $field) & CRM_Report_Form::OP_DATE |
9d72cede | 199 | ) { |
6a488035 | 200 | $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params); |
9d72cede EM |
201 | $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params); |
202 | $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params); | |
6a488035 TO |
203 | |
204 | $clause = $this->dateClause($field['dbAlias'], $relative, $from, $to); | |
205 | } | |
206 | else { | |
207 | $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params); | |
208 | if ($op) { | |
209 | $clause = $this->whereClause($field, | |
210 | $op, | |
211 | CRM_Utils_Array::value("{$fieldName}_value", $this->_params), | |
212 | CRM_Utils_Array::value("{$fieldName}_min", $this->_params), | |
213 | CRM_Utils_Array::value("{$fieldName}_max", $this->_params) | |
214 | ); | |
215 | } | |
216 | } | |
217 | ||
218 | if (!empty($clause)) { | |
219 | $clauses[] = $clause; | |
220 | } | |
221 | } | |
222 | } | |
223 | } | |
224 | ||
225 | $clauses[] = "({$this->_aliases['civicrm_log']}.entity_table <> 'civicrm_domain')"; | |
226 | $this->_where = "WHERE " . implode(' AND ', $clauses); | |
227 | } | |
228 | ||
00be9182 | 229 | public function orderBy() { |
6a488035 TO |
230 | $this->_orderBy = " |
231 | ORDER BY {$this->_aliases['civicrm_log']}.modified_date DESC, {$this->_aliases['civicrm_contact']}.sort_name, {$this->_aliases['civicrm_contact_touched']}.sort_name | |
232 | "; | |
233 | } | |
234 | ||
74cf4551 | 235 | /** |
ced9bfed EM |
236 | * Alter display of rows. |
237 | * | |
238 | * Iterate through the rows retrieved via SQL and make changes for display purposes, | |
239 | * such as rendering contacts as links. | |
240 | * | |
241 | * @param array $rows | |
242 | * Rows generated by SQL, with an array for each row. | |
74cf4551 | 243 | */ |
00be9182 | 244 | public function alterDisplay(&$rows) { |
ced9bfed | 245 | |
6a488035 TO |
246 | $entryFound = FALSE; |
247 | foreach ($rows as $rowNum => $row) { | |
248 | // convert display name to links | |
249 | if (array_key_exists('civicrm_contact_sort_name', $row) && | |
250 | array_key_exists('civicrm_contact_id', $row) | |
251 | ) { | |
252 | $url = CRM_Utils_System::url('civicrm/contact/view', | |
253 | 'reset=1&cid=' . $row['civicrm_contact_id'], | |
254 | $this->_absoluteUrl | |
255 | ); | |
256 | $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url; | |
257 | $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact details for this contact."); | |
258 | $entryFound = TRUE; | |
259 | } | |
260 | ||
261 | if (array_key_exists('civicrm_contact_touched_sort_name_touched', $row) && | |
262 | array_key_exists('civicrm_contact_touched_id', $row) && | |
263 | $row['civicrm_contact_touched_sort_name_touched'] !== '' | |
264 | ) { | |
265 | $url = CRM_Utils_System::url('civicrm/contact/view', | |
266 | 'reset=1&cid=' . $row['civicrm_contact_touched_id'], | |
267 | $this->_absoluteUrl | |
268 | ); | |
269 | $rows[$rowNum]['civicrm_contact_touched_sort_name_touched_link'] = $url; | |
270 | $rows[$rowNum]['civicrm_contact_touched_sort_name_touched_hover'] = ts("View Contact details for this contact."); | |
271 | $entryFound = TRUE; | |
272 | } | |
273 | ||
274 | if (array_key_exists('civicrm_activity_subject', $row) && | |
275 | array_key_exists('civicrm_activity_id', $row) && | |
276 | $row['civicrm_activity_subject'] !== '' | |
277 | ) { | |
278 | $url = CRM_Utils_System::url('civicrm/contact/view/activity', | |
9d72cede EM |
279 | 'reset=1&action=view&id=' . $row['civicrm_activity_id'] . '&cid=' . |
280 | $row['civicrm_activity_source_contact_id'] . '&atype=' . | |
281 | $row['civicrm_activity_activity_type_id'], | |
6a488035 TO |
282 | $this->_absoluteUrl |
283 | ); | |
284 | $rows[$rowNum]['civicrm_activity_subject_link'] = $url; | |
285 | $rows[$rowNum]['civicrm_activity_subject_hover'] = ts("View Contact details for this contact."); | |
286 | $entryFound = TRUE; | |
287 | } | |
288 | ||
289 | if (array_key_exists('civicrm_activity_activity_type_id', $row)) { | |
290 | if ($value = $row['civicrm_activity_activity_type_id']) { | |
291 | $rows[$rowNum]['civicrm_activity_activity_type_id'] = $this->activityTypes[$value]; | |
292 | } | |
293 | $entryFound = TRUE; | |
294 | } | |
295 | ||
296 | // skip looking further in rows, if first row itself doesn't | |
297 | // have the column we need | |
298 | if (!$entryFound) { | |
299 | break; | |
300 | } | |
301 | } | |
302 | } | |
96025800 | 303 | |
6a488035 | 304 | } |