3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * This class is used to retrieve and display activities for a contact
40 class CRM_Activity_Selector_Activity
extends CRM_Core_Selector_Base
implements CRM_Core_Selector_API
{
43 * We use desc to remind us what that column is, name is used in the tpl
48 static $_columnHeaders;
51 * ContactId - contact id of contact whose activies are displayed
55 protected $_contactId;
61 protected $_activityTypeIDs;
63 protected $_viewOptions;
68 * @param int $contactId
69 * Contact whose activities we want to display.
70 * @param int $permission
71 * The permission we have for this contact.
74 * @param string $context
75 * @param null $activityTypeIDs
77 * @return \CRM_Activity_Selector_Activity
84 $context = 'activity',
85 $activityTypeIDs = NULL) {
86 $this->_contactId
= $contactId;
87 $this->_permission
= $permission;
88 $this->_admin
= $admin;
89 $this->_context
= $context;
90 $this->_activityTypeIDs
= $activityTypeIDs;
92 // get all enabled view componentc (check if case is enabled)
93 $this->_viewOptions
= CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
94 'contact_view_options', TRUE, NULL, TRUE
99 * This method returns the action links that are given for each search row.
100 * currently the action links added for each row are
104 * @param int $activityTypeId
105 * @param int $sourceRecordId
106 * @param bool $accessMailingReport
107 * @param int $activityId
109 * @param null $compContext
113 public static function actionLinks(
115 $sourceRecordId = NULL,
116 $accessMailingReport = FALSE,
119 $compContext = NULL) {
120 static $activityActTypes = NULL;
121 //CRM-14277 added addtitional param to handle activity search
122 $extraParams = "&searchContext=activity";
124 $extraParams .= ($key) ?
"&key={$key}" : NULL;
126 $extraParams .= "&compContext={$compContext}";
130 $showUpdate = $showDelete = FALSE;
133 if (!$activityActTypes) {
134 $activeActTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, FALSE, 'name', TRUE);
136 $activityTypeName = CRM_Utils_Array
::value($activityTypeId, $activeActTypes);
139 //lets allow to have normal operation for only activity types.
140 //when activity type is disabled or no more exists give only delete.
141 switch ($activityTypeName) {
142 case 'Event Registration':
143 case 'Change Registration':
144 $url = 'civicrm/contact/view/participant';
145 $qsView = "action=view&reset=1&id={$sourceRecordId}&cid=%%cid%%&context=%%cxt%%{$extraParams}";
149 $url = 'civicrm/contact/view/contribution';
150 $qsView = "action=view&reset=1&id={$sourceRecordId}&cid=%%cid%%&context=%%cxt%%{$extraParams}";
155 $participantId = CRM_Core_DAO
::getFieldValue('CRM_Event_BAO_ParticipantPayment', $sourceRecordId, 'participant_id', 'contribution_id');
156 if (!empty($participantId)) {
157 $url = 'civicrm/contact/view/participant';
158 $qsView = "action=view&reset=1&id={$participantId}&cid=%%cid%%&context=%%cxt%%{$extraParams}";
162 case 'Membership Signup':
163 case 'Membership Renewal':
164 case 'Change Membership Status':
165 case 'Change Membership Type':
166 $url = 'civicrm/contact/view/membership';
167 $qsView = "action=view&reset=1&id={$sourceRecordId}&cid=%%cid%%&context=%%cxt%%{$extraParams}";
170 case 'Pledge Reminder':
171 case 'Pledge Acknowledgment':
172 $url = 'civicrm/contact/view/activity';
173 $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
178 $url = 'civicrm/activity/view';
179 $delUrl = 'civicrm/activity';
180 $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
181 if ($activityTypeName == 'Email') {
186 case 'Inbound Email':
187 $url = 'civicrm/contact/view/activity';
188 $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
192 case 'Change Case Type':
193 case 'Change Case Status':
194 case 'Change Case Start Date':
195 $showUpdate = $showDelete = FALSE;
196 $url = 'civicrm/activity';
197 $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
198 $qsUpdate = "atype={$activityTypeId}&action=update&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
202 $url = 'civicrm/activity';
203 $showView = $showDelete = $showUpdate = TRUE;
204 $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
205 $qsUpdate = "atype={$activityTypeId}&action=update&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
207 //when type is not available lets hide view and update.
208 if (empty($activityTypeName)) {
209 $showView = $showUpdate = FALSE;
214 $qsDelete = "atype={$activityTypeId}&action=delete&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
216 $actionLinks = array();
219 $actionLinks +
= array(CRM_Core_Action
::
221 'name' => ts('View'),
224 'title' => ts('View Activity'),
229 $updateUrl = 'civicrm/activity/add';
230 if ($activityTypeName == 'Email') {
231 $updateUrl = 'civicrm/activity/email/add';
233 elseif ($activityTypeName == 'Print PDF Letter') {
234 $updateUrl = 'civicrm/activity/pdf/add';
236 if (CRM_Activity_BAO_Activity
::checkPermission($activityId, CRM_Core_Action
::UPDATE
)) {
237 $actionLinks +
= array(CRM_Core_Action
::
239 'name' => ts('Edit'),
242 'title' => ts('Update Activity'),
249 CRM_Case_BAO_Case
::checkPermission($activityId, 'File On Case', $activityTypeId)
251 $actionLinks +
= array(CRM_Core_Action
::
253 'name' => ts('File on Case'),
255 'extra' => 'onclick="javascript:fileOnCase( \'file\', \'%%id%%\', null, this ); return false;"',
256 'title' => ts('File on Case'),
261 if (!isset($delUrl) ||
!$delUrl) {
264 $actionLinks +
= array(CRM_Core_Action
::
266 'name' => ts('Delete'),
269 'title' => ts('Delete Activity'),
273 if ($accessMailingReport) {
274 $actionLinks +
= array(CRM_Core_Action
::
276 'name' => ts('Mailing Report'),
277 'url' => 'civicrm/mailing/report',
278 'qs' => "mid={$sourceRecordId}&reset=1&cid=%%cid%%&context=activitySelector",
279 'title' => ts('View Mailing Report'),
287 * Getter for array of the parameters required for creating pager.
290 * @param array $params
293 public function getPagerParams($action, &$params) {
294 $params['status'] = ts('Activities %%StatusMessage%%');
295 $params['csvString'] = NULL;
296 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
298 $params['buttonTop'] = 'PagerTopButton';
299 $params['buttonBottom'] = 'PagerBottomButton';
303 * Returns the column headers as an array of tuples:
304 * (name, sortName (key to the sort array))
306 * @param string $action
307 * The action being performed.
308 * @param enum $output
309 * What should the result set include (web/email/csv).
312 * the column headers that need to be displayed
314 public function &getColumnHeaders($action = NULL, $output = NULL) {
315 if ($output == CRM_Core_Selector_Controller
::EXPORT ||
$output == CRM_Core_Selector_Controller
::SCREEN
) {
316 $csvHeaders = array(ts('Activity Type'), ts('Description'), ts('Activity Date'));
317 foreach (self
::_getColumnHeaders() as $column) {
318 if (array_key_exists('name', $column)) {
319 $csvHeaders[] = $column['name'];
325 return self
::_getColumnHeaders();
330 * Returns total number of rows for the query.
332 * @param string $action
333 * Action being performed.
338 * Total number of rows
340 public function getTotalCount($action, $case = NULL) {
342 'contact_id' => $this->_contactId
,
343 'admin' => $this->_admin
,
345 'context' => $this->_context
,
346 'activity_type_id' => $this->_activityTypeIDs
,
351 return CRM_Activity_BAO_Activity
::getActivitiesCount($params);
355 * Returns all the rows in the given offset and rowCount
357 * @param enum $action
358 * The action being performed.
360 * The row number to start from.
361 * @param int $rowCount
362 * The number of rows to return.
363 * @param string $sort
364 * The sql string that describes the sort order.
365 * @param enum $output
366 * What should the result set include (web/email/csv).
371 * the total number of rows for this action
373 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL, $case = NULL) {
375 'contact_id' => $this->_contactId
,
376 'admin' => $this->_admin
,
378 'context' => $this->_context
,
379 'activity_type_id' => $this->_activityTypeIDs
,
381 'rowCount' => $rowCount,
384 $config = CRM_Core_Config
::singleton();
385 $rows = CRM_Activity_BAO_Activity
::getActivities($params);
391 $activityStatus = CRM_Core_PseudoConstant
::activityStatus();
393 $engagementLevels = CRM_Campaign_PseudoConstant
::engagementLevel();
396 $permissions = array($this->_permission
);
397 if (CRM_Core_Permission
::check('delete activities')) {
398 $permissions[] = CRM_Core_Permission
::DELETE
;
400 $mask = CRM_Core_Action
::mask($permissions);
402 foreach ($rows as $k => $row) {
405 // DRAFTING: provide a facility for db-stored strings
406 // localize the built-in activity names for display
407 // (these are not enums, so we can't use any automagic here)
408 switch ($row['activity_type']) {
410 $row['activity_type'] = ts('Meeting');
414 $row['activity_type'] = ts('Phone Call');
418 $row['activity_type'] = ts('Email');
422 $row['activity_type'] = ts('SMS');
426 $row['activity_type'] = ts('Event');
430 // add class to this row if overdue
431 if (CRM_Utils_Date
::overdue(CRM_Utils_Array
::value('activity_date_time', $row))
432 && CRM_Utils_Array
::value('status_id', $row) == 1
435 $row['class'] = 'status-overdue';
439 $row['class'] = 'status-ontime';
442 $row['status'] = $row['status_id'] ?
$activityStatus[$row['status_id']] : NULL;
444 if ($engagementLevel = CRM_Utils_Array
::value('engagement_level', $row)) {
445 $row['engagement_level'] = CRM_Utils_Array
::value($engagementLevel, $engagementLevels, $engagementLevel);
449 $accessMailingReport = FALSE;
450 if (!empty($row['mailingId'])) {
451 $accessMailingReport = TRUE;
454 $actionLinks = $this->actionLinks(CRM_Utils_Array
::value('activity_type_id', $row),
455 CRM_Utils_Array
::value('source_record_id', $row),
456 $accessMailingReport,
457 CRM_Utils_Array
::value('activity_id', $row),
461 $actionMask = array_sum(array_keys($actionLinks)) & $mask;
463 if ($output != CRM_Core_Selector_Controller
::EXPORT
&& $output != CRM_Core_Selector_Controller
::SCREEN
) {
464 $row['action'] = CRM_Core_Action
::formLink($actionLinks,
467 'id' => $row['activity_id'],
468 'cid' => $this->_contactId
,
469 'cxt' => $this->_context
,
470 'caseid' => CRM_Utils_Array
::value('case_id', $row),
474 'activity.selector.action',
487 * Name of export file.
489 * @param string $output
495 public function getExportFileName($output = 'csv') {
496 return ts('CiviCRM Activity');
500 * Get colunmn headers for search selector
505 private static function &_getColumnHeaders() {
506 if (!isset(self
::$_columnHeaders)) {
507 self
::$_columnHeaders = array(
509 'name' => ts('Type'),
510 'sort' => 'activity_type',
511 'direction' => CRM_Utils_Sort
::DONTCARE
,
514 'name' => ts('Subject'),
516 'direction' => CRM_Utils_Sort
::DONTCARE
,
519 'name' => ts('Added By'),
520 'sort' => 'source_contact_name',
521 'direction' => CRM_Utils_Sort
::DONTCARE
,
523 array('name' => ts('With')),
524 array('name' => ts('Assigned')),
526 'name' => ts('Date'),
527 'sort' => 'activity_date_time',
528 'direction' => CRM_Utils_Sort
::DONTCARE
,
531 'name' => ts('Status'),
532 'sort' => 'status_id',
533 'direction' => CRM_Utils_Sort
::DONTCARE
,
535 array('desc' => ts('Actions')),
539 return self
::$_columnHeaders;