3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
35 * This class is used to retrieve and display activities for a contact.
37 class CRM_Activity_Selector_Activity
extends CRM_Core_Selector_Base
implements CRM_Core_Selector_API
{
40 * We use desc to remind us what that column is, name is used in the tpl
44 static $_columnHeaders;
47 * ContactId - contact id of contact whose activies are displayed
51 protected $_contactId;
57 protected $_activityTypeIDs;
59 protected $_viewOptions;
64 * @param int $contactId
65 * Contact whose activities we want to display.
66 * @param int $permission
67 * The permission we have for this contact.
70 * @param string $context
71 * @param null $activityTypeIDs
73 * @return \CRM_Activity_Selector_Activity
75 public function __construct(
79 $context = 'activity',
80 $activityTypeIDs = NULL) {
81 $this->_contactId
= $contactId;
82 $this->_permission
= $permission;
83 $this->_admin
= $admin;
84 $this->_context
= $context;
85 $this->_activityTypeIDs
= $activityTypeIDs;
87 // get all enabled view componentc (check if case is enabled)
88 $this->_viewOptions
= CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
89 'contact_view_options', TRUE, NULL, TRUE
94 * This method returns the action links that are given for each search row.
95 * currently the action links added for each row are
99 * @param int $activityTypeId
100 * @param int $sourceRecordId
101 * @param bool $accessMailingReport
102 * @param int $activityId
104 * @param null $compContext
108 public static function actionLinks(
110 $sourceRecordId = NULL,
111 $accessMailingReport = FALSE,
114 $compContext = NULL) {
116 //CRM-14277 added additional param to handle activity search
117 $extraParams = "&searchContext=activity";
119 $extraParams .= ($key) ?
"&key={$key}" : NULL;
121 $extraParams .= "&compContext={$compContext}";
125 $showUpdate = $showDelete = FALSE;
130 $activityTypeName = CRM_Core_PseudoConstant
::getName('CRM_Activity_BAO_Activity', 'activity_type_id', $activityTypeId);
133 // Lets allow to have normal operation for only activity types.
134 // When activity type is disabled or no more exists give only delete.
135 switch ($activityTypeName) {
136 case 'Event Registration':
137 case 'Change Registration':
138 $url = 'civicrm/contact/view/participant';
139 $qsView = "action=view&reset=1&id={$sourceRecordId}&cid=%%cid%%&context=%%cxt%%{$extraParams}";
143 $url = 'civicrm/contact/view/contribution';
144 $qsView = "action=view&reset=1&id={$sourceRecordId}&cid=%%cid%%&context=%%cxt%%{$extraParams}";
149 $participantId = CRM_Core_DAO
::getFieldValue('CRM_Event_BAO_ParticipantPayment', $sourceRecordId, 'participant_id', 'contribution_id');
150 if (!empty($participantId)) {
151 $url = 'civicrm/contact/view/participant';
152 $qsView = "action=view&reset=1&id={$participantId}&cid=%%cid%%&context=%%cxt%%{$extraParams}";
156 case 'Membership Signup':
157 case 'Membership Renewal':
158 case 'Change Membership Status':
159 case 'Change Membership Type':
160 $url = 'civicrm/contact/view/membership';
161 $qsView = "action=view&reset=1&id={$sourceRecordId}&cid=%%cid%%&context=%%cxt%%{$extraParams}";
164 case 'Pledge Reminder':
165 case 'Pledge Acknowledgment':
166 $url = 'civicrm/contact/view/activity';
167 $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
172 $url = 'civicrm/activity/view';
173 $delUrl = 'civicrm/activity';
174 $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
175 if ($activityTypeName == 'Email') {
180 case 'Inbound Email':
181 $url = 'civicrm/contact/view/activity';
182 $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
184 if (CRM_Core_Permission
::check('edit inbound email basic information')
185 || CRM_Core_Permission
::check('edit inbound email basic information and content')
187 $showDelete = $showUpdate = TRUE;
188 $qsUpdate = "atype={$activityTypeId}&action=update&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
193 case 'Change Case Type':
194 case 'Change Case Status':
195 case 'Change Case Start Date':
196 $showUpdate = $showDelete = FALSE;
197 $url = 'civicrm/activity';
198 $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
199 $qsUpdate = "atype={$activityTypeId}&action=update&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
203 $url = 'civicrm/activity';
204 $showView = $showDelete = $showUpdate = TRUE;
205 $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
206 $qsUpdate = "atype={$activityTypeId}&action=update&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
208 // When type is not available lets hide view and update.
209 if (empty($activityTypeName)) {
210 $showView = $showUpdate = FALSE;
215 $qsDelete = "atype={$activityTypeId}&action=delete&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
217 $actionLinks = array();
220 $actionLinks +
= array(
223 'name' => ts('View'),
226 'title' => ts('View Activity'),
232 $updateUrl = 'civicrm/activity/add';
233 if ($activityTypeName == 'Email') {
234 $updateUrl = 'civicrm/activity/email/add';
236 elseif ($activityTypeName == 'Print PDF Letter') {
237 $updateUrl = 'civicrm/activity/pdf/add';
239 if (CRM_Activity_BAO_Activity
::checkPermission($activityId, CRM_Core_Action
::UPDATE
)) {
240 $actionLinks +
= array(
243 'name' => ts('Edit'),
246 'title' => ts('Update Activity'),
254 CRM_Case_BAO_Case
::checkPermission($activityId, 'File On Case', $activityTypeId)
256 $actionLinks +
= array(
259 'name' => ts('File on Case'),
261 'extra' => 'onclick="javascript:fileOnCase( \'file\', \'%%id%%\', null, this ); return false;"',
262 'title' => ts('File on Case'),
268 if (!isset($delUrl) ||
!$delUrl) {
271 $actionLinks +
= array(
274 'name' => ts('Delete'),
277 'title' => ts('Delete Activity'),
282 if ($accessMailingReport) {
283 $actionLinks +
= array(
286 'name' => ts('Mailing Report'),
287 'url' => 'civicrm/mailing/report',
288 'qs' => "mid={$sourceRecordId}&reset=1&cid=%%cid%%&context=activitySelector",
289 'title' => ts('View Mailing Report'),
298 * Getter for array of the parameters required for creating pager.
301 * @param array $params
303 public function getPagerParams($action, &$params) {
304 $params['status'] = ts('Activities %%StatusMessage%%');
305 $params['csvString'] = NULL;
306 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
308 $params['buttonTop'] = 'PagerTopButton';
309 $params['buttonBottom'] = 'PagerBottomButton';
313 * Returns the column headers as an array of tuples:
314 * (name, sortName (key to the sort array))
316 * @param string $action
317 * The action being performed.
318 * @param string $output
319 * What should the result set include (web/email/csv).
322 * the column headers that need to be displayed
324 public function &getColumnHeaders($action = NULL, $output = NULL) {
325 if ($output == CRM_Core_Selector_Controller
::EXPORT ||
$output == CRM_Core_Selector_Controller
::SCREEN
) {
326 $csvHeaders = array(ts('Activity Type'), ts('Description'), ts('Activity Date'));
327 foreach (self
::_getColumnHeaders() as $column) {
328 if (array_key_exists('name', $column)) {
329 $csvHeaders[] = $column['name'];
335 return self
::_getColumnHeaders();
340 * Returns total number of rows for the query.
342 * @param string $action
343 * Action being performed.
348 * Total number of rows
350 public function getTotalCount($action, $case = NULL) {
352 'contact_id' => $this->_contactId
,
353 'admin' => $this->_admin
,
355 'context' => $this->_context
,
356 'activity_type_id' => $this->_activityTypeIDs
,
361 return CRM_Activity_BAO_Activity
::deprecatedGetActivitiesCount($params);
365 * Returns all the rows in the given offset and rowCount.
367 * @param string $action
368 * The action being performed.
370 * The row number to start from.
371 * @param int $rowCount
372 * The number of rows to return.
373 * @param string $sort
374 * The sql string that describes the sort order.
375 * @param string $output
376 * What should the result set include (web/email/csv).
381 * the total number of rows for this action
383 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL, $case = NULL) {
385 'contact_id' => $this->_contactId
,
386 'admin' => $this->_admin
,
388 'context' => $this->_context
,
389 'activity_type_id' => $this->_activityTypeIDs
,
391 'rowCount' => $rowCount,
394 $config = CRM_Core_Config
::singleton();
395 $rows = CRM_Activity_BAO_Activity
::deprecatedGetActivities($params);
401 $activityStatus = CRM_Core_PseudoConstant
::activityStatus();
403 $engagementLevels = CRM_Campaign_PseudoConstant
::engagementLevel();
406 $permissions = array($this->_permission
);
407 if (CRM_Core_Permission
::check('delete activities')) {
408 $permissions[] = CRM_Core_Permission
::DELETE
;
410 $mask = CRM_Core_Action
::mask($permissions);
412 foreach ($rows as $k => $row) {
415 // DRAFTING: provide a facility for db-stored strings
416 // localize the built-in activity names for display
417 // (these are not enums, so we can't use any automagic here)
418 switch ($row['activity_type']) {
420 $row['activity_type'] = ts('Meeting');
424 $row['activity_type'] = ts('Phone Call');
428 $row['activity_type'] = ts('Email');
432 $row['activity_type'] = ts('SMS');
436 $row['activity_type'] = ts('Event');
440 // add class to this row if overdue
441 if (CRM_Utils_Date
::overdue(CRM_Utils_Array
::value('activity_date_time', $row))
442 && CRM_Utils_Array
::value('status_id', $row) == 1
445 $row['class'] = 'status-overdue';
449 $row['class'] = 'status-ontime';
452 $row['status'] = $row['status_id'] ?
$activityStatus[$row['status_id']] : NULL;
454 if ($engagementLevel = CRM_Utils_Array
::value('engagement_level', $row)) {
455 $row['engagement_level'] = CRM_Utils_Array
::value($engagementLevel, $engagementLevels, $engagementLevel);
459 $accessMailingReport = FALSE;
460 if (!empty($row['mailingId'])) {
461 $accessMailingReport = TRUE;
464 $actionLinks = $this->actionLinks(CRM_Utils_Array
::value('activity_type_id', $row),
465 CRM_Utils_Array
::value('source_record_id', $row),
466 $accessMailingReport,
467 CRM_Utils_Array
::value('activity_id', $row),
471 $actionMask = array_sum(array_keys($actionLinks)) & $mask;
473 if ($output != CRM_Core_Selector_Controller
::EXPORT
&& $output != CRM_Core_Selector_Controller
::SCREEN
) {
474 $row['action'] = CRM_Core_Action
::formLink($actionLinks,
477 'id' => $row['activity_id'],
478 'cid' => $this->_contactId
,
479 'cxt' => $this->_context
,
480 'caseid' => CRM_Utils_Array
::value('case_id', $row),
484 'activity.selector.action',
497 * Name of export file.
499 * @param string $output
505 public function getExportFileName($output = 'csv') {
506 return ts('CiviCRM Activity');
510 * Get colunmn headers for search selector.
515 private static function &_getColumnHeaders() {
516 if (!isset(self
::$_columnHeaders)) {
517 self
::$_columnHeaders = array(
519 'name' => ts('Type'),
520 'sort' => 'activity_type',
521 'direction' => CRM_Utils_Sort
::DONTCARE
,
524 'name' => ts('Subject'),
526 'direction' => CRM_Utils_Sort
::DONTCARE
,
529 'name' => ts('Added By'),
530 'sort' => 'source_contact_name',
531 'direction' => CRM_Utils_Sort
::DONTCARE
,
533 array('name' => ts('With')),
534 array('name' => ts('Assigned')),
536 'name' => ts('Date'),
537 'sort' => 'activity_date_time',
538 'direction' => CRM_Utils_Sort
::DONTCARE
,
541 'name' => ts('Status'),
542 'sort' => 'status_id',
543 'direction' => CRM_Utils_Sort
::DONTCARE
,
545 array('desc' => ts('Actions')),
549 return self
::$_columnHeaders;