3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class is used to retrieve and display activities for a contact.
21 class CRM_Activity_Selector_Activity
extends CRM_Core_Selector_Base
implements CRM_Core_Selector_API
{
24 * We use desc to remind us what that column is, name is used in the tpl
28 public static $_columnHeaders;
31 * ContactId - contact id of contact whose activies are displayed
35 protected $_contactId;
41 protected $_activityTypeIDs;
43 protected $_viewOptions;
48 * @param int $contactId
49 * Contact whose activities we want to display.
50 * @param int $permission
51 * The permission we have for this contact.
54 * @param string $context
55 * @param null $activityTypeIDs
57 * @return \CRM_Activity_Selector_Activity
59 public function __construct(
63 $context = 'activity',
64 $activityTypeIDs = NULL) {
65 $this->_contactId
= $contactId;
66 $this->_permission
= $permission;
67 $this->_admin
= $admin;
68 $this->_context
= $context;
69 $this->_activityTypeIDs
= $activityTypeIDs;
71 // get all enabled view componentc (check if case is enabled)
72 $this->_viewOptions
= CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
73 'contact_view_options', TRUE, NULL, TRUE
78 * This method returns the action links that are given for each search row.
79 * currently the action links added for each row are
83 * @param int $activityTypeId
84 * @param int $sourceRecordId
85 * @param bool $accessMailingReport
86 * @param int $activityId
88 * @param null $compContext
92 public static function actionLinks(
94 $sourceRecordId = NULL,
95 $accessMailingReport = FALSE,
98 $compContext = NULL) {
100 //CRM-14277 added additional param to handle activity search
101 $extraParams = "&searchContext=activity";
103 $extraParams .= ($key) ?
"&key={$key}" : NULL;
105 $extraParams .= "&compContext={$compContext}";
109 $showUpdate = $showDelete = FALSE;
114 $activityTypeName = CRM_Core_PseudoConstant
::getName('CRM_Activity_BAO_Activity', 'activity_type_id', $activityTypeId);
117 // Lets allow to have normal operation for only activity types.
118 // When activity type is disabled or no more exists give only delete.
119 switch ($activityTypeName) {
120 case 'Event Registration':
121 case 'Change Registration':
122 $url = 'civicrm/contact/view/participant';
123 $qsView = "action=view&reset=1&id={$sourceRecordId}&cid=%%cid%%&context=%%cxt%%{$extraParams}";
127 $url = 'civicrm/contact/view/contribution';
128 $qsView = "action=view&reset=1&id={$sourceRecordId}&cid=%%cid%%&context=%%cxt%%{$extraParams}";
133 $participantId = CRM_Core_DAO
::getFieldValue('CRM_Event_BAO_ParticipantPayment', $sourceRecordId, 'participant_id', 'contribution_id');
134 if (!empty($participantId)) {
135 $url = 'civicrm/contact/view/participant';
136 $qsView = "action=view&reset=1&id={$participantId}&cid=%%cid%%&context=%%cxt%%{$extraParams}";
140 case 'Membership Signup':
141 case 'Membership Renewal':
142 case 'Change Membership Status':
143 case 'Change Membership Type':
144 $url = 'civicrm/contact/view/membership';
145 $qsView = "action=view&reset=1&id={$sourceRecordId}&cid=%%cid%%&context=%%cxt%%{$extraParams}";
148 case 'Pledge Reminder':
149 case 'Pledge Acknowledgment':
150 $url = 'civicrm/contact/view/activity';
151 $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
156 $url = 'civicrm/activity/view';
157 $delUrl = 'civicrm/activity';
158 $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
159 if ($activityTypeName == 'Email') {
164 case 'Inbound Email':
165 $url = 'civicrm/contact/view/activity';
166 $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
168 if (CRM_Activity_BAO_Activity
::checkEditInboundEmailsPermissions()) {
169 $showDelete = $showUpdate = TRUE;
170 $qsUpdate = "atype={$activityTypeId}&action=update&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
175 case 'Change Case Type':
176 case 'Change Case Status':
177 case 'Change Case Start Date':
178 $showUpdate = $showDelete = FALSE;
179 $url = 'civicrm/activity';
180 $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
181 $qsUpdate = "atype={$activityTypeId}&action=update&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
185 $url = 'civicrm/activity';
186 $showView = $showDelete = $showUpdate = TRUE;
187 $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
188 $qsUpdate = "atype={$activityTypeId}&action=update&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
190 // When type is not available lets hide view and update.
191 if (empty($activityTypeName)) {
192 $showView = $showUpdate = FALSE;
197 $qsDelete = "atype={$activityTypeId}&action=delete&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
205 'name' => ts('View'),
208 'title' => ts('View Activity'),
214 $updateUrl = 'civicrm/activity/add';
215 if ($activityTypeName == 'Email') {
216 $updateUrl = 'civicrm/activity/email/add';
218 elseif ($activityTypeName == 'Print PDF Letter') {
219 $updateUrl = 'civicrm/activity/pdf/add';
221 if (CRM_Activity_BAO_Activity
::checkPermission($activityId, CRM_Core_Action
::UPDATE
)) {
225 'name' => ts('Edit'),
228 'title' => ts('Update Activity'),
236 CRM_Case_BAO_Case
::checkPermission($activityId, 'File On Case', $activityTypeId)
241 'name' => ts('File on Case'),
243 'extra' => 'onclick="javascript:fileOnCase( \'file\', \'%%id%%\', null, this ); return false;"',
244 'title' => ts('File on Case'),
250 if (!isset($delUrl) ||
!$delUrl) {
256 'name' => ts('Delete'),
259 'title' => ts('Delete Activity'),
264 if ($accessMailingReport) {
268 'name' => ts('Mailing Report'),
269 'url' => 'civicrm/mailing/report',
270 'qs' => "mid={$sourceRecordId}&reset=1&cid=%%cid%%&context=activitySelector",
271 'title' => ts('View Mailing Report'),
280 * Getter for array of the parameters required for creating pager.
283 * @param array $params
285 public function getPagerParams($action, &$params) {
286 $params['status'] = ts('Activities %%StatusMessage%%');
287 $params['csvString'] = NULL;
288 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
290 $params['buttonTop'] = 'PagerTopButton';
291 $params['buttonBottom'] = 'PagerBottomButton';
295 * Returns the column headers as an array of tuples:
296 * (name, sortName (key to the sort array))
298 * @param string $action
299 * The action being performed.
300 * @param string $output
301 * What should the result set include (web/email/csv).
304 * the column headers that need to be displayed
306 public function &getColumnHeaders($action = NULL, $output = NULL) {
307 if ($output == CRM_Core_Selector_Controller
::EXPORT ||
$output == CRM_Core_Selector_Controller
::SCREEN
) {
308 $csvHeaders = [ts('Activity Type'), ts('Description'), ts('Activity Date')];
309 foreach (self
::_getColumnHeaders() as $column) {
310 if (array_key_exists('name', $column)) {
311 $csvHeaders[] = $column['name'];
317 return self
::_getColumnHeaders();
322 * Returns total number of rows for the query.
324 * @param string $action
325 * Action being performed.
330 * Total number of rows
332 public function getTotalCount($action, $case = NULL) {
334 'contact_id' => $this->_contactId
,
335 'admin' => $this->_admin
,
337 'context' => $this->_context
,
338 'activity_type_id' => $this->_activityTypeIDs
,
343 return CRM_Activity_BAO_Activity
::getActivitiesCount($params);
347 * Returns all the rows in the given offset and rowCount.
349 * @param string $action
350 * The action being performed.
352 * The row number to start from.
353 * @param int $rowCount
354 * The number of rows to return.
355 * @param string $sort
356 * The sql string that describes the sort order.
357 * @param string $output
358 * What should the result set include (web/email/csv).
363 * the total number of rows for this action
365 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL, $case = NULL) {
367 'contact_id' => $this->_contactId
,
368 'admin' => $this->_admin
,
370 'context' => $this->_context
,
371 'activity_type_id' => $this->_activityTypeIDs
,
373 'rowCount' => $rowCount,
376 $config = CRM_Core_Config
::singleton();
377 $rows = CRM_Activity_BAO_Activity
::getActivities($params);
383 $activityStatus = CRM_Core_PseudoConstant
::activityStatus();
385 $engagementLevels = CRM_Campaign_PseudoConstant
::engagementLevel();
388 $permissions = [$this->_permission
];
389 if (CRM_Core_Permission
::check('delete activities')) {
390 $permissions[] = CRM_Core_Permission
::DELETE
;
392 $mask = CRM_Core_Action
::mask($permissions);
394 foreach ($rows as $k => $row) {
397 // DRAFTING: provide a facility for db-stored strings
398 // localize the built-in activity names for display
399 // (these are not enums, so we can't use any automagic here)
400 switch ($row['activity_type']) {
402 $row['activity_type'] = ts('Meeting');
406 $row['activity_type'] = ts('Phone Call');
410 $row['activity_type'] = ts('Email');
414 $row['activity_type'] = ts('SMS');
418 $row['activity_type'] = ts('Event');
422 // add class to this row if overdue
423 if (CRM_Utils_Date
::overdue(CRM_Utils_Array
::value('activity_date_time', $row))
424 && CRM_Utils_Array
::value('status_id', $row) == 1
427 $row['class'] = 'status-overdue';
431 $row['class'] = 'status-ontime';
434 $row['status'] = $row['status_id'] ?
$activityStatus[$row['status_id']] : NULL;
436 if ($engagementLevel = CRM_Utils_Array
::value('engagement_level', $row)) {
437 $row['engagement_level'] = CRM_Utils_Array
::value($engagementLevel, $engagementLevels, $engagementLevel);
441 $accessMailingReport = FALSE;
442 if (!empty($row['mailingId'])) {
443 $accessMailingReport = TRUE;
446 $actionLinks = $this->actionLinks(CRM_Utils_Array
::value('activity_type_id', $row),
447 CRM_Utils_Array
::value('source_record_id', $row),
448 $accessMailingReport,
449 CRM_Utils_Array
::value('activity_id', $row),
453 $actionMask = array_sum(array_keys($actionLinks)) & $mask;
455 if ($output != CRM_Core_Selector_Controller
::EXPORT
&& $output != CRM_Core_Selector_Controller
::SCREEN
) {
456 $row['action'] = CRM_Core_Action
::formLink($actionLinks,
459 'id' => $row['activity_id'],
460 'cid' => $this->_contactId
,
461 'cxt' => $this->_context
,
462 'caseid' => CRM_Utils_Array
::value('case_id', $row),
466 'activity.selector.action',
479 * Name of export file.
481 * @param string $output
487 public function getExportFileName($output = 'csv') {
488 return ts('CiviCRM Activity');
492 * Get colunmn headers for search selector.
497 private static function &_getColumnHeaders() {
498 if (!isset(self
::$_columnHeaders)) {
499 self
::$_columnHeaders = [
501 'name' => ts('Type'),
502 'sort' => 'activity_type',
503 'direction' => CRM_Utils_Sort
::DONTCARE
,
506 'name' => ts('Subject'),
508 'direction' => CRM_Utils_Sort
::DONTCARE
,
511 'name' => ts('Added By'),
512 'sort' => 'source_contact_name',
513 'direction' => CRM_Utils_Sort
::DONTCARE
,
515 ['name' => ts('With')],
516 ['name' => ts('Assigned')],
518 'name' => ts('Date'),
519 'sort' => 'activity_date_time',
520 'direction' => CRM_Utils_Sort
::DONTCARE
,
523 'name' => ts('Status'),
524 'sort' => 'status_id',
525 'direction' => CRM_Utils_Sort
::DONTCARE
,
527 ['desc' => ts('Actions')],
531 return self
::$_columnHeaders;