Skip to content

Commit

Permalink
Convert Event to use core Task class
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwire committed Jan 19, 2018
1 parent 3137a6a commit 8fd2683
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 90 deletions.
8 changes: 2 additions & 6 deletions CRM/Event/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,10 @@ public function buildQuickForm() {
$this->assign('participantCount', $participantCount);
$this->assign('lineItems', $lineItems);

$permission = CRM_Core_Permission::getPermission();
$taskParams['ssID'] = isset($this->_ssID) ? $this->_ssID : NULL;
$tasks = CRM_Event_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission(), $taskParams);

$tasks = CRM_Event_Task::permissionedTaskTitles($permission);
if (isset($this->_ssID)) {
if ($permission == CRM_Core_Permission::EDIT) {
$tasks = $tasks + CRM_Event_Task::optionalTaskTitle();
}

$savedSearchValues = array(
'id' => $this->_ssID,
'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title'),
Expand Down
7 changes: 5 additions & 2 deletions CRM/Event/Form/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,11 @@ public static function preProcessCommon(&$form, $useTable = FALSE) {
$values = $form->controller->exportValues($form->get('searchFormName'));

$form->_task = $values['task'];
$eventTasks = CRM_Event_Task::tasks();
$form->assign('taskName', $eventTasks[$form->_task]);
$tasks = CRM_Event_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission());
if (!array_key_exists($form->_task, $tasks)) {
CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.'));
}
$form->assign('taskName', $tasks[$form->_task]);

$ids = array();
if ($values['radio_ts'] == 'ts_sel') {
Expand Down
119 changes: 37 additions & 82 deletions CRM/Event/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/

Expand All @@ -38,102 +36,93 @@
* used by the search forms
*
*/
class CRM_Event_Task {
// Value for SAVE_SEARCH is set to 13 in accordance with CRM_Contact_Task::SAVE_SEARCH
const DELETE_EVENTS = 1, PRINT_EVENTS = 2, EXPORT_EVENTS = 3, BATCH_EVENTS = 4, CANCEL_REGISTRATION = 5, EMAIL_CONTACTS = 6,
// Value for LABEL_CONTACTS is set to 16 in accordance with CRM_Contact_Task::LABEL_CONTACTS
SAVE_SEARCH = 13, SAVE_SEARCH_UPDATE = 14, PARTICIPANT_STATUS = 15,
LABEL_CONTACTS = 16, GROUP_CONTACTS = 20;
class CRM_Event_Task extends CRM_Core_Task {

/**
* The task array
*
* @var array
*/
static $_tasks = NULL;
const
// Event tasks
CANCEL_REGISTRATION = 301,
PARTICIPANT_STATUS = 302;

/**
* The optional task array
*
* @var array
*/
static $_optionalTasks = NULL;
static $objectType = 'event';

/**
* These tasks are the core set of tasks that the user can perform
* on a contact / group of contacts
*
* @return array
* the set of tasks for a group of contacts
* @return array The set of tasks for a group of contacts
* [ 'title' => The Task title,
* 'class' => The Task Form class name,
* 'result => Boolean. FIXME: Not sure what this is for
* ]
*/
public static function &tasks() {
if (!(self::$_tasks)) {
public static function tasks() {
if (!self::$_tasks) {
self::$_tasks = array(
1 => array(
self::TASK_DELETE => array(
'title' => ts('Delete participants from event'),
'class' => 'CRM_Event_Form_Task_Delete',
'result' => FALSE,
),
2 => array(
self::TASK_PRINT => array(
'title' => ts('Print selected rows'),
'class' => 'CRM_Event_Form_Task_Print',
'result' => FALSE,
),
3 => array(
self::TASK_EXPORT => array(
'title' => ts('Export participants'),
'class' => array(
'CRM_Export_Form_Select',
'CRM_Export_Form_Map',
),
'result' => FALSE,
),
4 => array(
self::BATCH_UPDATE => array(
'title' => ts('Update multiple participants'),
'class' => array(
'CRM_Event_Form_Task_PickProfile',
'CRM_Event_Form_Task_Batch',
),
'result' => TRUE,
),
5 => array(
self::CANCEL_REGISTRATION => array(
'title' => ts('Cancel registration'),
'class' => 'CRM_Event_Form_Task_Cancel',
'result' => FALSE,
),
6 => array(
self::TASK_EMAIL => array(
'title' => ts('Email - send now (to %1 or less)', array(
1 => Civi::settings()
->get('simple_mail_limit'),
)),
'class' => 'CRM_Event_Form_Task_Email',
'result' => TRUE,
),
13 => array(
self::SAVE_SEARCH => array(
'title' => ts('Group - create smart group'),
'class' => 'CRM_Event_Form_Task_SaveSearch',
'result' => TRUE,
),
14 => array(
self::SAVE_SEARCH_UPDATE => array(
'title' => ts('Group - update smart group'),
'class' => 'CRM_Event_Form_Task_SaveSearch_Update',
'result' => TRUE,
),
15 => array(
self::PARTICIPANT_STATUS => array(
'title' => ts('Participant status - change'),
'class' => 'CRM_Event_Form_Task_ParticipantStatus',
'result' => TRUE,
),
16 => array(
self::LABEL_CONTACTS => array(
'title' => ts('Name badges - print'),
'class' => 'CRM_Event_Form_Task_Badge',
'result' => FALSE,
),
17 => array(
self::TASK_PRINT => array(
'title' => ts('PDF letter - print for participants'),
'class' => 'CRM_Event_Form_Task_PDF',
'result' => TRUE,
),
20 => array(
self::GROUP_ADD => array(
'title' => ts('Group - add contacts'),
'class' => 'CRM_Event_Form_Task_AddToGroup',
'result' => FALSE,
Expand All @@ -142,78 +131,48 @@ public static function &tasks() {

//CRM-4418, check for delete
if (!CRM_Core_Permission::check('delete in CiviEvent')) {
unset(self::$_tasks[1]);
unset(self::$_tasks[self::TASK_DELETE]);
}
//CRM-12920 - check for edit permission
if (!CRM_Core_Permission::check('edit event participants')) {
unset(self::$_tasks[4], self::$_tasks[5], self::$_tasks[15]);
unset(self::$_tasks[self::BATCH_UPDATE], self::$_tasks[self::CANCEL_REGISTRATION], self::$_tasks[self::PARTICIPANT_STATUS]);
}

CRM_Utils_Hook::searchTasks('event', self::$_tasks);
parent::tasks();
}

return self::$_tasks;
}

/**
* These tasks are the core set of task titles
* for participants
*
* @return array
* the set of task titles
*/
public static function &taskTitles() {
self::tasks();
$titles = array();
foreach (self::$_tasks as $id => $value) {
// skip Update Smart Group task
if ($id != self::SAVE_SEARCH_UPDATE) {
$titles[$id] = $value['title'];
}
}
return $titles;
}

/**
* These tasks get added based on the context the user is in.
*
* @return array
* the set of optional tasks for a group of contacts
*/
public static function &optionalTaskTitle() {
$tasks = array(
14 => self::$_tasks[14]['title'],
);
return $tasks;
}

/**
* Show tasks selectively based on the permission level
* of the user
*
* @param int $permission
* @param array $params
*
* @return array
* set of tasks that are valid for the user
*/
public static function &permissionedTaskTitles($permission) {
$tasks = array();
public static function permissionedTaskTitles($permission, $params = array()) {
if (($permission == CRM_Core_Permission::EDIT)
|| CRM_Core_Permission::check('edit event participants')
) {
$tasks = self::taskTitles();
}
else {
$tasks = array(
3 => self::$_tasks[3]['title'],
6 => self::$_tasks[6]['title'],
self::TASK_EXPORT => self::$_tasks[self::TASK_EXPORT]['title'],
self::TASK_EMAIL => self::$_tasks[self::TASK_EMAIL]['title'],
);

//CRM-4418,
if (CRM_Core_Permission::check('delete in CiviEvent')) {
$tasks[1] = self::$_tasks[1]['title'];
$tasks[self::TASK_DELETE] = self::$_tasks[self::TASK_DELETE]['title'];
}
}

$tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
return $tasks;
}

Expand All @@ -230,13 +189,9 @@ public static function getTask($value) {
self::tasks();
if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
// make the print task by default
$value = 2;
$value = self::TASK_PRINT;
}
asort(self::$_tasks);
return array(
self::$_tasks[$value]['class'],
self::$_tasks[$value]['result'],
);
return parent::getTask($value);
}

}

0 comments on commit 8fd2683

Please sign in to comment.