| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
| 7 | +--------------------------------------------------------------------+ |
| 8 | | This file is a part of CiviCRM. | |
| 9 | | | |
| 10 | | CiviCRM is free software; you can copy, modify, and distribute it | |
| 11 | | under the terms of the GNU Affero General Public License | |
| 12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | |
| 13 | | | |
| 14 | | CiviCRM is distributed in the hope that it will be useful, but | |
| 15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 17 | | See the GNU Affero General Public License for more details. | |
| 18 | | | |
| 19 | | You should have received a copy of the GNU Affero General Public | |
| 20 | | License and the CiviCRM Licensing Exception along | |
| 21 | | with this program; if not, contact CiviCRM LLC | |
| 22 | | at info[AT]civicrm[DOT]org. If you have questions about the | |
| 23 | | GNU Affero General Public License or the licensing of CiviCRM, | |
| 24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | |
| 25 | +--------------------------------------------------------------------+ |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * |
| 30 | * @package CRM |
| 31 | * @copyright CiviCRM LLC (c) 2004-2017 |
| 32 | */ |
| 33 | |
| 34 | /** |
| 35 | * class to represent the actions that can be performed on a group of voters. |
| 36 | * |
| 37 | * Used by the search forms. |
| 38 | */ |
| 39 | class CRM_Campaign_Task { |
| 40 | const INTERVIEW = 1, RESERVE = 2, RELEASE = 3, PRINT_VOTERS = 4; |
| 41 | |
| 42 | /** |
| 43 | * The task array |
| 44 | * |
| 45 | * @var array |
| 46 | */ |
| 47 | static $_tasks = NULL; |
| 48 | |
| 49 | /** |
| 50 | * The optional task array |
| 51 | * |
| 52 | * @var array |
| 53 | */ |
| 54 | static $_optionalTasks = NULL; |
| 55 | |
| 56 | /** |
| 57 | * These tasks are the core set of tasks that the user can perform |
| 58 | * on a voter / group of voters |
| 59 | * |
| 60 | * @return array |
| 61 | * the set of tasks for a group of voters. |
| 62 | */ |
| 63 | public static function &tasks() { |
| 64 | if (!(self::$_tasks)) { |
| 65 | self::$_tasks = array( |
| 66 | 1 => array( |
| 67 | 'title' => ts('Record Respondents Interview'), |
| 68 | 'class' => array( |
| 69 | 'CRM_Campaign_Form_Task_Interview', |
| 70 | 'CRM_Campaign_Form_Task_Release', |
| 71 | ), |
| 72 | 'result' => FALSE, |
| 73 | ), |
| 74 | 2 => array( |
| 75 | 'title' => ts('Reserve Respondents'), |
| 76 | 'class' => array( |
| 77 | 'CRM_Campaign_Form_Task_Reserve', |
| 78 | 'CRM_Campaign_Form_Task_Interview', |
| 79 | 'CRM_Campaign_Form_Task_Release', |
| 80 | ), |
| 81 | 'result' => FALSE, |
| 82 | ), |
| 83 | 3 => array( |
| 84 | 'title' => ts('Release Respondents'), |
| 85 | 'class' => 'CRM_Campaign_Form_Task_Release', |
| 86 | 'result' => FALSE, |
| 87 | ), |
| 88 | 4 => array( |
| 89 | 'title' => ts('Print Respondents'), |
| 90 | 'class' => 'CRM_Campaign_Form_Task_Print', |
| 91 | 'result' => FALSE, |
| 92 | ), |
| 93 | ); |
| 94 | |
| 95 | CRM_Utils_Hook::searchTasks('campaign', self::$_tasks); |
| 96 | asort(self::$_tasks); |
| 97 | } |
| 98 | |
| 99 | return self::$_tasks; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * These tasks are the core set of task titles |
| 104 | * on voters. |
| 105 | * |
| 106 | * @return array |
| 107 | * the set of task titles |
| 108 | */ |
| 109 | public static function &taskTitles() { |
| 110 | self::tasks(); |
| 111 | $titles = array(); |
| 112 | foreach (self::$_tasks as $id => $value) { |
| 113 | $titles[$id] = $value['title']; |
| 114 | } |
| 115 | |
| 116 | return $titles; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Show tasks selectively based on the permission level |
| 121 | * of the user |
| 122 | * |
| 123 | * @param int $permission |
| 124 | * |
| 125 | * @return array |
| 126 | * set of tasks that are valid for the user |
| 127 | */ |
| 128 | public static function &permissionedTaskTitles($permission) { |
| 129 | $tasks = self::taskTitles(); |
| 130 | |
| 131 | return $tasks; |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * These tasks are the core set of tasks that the user can perform |
| 136 | * on voters. |
| 137 | * |
| 138 | * @param int $value |
| 139 | * |
| 140 | * @return array |
| 141 | * the set of tasks for a group of voters. |
| 142 | */ |
| 143 | public static function getTask($value) { |
| 144 | self::tasks(); |
| 145 | if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) { |
| 146 | // make the interview task by default |
| 147 | $value = 1; |
| 148 | } |
| 149 | |
| 150 | return array( |
| 151 | self::$_tasks[$value]['class'], |
| 152 | self::$_tasks[$value]['result'], |
| 153 | ); |
| 154 | } |
| 155 | |
| 156 | } |