Merge pull request #15640 from eileenmcnaughton/pp_pay
[civicrm-core.git] / CRM / Case / Task.php
index f667c1ee9653d7494802ad7c4877eb3da8e6871d..5907da813d544964ae10c6b855a30d804f956ea9 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.7                                                |
+ | CiviCRM version 5                                                  |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2018                                |
+ | Copyright CiviCRM LLC (c) 2004-2019                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2018
+ * @copyright CiviCRM LLC (c) 2004-2019
  */
 
 /**
  *
  * Used by the search forms
  */
-class CRM_Case_Task {
-  const DELETE_CASES = 1, PRINT_CASES = 2, EXPORT_CASES = 3, RESTORE_CASES = 4;
+class CRM_Case_Task extends CRM_Core_Task {
 
   /**
-   * The task array
-   *
-   * @var array
+   * Case tasks
    */
-  static $_tasks = NULL;
+  const RESTORE_CASES = 501;
 
   /**
-   * The optional task array
-   *
-   * @var array
+   * @var string
    */
-  static $_optionalTasks = NULL;
+  public static $objectType = 'case';
 
   /**
    * These tasks are the core set of tasks that the user can perform
@@ -60,96 +55,69 @@ class CRM_Case_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::$_tasks = [
+        self::TASK_DELETE => [
           'title' => ts('Delete cases'),
           'class' => 'CRM_Case_Form_Task_Delete',
           'result' => FALSE,
-        ),
-        2 => array(
+        ],
+        self::TASK_PRINT => [
           'title' => ts('Print selected rows'),
           'class' => 'CRM_Case_Form_Task_Print',
           'result' => FALSE,
-        ),
-        3 => array(
+        ],
+        self::TASK_EXPORT => [
           'title' => ts('Export cases'),
-          'class' => array(
-            'CRM_Export_Form_Select',
+          'class' => [
+            'CRM_Export_Form_Select_Case',
             'CRM_Export_Form_Map',
-          ),
+          ],
           'result' => FALSE,
-        ),
-        4 => array(
+        ],
+        self::RESTORE_CASES => [
           'title' => ts('Restore cases'),
           'class' => 'CRM_Case_Form_Task_Restore',
           'result' => FALSE,
-        ),
-        5 => array(
-          'title' => ts('Print/merge Document'),
+        ],
+        self::PDF_LETTER => [
+          'title' => ts('Print/merge document'),
           'class' => 'CRM_Case_Form_Task_PDF',
           'result' => FALSE,
-        ),
-        6 => array(
+        ],
+        self::BATCH_UPDATE => [
           'title' => ts('Update multiple cases'),
-          'class' => array(
+          'class' => [
             'CRM_Case_Form_Task_PickProfile',
             'CRM_Case_Form_Task_Batch',
-          ),
+          ],
           'result' => FALSE,
-        ),
-      );
+        ],
+      ];
 
       //CRM-4418, check for delete
       if (!CRM_Core_Permission::check('delete in CiviCase')) {
-        unset(self::$_tasks[1]);
+        unset(self::$_tasks[self::TASK_DELETE]);
       }
 
-      CRM_Utils_Hook::searchTasks('case', self::$_tasks);
-      asort(self::$_tasks);
+      parent::tasks();
     }
 
     return self::$_tasks;
   }
 
-  /**
-   * These tasks are the core set of task titles.
-   *
-   * @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;
-  }
-
-  /**
-   * 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();
-    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 = []) {
     if (($permission == CRM_Core_Permission::EDIT)
       || CRM_Core_Permission::check('access all cases and activities')
       || CRM_Core_Permission::check('access my cases and activities')
@@ -157,14 +125,16 @@ class CRM_Case_Task {
       $tasks = self::taskTitles();
     }
     else {
-      $tasks = array(
-        3 => self::$_tasks[3]['title'],
-      );
+      $tasks = [
+        self::TASK_EXPORT => self::$_tasks[self::TASK_EXPORT]['title'],
+      ];
       //CRM-4418,
       if (CRM_Core_Permission::check('delete in CiviCase')) {
-        $tasks[1] = self::$_tasks[1]['title'];
+        $tasks[self::TASK_DELETE] = self::$_tasks[self::TASK_DELETE]['title'];
       }
     }
+
+    $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
     return $tasks;
   }
 
@@ -180,13 +150,13 @@ class CRM_Case_Task {
     self::tasks();
     if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
       // make the print task by default
-      $value = 2;
+      $value = self::TASK_PRINT;
     }
 
-    return array(
+    return [
       self::$_tasks[$value]['class'],
       self::$_tasks[$value]['result'],
-    );
+    ];
   }
 
 }