| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | Copyright CiviCRM LLC. All rights reserved. | |
| 5 | | | |
| 6 | | This work is published under the GNU AGPLv3 license with some | |
| 7 | | permitted exceptions and without any warranty. For full license | |
| 8 | | and copyright information, see https://civicrm.org/licensing | |
| 9 | +--------------------------------------------------------------------+ |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * |
| 14 | * @package CRM |
| 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
| 16 | */ |
| 17 | |
| 18 | /** |
| 19 | * class to represent the actions that can be performed on a group of voters. |
| 20 | * |
| 21 | * Used by the search forms. |
| 22 | */ |
| 23 | class CRM_Campaign_Task extends CRM_Core_Task { |
| 24 | |
| 25 | /** |
| 26 | * Campaign tasks |
| 27 | */ |
| 28 | const |
| 29 | INTERVIEW = 601, |
| 30 | RESERVE = 602, |
| 31 | RELEASE = 603; |
| 32 | |
| 33 | /** |
| 34 | * @var string |
| 35 | */ |
| 36 | public static $objectType = 'campaign'; |
| 37 | |
| 38 | /** |
| 39 | * These tasks are the core set of tasks that the user can perform |
| 40 | * on a voter / group of voters |
| 41 | * |
| 42 | * @return array |
| 43 | * the set of tasks for a group of voters. |
| 44 | */ |
| 45 | public static function tasks() { |
| 46 | if (!(self::$_tasks)) { |
| 47 | self::$_tasks = [ |
| 48 | self::INTERVIEW => [ |
| 49 | 'title' => ts('Record Respondents Interview'), |
| 50 | 'class' => [ |
| 51 | 'CRM_Campaign_Form_Task_Interview', |
| 52 | 'CRM_Campaign_Form_Task_Release', |
| 53 | ], |
| 54 | 'result' => FALSE, |
| 55 | ], |
| 56 | self::RESERVE => [ |
| 57 | 'title' => ts('Reserve Respondents'), |
| 58 | 'class' => [ |
| 59 | 'CRM_Campaign_Form_Task_Reserve', |
| 60 | 'CRM_Campaign_Form_Task_Interview', |
| 61 | 'CRM_Campaign_Form_Task_Release', |
| 62 | ], |
| 63 | 'result' => FALSE, |
| 64 | ], |
| 65 | self::RELEASE => [ |
| 66 | 'title' => ts('Release Respondents'), |
| 67 | 'class' => 'CRM_Campaign_Form_Task_Release', |
| 68 | 'result' => FALSE, |
| 69 | ], |
| 70 | self::TASK_PRINT => [ |
| 71 | 'title' => ts('Print Respondents'), |
| 72 | 'class' => 'CRM_Campaign_Form_Task_Print', |
| 73 | 'result' => FALSE, |
| 74 | ], |
| 75 | ]; |
| 76 | |
| 77 | parent::tasks(); |
| 78 | } |
| 79 | |
| 80 | return self::$_tasks; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Show tasks selectively based on the permission level |
| 85 | * of the user |
| 86 | * |
| 87 | * @param int $permission |
| 88 | * @param array $params |
| 89 | * |
| 90 | * @return array |
| 91 | * set of tasks that are valid for the user |
| 92 | */ |
| 93 | public static function permissionedTaskTitles($permission, $params = []) { |
| 94 | $tasks = self::taskTitles(); |
| 95 | |
| 96 | $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params); |
| 97 | return $tasks; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * These tasks are the core set of tasks that the user can perform |
| 102 | * on voters. |
| 103 | * |
| 104 | * @param int $value |
| 105 | * |
| 106 | * @return array |
| 107 | * the set of tasks for a group of voters. |
| 108 | */ |
| 109 | public static function getTask($value) { |
| 110 | self::tasks(); |
| 111 | if (!$value || empty(self::$_tasks[$value])) { |
| 112 | // Set the interview task as default |
| 113 | $value = self::INTERVIEW; |
| 114 | } |
| 115 | |
| 116 | return [ |
| 117 | self::$_tasks[$value]['class'], |
| 118 | self::$_tasks[$value]['result'], |
| 119 | ]; |
| 120 | } |
| 121 | |
| 122 | } |