Skip to content

Commit

Permalink
Merge pull request #11758 from mattwire/CRM-21391_campaign_task
Browse files Browse the repository at this point in the history
CRM-21391 Convert Campaign to use core Task class
  • Loading branch information
eileenmcnaughton authored Mar 5, 2018
2 parents 9cfddaf + 5da76db commit 3395b87
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 43 deletions.
3 changes: 1 addition & 2 deletions CRM/Campaign/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ public function buildQuickForm() {
$this->addRowSelectors($rows);
}

$permission = CRM_Core_Permission::getPermission();
$allTasks = CRM_Campaign_Task::permissionedTaskTitles($permission);
$allTasks = CRM_Campaign_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission());

//hack to serve right page to state machine.
$taskMapping = array(
Expand Down
59 changes: 18 additions & 41 deletions CRM/Campaign/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,15 @@
*
* Used by the search forms.
*/
class CRM_Campaign_Task {
const INTERVIEW = 1, RESERVE = 2, RELEASE = 3, PRINT_VOTERS = 4;
class CRM_Campaign_Task extends CRM_Core_Task {

/**
* The task array
*
* @var array
*/
static $_tasks = NULL;
const
// Campaign tasks
INTERVIEW = 601,
RESERVE = 602,
RELEASE = 603;

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

/**
* These tasks are the core set of tasks that the user can perform
Expand All @@ -60,18 +53,18 @@ class CRM_Campaign_Task {
* @return array
* the set of tasks for a group of voters.
*/
public static function &tasks() {
public static function tasks() {
if (!(self::$_tasks)) {
self::$_tasks = array(
1 => array(
self::INTERVIEW => array(
'title' => ts('Record Respondents Interview'),
'class' => array(
'CRM_Campaign_Form_Task_Interview',
'CRM_Campaign_Form_Task_Release',
),
'result' => FALSE,
),
2 => array(
self::RESERVE => array(
'title' => ts('Reserve Respondents'),
'class' => array(
'CRM_Campaign_Form_Task_Reserve',
Expand All @@ -80,54 +73,38 @@ public static function &tasks() {
),
'result' => FALSE,
),
3 => array(
self::RELEASE => array(
'title' => ts('Release Respondents'),
'class' => 'CRM_Campaign_Form_Task_Release',
'result' => FALSE,
),
4 => array(
self::TASK_PRINT => array(
'title' => ts('Print Respondents'),
'class' => 'CRM_Campaign_Form_Task_Print',
'result' => FALSE,
),
);

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

return self::$_tasks;
}

/**
* These tasks are the core set of task titles
* on voters.
*
* @return array
* the set of task titles
*/
public static function &taskTitles() {
self::tasks();
$titles = array();
foreach (self::$_tasks as $id => $value) {
$titles[$id] = $value['title'];
}

return $titles;
}

/**
* 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) {
public static function permissionedTaskTitles($permission, $params = array()) {
$tasks = self::taskTitles();

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

Expand All @@ -143,8 +120,8 @@ public static function &permissionedTaskTitles($permission) {
public static function getTask($value) {
self::tasks();
if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
// make the interview task by default
$value = 1;
// Set the interview task as default
$value = self::INTERVIEW;
}

return array(
Expand Down

0 comments on commit 3395b87

Please sign in to comment.