Skip to content

Commit

Permalink
Refactor form search to use a base class, resolve issues with action …
Browse files Browse the repository at this point in the history
…list when changing the entity filter
  • Loading branch information
mattwire committed Nov 3, 2017
1 parent 2e31bc8 commit 1b46bb0
Show file tree
Hide file tree
Showing 19 changed files with 440 additions and 628 deletions.
69 changes: 17 additions & 52 deletions CRM/Activity/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,7 @@
/**
* Class to represent the actions that can be performed on a group of contacts used by the search forms.
*/
class CRM_Activity_Task {
const
DELETE_ACTIVITIES = 1,
PRINT_ACTIVITIES = 2,
EXPORT_ACTIVITIES = 3,
BATCH_ACTIVITIES = 4,
EMAIL_CONTACTS = 5,
EMAIL_SMS = 6;

/**
* The task array.
*
* @var array
*/
static $_tasks = NULL;

/**
* The optional task array.
*
* @var array
*/
static $_optionalTasks = NULL;
class CRM_Activity_Task extends CRM_Core_Task {

/**
* These tasks are the core set of tasks that the user can perform
Expand All @@ -63,54 +42,54 @@ class CRM_Activity_Task {
* @return array
* the set of tasks for a group of contacts
*/
public static function &tasks() {
public static function tasks() {
if (!(self::$_tasks)) {
self::$_tasks = array(
1 => array(
self::DELETE_ACTIVITIES => array(
'title' => ts('Delete activities'),
'class' => 'CRM_Activity_Form_Task_Delete',
'result' => FALSE,
),
2 => array(
self::PRINT_ACTIVITIES => array(
'title' => ts('Print selected rows'),
'class' => 'CRM_Activity_Form_Task_Print',
'result' => FALSE,
),
3 => array(
self::EXPORT_ACTIVITIES => array(
'title' => ts('Export activities'),
'class' => array(
'CRM_Export_Form_Select',
'CRM_Export_Form_Map',
),
'result' => FALSE,
),
4 => array(
self::BATCH_ACTIVITIES => array(
'title' => ts('Update multiple activities'),
'class' => array(
'CRM_Activity_Form_Task_PickProfile',
'CRM_Activity_Form_Task_Batch',
),
'result' => FALSE,
),
5 => array(
self::EMAIL_CONTACTS => array(
'title' => ts('Email - send now'),
'class' => array(
'CRM_Activity_Form_Task_PickOption',
'CRM_Activity_Form_Task_Email',
),
'result' => FALSE,
),
6 => array(
self::EMAIL_SMS => array(
'title' => ts('SMS - send reply'),
'class' => 'CRM_Activity_Form_Task_SMS',
'result' => FALSE,
),
7 => array(
self::TAG_ACTIVITIES => array(
'title' => ts('Tag - add to activities'),
'class' => 'CRM_Activity_Form_Task_AddToTag',
'result' => FALSE,
),
8 => array(
self::UNTAG_ACTIVITIES => array(
'title' => ts('Tag - remove from activities'),
'class' => 'CRM_Activity_Form_Task_RemoveFromTag',
'result' => FALSE,
Expand All @@ -122,7 +101,7 @@ public static function &tasks() {
if (CRM_Core_Permission::check('access all cases and activities') ||
CRM_Core_Permission::check('access my cases and activities')
) {
self::$_tasks[6] = array(
self::$_tasks[self::EMAIL_SMS] = array(
'title' => ts('File on case'),
'class' => 'CRM_Activity_Form_Task_FileOnCase',
'result' => FALSE,
Expand All @@ -132,7 +111,7 @@ public static function &tasks() {

// CRM-4418, check for delete
if (!CRM_Core_Permission::check('delete activities')) {
unset(self::$_tasks[1]);
unset(self::$_tasks[self::DELETE_ACTIVITIES]);
}

CRM_Utils_Hook::searchTasks('activity', self::$_tasks);
Expand All @@ -142,21 +121,6 @@ public static function &tasks() {
return self::$_tasks;
}

/**
* These tasks are the core set of task titles on activity.
*
* @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.
*
Expand All @@ -165,19 +129,19 @@ public static function &taskTitles() {
* @return array
* set of tasks that are valid for the user
*/
public static function &permissionedTaskTitles($permission) {
public static function permissionedTaskTitles($permission, $deleteContacts = FALSE) {
$tasks = array();
if ($permission == CRM_Core_Permission::EDIT) {
$tasks = self::taskTitles();
}
else {
$tasks = array(
3 => self::$_tasks[3]['title'],
self::EXPORT_ACTIVITIES => self::$_tasks[self::EXPORT_ACTIVITIES]['title'],
);

//CRM-4418,
if (CRM_Core_Permission::check('delete activities')) {
$tasks[1] = self::$_tasks[1]['title'];
$tasks[self::DELETE_ACTIVITIES] = self::$_tasks[self::DELETE_ACTIVITIES]['title'];
}
}
return $tasks;
Expand All @@ -195,8 +159,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::PRINT_ACTIVITIES;
}

return array(
self::$_tasks[$value]['class'],
self::$_tasks[$value]['result'],
Expand Down
50 changes: 9 additions & 41 deletions CRM/Campaign/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,7 @@
*
* Used by the search forms.
*/
class CRM_Campaign_Task {
const INTERVIEW = 1, RESERVE = 2, RELEASE = 3, PRINT_VOTERS = 4;

/**
* The task array
*
* @var array
*/
static $_tasks = NULL;

/**
* The optional task array
*
* @var array
*/
static $_optionalTasks = NULL;
class CRM_Campaign_Task extends CRM_Core_Task {

/**
* These tasks are the core set of tasks that the user can perform
Expand All @@ -60,18 +45,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,12 +65,12 @@ 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::PRINT_VOTERS => array(
'title' => ts('Print Respondents'),
'class' => 'CRM_Campaign_Form_Task_Print',
'result' => FALSE,
Expand All @@ -99,23 +84,6 @@ public static function &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
Expand All @@ -125,7 +93,7 @@ public static function &taskTitles() {
* @return array
* set of tasks that are valid for the user
*/
public static function &permissionedTaskTitles($permission) {
public static function permissionedTaskTitles($permission, $deleteContacts = FALSE) {
$tasks = self::taskTitles();

return $tasks;
Expand All @@ -143,8 +111,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;
// make the print task by default
$value = self::INTERVIEW;
}

return array(
Expand Down
Loading

0 comments on commit 1b46bb0

Please sign in to comment.