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 7, 2017
1 parent d51efd5 commit a4f50cc
Show file tree
Hide file tree
Showing 29 changed files with 527 additions and 753 deletions.
4 changes: 1 addition & 3 deletions CRM/Activity/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ public function buildQuickForm() {
$this->addRowSelectors($rows);
}

$permission = CRM_Core_Permission::getPermission();

$this->addTaskMenu(CRM_Activity_Task::permissionedTaskTitles($permission));
$this->addTaskMenu(CRM_Activity_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission()));
}

}
Expand Down
73 changes: 20 additions & 53 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,44 +121,31 @@ 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.
*
* @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) {
$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'];
}
}

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

Expand All @@ -195,8 +161,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
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
52 changes: 11 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,35 +84,20 @@ 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
*
* @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 +113,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
8 changes: 3 additions & 5 deletions CRM/Case/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,13 @@ public function buildQuickForm() {
$this->addRowSelectors($rows);
}

$permission = CRM_Core_Permission::getPermission();

$tasks = CRM_Case_Task::permissionedTaskTitles($permission);
$tasks = CRM_Case_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission());

if (!empty($this->_formValues['case_deleted'])) {
unset($tasks[1]);
unset($tasks[CRM_Case_Task::DELETE_CASES]);
}
else {
unset($tasks[4]);
unset($tasks[CRM_Case_Task::RESTORE_CASES]);
}

$this->addTaskMenu($tasks);
Expand Down
Loading

0 comments on commit a4f50cc

Please sign in to comment.