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
47 static $_columnHeaders;
50 * ContactId - contact id of contact whose activies are displayed
54 protected $_contactId;
60 protected $_activityTypeIDs;
62 protected $_viewOptions;
67 * @param int $contactId
68 * Contact whose activities we want to display.
69 * @param int $permission
70 * The permission we have for this contact.
73 * @param string $context
74 * @param null $activityTypeIDs
76 * @return \CRM_Activity_Selector_Activity
78 public function __construct(
82 $context = 'activity',
83 $activityTypeIDs = NULL) {
84 $this->_contactId
= $contactId;
85 $this->_permission
= $permission;
86 $this->_admin
= $admin;
87 $this->_context
= $context;
88 $this->_activityTypeIDs
= $activityTypeIDs;
90 // get all enabled view componentc (check if case is enabled)
91 $this->_viewOptions
= CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
92 'contact_view_options', TRUE, NULL, TRUE
97 * This method returns the action links that are given for each search row.
98 * currently the action links added for each row are
102 * @param int $activityTypeId
103 * @param int $sourceRecordId
104 * @param bool $accessMailingReport
105 * @param int $activityId
107 * @param null $compContext
111 public static function actionLinks(
113 $sourceRecordId = NULL,
114 $accessMailingReport = FALSE,
117 $compContext = NULL) {
118 static $activityActTypes = NULL;
119 //CRM-14277 added addtitional param to handle activity search
120 $extraParams = "&searchContext=activity";
122 $extraParams .= ($key) ?
"&key={$key}" : NULL;
124 $extraParams .= "&compContext={$compContext}";
128 $showUpdate = $showDelete = FALSE;
131 if (!$activityActTypes) {
132 $activeActTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, FALSE, 'name', TRUE);
134 $activityTypeName = CRM_Utils_Array
::value($activityTypeId, $activeActTypes);
137 //lets allow to have normal operation for only activity types.
138 //when activity type is disabled or no more exists give only delete.
139 switch ($activityTypeName) {
140 case 'Event Registration':
141 case 'Change Registration':
142 $url = 'civicrm/contact/view/participant';
143 $qsView = "action=view&reset=1&id={$sourceRecordId}&cid=%%cid%%&context=%%cxt%%{$extraParams}";
147 $url = 'civicrm/contact/view/contribution';
148 $qsView = "action=view&reset=1&id={$sourceRecordId}&cid=%%cid%%&context=%%cxt%%{$extraParams}";
153 $participantId = CRM_Core_DAO
::getFieldValue('CRM_Event_BAO_ParticipantPayment', $sourceRecordId, 'participant_id', 'contribution_id');
154 if (!empty($participantId)) {
155 $url = 'civicrm/contact/view/participant';
156 $qsView = "action=view&reset=1&id={$participantId}&cid=%%cid%%&context=%%cxt%%{$extraParams}";
160 case 'Membership Signup':
161 case 'Membership Renewal':
162 case 'Change Membership Status':
163 case 'Change Membership Type':
164 $url = 'civicrm/contact/view/membership';
165 $qsView = "action=view&reset=1&id={$sourceRecordId}&cid=%%cid%%&context=%%cxt%%{$extraParams}";
168 case 'Pledge Reminder':
169 case 'Pledge Acknowledgment':
170 $url = 'civicrm/contact/view/activity';
171 $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
176 $url = 'civicrm/activity/view';
177 $delUrl = 'civicrm/activity';
178 $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
179 if ($activityTypeName == 'Email') {
184 case 'Inbound Email':
185 $url = 'civicrm/contact/view/activity';
186 $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
190 case 'Change Case Type':
191 case 'Change Case Status':
192 case 'Change Case Start Date':
193 $showUpdate = $showDelete = FALSE;
194 $url = 'civicrm/activity';
195 $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
196 $qsUpdate = "atype={$activityTypeId}&action=update&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
200 $url = 'civicrm/activity';
201 $showView = $showDelete = $showUpdate = TRUE;
202 $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
203 $qsUpdate = "atype={$activityTypeId}&action=update&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
205 //when type is not available lets hide view and update.
206 if (empty($activityTypeName)) {
207 $showView = $showUpdate = FALSE;
212 $qsDelete = "atype={$activityTypeId}&action=delete&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}";
214 $actionLinks = array();
217 $actionLinks +
= array(
220 'name' => ts('View'),
223 '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(
240 'name' => ts('Edit'),
243 'title' => ts('Update Activity'),
251 CRM_Case_BAO_Case
::checkPermission($activityId, 'File On Case', $activityTypeId)
253 $actionLinks +
= array(
256 'name' => ts('File on Case'),
258 'extra' => 'onclick="javascript:fileOnCase( \'file\', \'%%id%%\', null, this ); return false;"',
259 'title' => ts('File on Case'),
265 if (!isset($delUrl) ||
!$delUrl) {
268 $actionLinks +
= array(
271 'name' => ts('Delete'),
274 'title' => ts('Delete Activity'),
279 if ($accessMailingReport) {
280 $actionLinks +
= array(
283 'name' => ts('Mailing Report'),
284 'url' => 'civicrm/mailing/report',
285 'qs' => "mid={$sourceRecordId}&reset=1&cid=%%cid%%&context=activitySelector",
286 'title' => ts('View Mailing Report'),
295 * Getter for array of the parameters required for creating pager.
298 * @param array $params
300 public function getPagerParams($action, &$params) {
301 $params['status'] = ts('Activities %%StatusMessage%%');
302 $params['csvString'] = NULL;
303 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
305 $params['buttonTop'] = 'PagerTopButton';
306 $params['buttonBottom'] = 'PagerBottomButton';
310 * Returns the column headers as an array of tuples:
311 * (name, sortName (key to the sort array))
313 * @param string $action
314 * The action being performed.
315 * @param string $output
316 * What should the result set include (web/email/csv).
319 * the column headers that need to be displayed
321 public function &getColumnHeaders($action = NULL, $output = NULL) {
322 if ($output == CRM_Core_Selector_Controller
::EXPORT ||
$output == CRM_Core_Selector_Controller
::SCREEN
) {
323 $csvHeaders = array(ts('Activity Type'), ts('Description'), ts('Activity Date'));
324 foreach (self
::_getColumnHeaders() as $column) {
325 if (array_key_exists('name', $column)) {
326 $csvHeaders[] = $column['name'];
332 return self
::_getColumnHeaders();
337 * Returns total number of rows for the query.
339 * @param string $action
340 * Action being performed.
345 * Total number of rows
347 public function getTotalCount($action, $case = NULL) {
349 'contact_id' => $this->_contactId
,
350 'admin' => $this->_admin
,
352 'context' => $this->_context
,
353 'activity_type_id' => $this->_activityTypeIDs
,
358 return CRM_Activity_BAO_Activity
::getActivitiesCount($params);
362 * Returns all the rows in the given offset and rowCount.
364 * @param string $action
365 * The action being performed.
367 * The row number to start from.
368 * @param int $rowCount
369 * The number of rows to return.
370 * @param string $sort
371 * The sql string that describes the sort order.
372 * @param string $output
373 * What should the result set include (web/email/csv).
378 * the total number of rows for this action
380 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL, $case = NULL) {
382 'contact_id' => $this->_contactId
,
383 'admin' => $this->_admin
,
385 'context' => $this->_context
,
386 'activity_type_id' => $this->_activityTypeIDs
,
388 'rowCount' => $rowCount,
391 $config = CRM_Core_Config
::singleton();
392 $rows = CRM_Activity_BAO_Activity
::getActivities($params);
398 $activityStatus = CRM_Core_PseudoConstant
::activityStatus();
400 $engagementLevels = CRM_Campaign_PseudoConstant
::engagementLevel();
403 $permissions = array($this->_permission
);
404 if (CRM_Core_Permission
::check('delete activities')) {
405 $permissions[] = CRM_Core_Permission
::DELETE
;
407 $mask = CRM_Core_Action
::mask($permissions);
409 foreach ($rows as $k => $row) {
412 // DRAFTING: provide a facility for db-stored strings
413 // localize the built-in activity names for display
414 // (these are not enums, so we can't use any automagic here)
415 switch ($row['activity_type']) {
417 $row['activity_type'] = ts('Meeting');
421 $row['activity_type'] = ts('Phone Call');
425 $row['activity_type'] = ts('Email');
429 $row['activity_type'] = ts('SMS');
433 $row['activity_type'] = ts('Event');
437 // add class to this row if overdue
438 if (CRM_Utils_Date
::overdue(CRM_Utils_Array
::value('activity_date_time', $row))
439 && CRM_Utils_Array
::value('status_id', $row) == 1
442 $row['class'] = 'status-overdue';
446 $row['class'] = 'status-ontime';
449 $row['status'] = $row['status_id'] ?
$activityStatus[$row['status_id']] : NULL;
451 if ($engagementLevel = CRM_Utils_Array
::value('engagement_level', $row)) {
452 $row['engagement_level'] = CRM_Utils_Array
::value($engagementLevel, $engagementLevels, $engagementLevel);
456 $accessMailingReport = FALSE;
457 if (!empty($row['mailingId'])) {
458 $accessMailingReport = TRUE;
461 $actionLinks = $this->actionLinks(CRM_Utils_Array
::value('activity_type_id', $row),
462 CRM_Utils_Array
::value('source_record_id', $row),
463 $accessMailingReport,
464 CRM_Utils_Array
::value('activity_id', $row),
468 $actionMask = array_sum(array_keys($actionLinks)) & $mask;
470 if ($output != CRM_Core_Selector_Controller
::EXPORT
&& $output != CRM_Core_Selector_Controller
::SCREEN
) {
471 $row['action'] = CRM_Core_Action
::formLink($actionLinks,
474 'id' => $row['activity_id'],
475 'cid' => $this->_contactId
,
476 'cxt' => $this->_context
,
477 'caseid' => CRM_Utils_Array
::value('case_id', $row),
481 'activity.selector.action',
494 * Name of export file.
496 * @param string $output
502 public function getExportFileName($output = 'csv') {
503 return ts('CiviCRM Activity');
507 * Get colunmn headers for search selector.
512 private static function &_getColumnHeaders() {
513 if (!isset(self
::$_columnHeaders)) {
514 self
::$_columnHeaders = array(
516 'name' => ts('Type'),
517 'sort' => 'activity_type',
518 'direction' => CRM_Utils_Sort
::DONTCARE
,
521 'name' => ts('Subject'),
523 'direction' => CRM_Utils_Sort
::DONTCARE
,
526 'name' => ts('Added By'),
527 'sort' => 'source_contact_name',
528 'direction' => CRM_Utils_Sort
::DONTCARE
,
530 array('name' => ts('With')),
531 array('name' => ts('Assigned')),
533 'name' => ts('Date'),
534 'sort' => 'activity_date_time',
535 'direction' => CRM_Utils_Sort
::DONTCARE
,
538 'name' => ts('Status'),
539 'sort' => 'status_id',
540 'direction' => CRM_Utils_Sort
::DONTCARE
,
542 array('desc' => ts('Actions')),
546 return self
::$_columnHeaders;