| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 5 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
| 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 | * @package CRM |
| 30 | * @copyright CiviCRM LLC (c) 2004-2018 |
| 31 | * |
| 32 | */ |
| 33 | |
| 34 | /** |
| 35 | * class to represent the actions that can be performed on a group of contacts |
| 36 | * used by the search forms |
| 37 | * |
| 38 | */ |
| 39 | class CRM_Event_Task extends CRM_Core_Task { |
| 40 | |
| 41 | const |
| 42 | // Event tasks |
| 43 | CANCEL_REGISTRATION = 301, |
| 44 | PARTICIPANT_STATUS = 302; |
| 45 | |
| 46 | static $objectType = 'event'; |
| 47 | |
| 48 | /** |
| 49 | * These tasks are the core set of tasks that the user can perform |
| 50 | * on a contact / group of contacts |
| 51 | * |
| 52 | * @return array The set of tasks for a group of contacts |
| 53 | * [ 'title' => The Task title, |
| 54 | * 'class' => The Task Form class name, |
| 55 | * 'result => Boolean. FIXME: Not sure what this is for |
| 56 | * ] |
| 57 | */ |
| 58 | public static function tasks() { |
| 59 | if (!self::$_tasks) { |
| 60 | self::$_tasks = array( |
| 61 | self::TASK_DELETE => array( |
| 62 | 'title' => ts('Delete participants from event'), |
| 63 | 'class' => 'CRM_Event_Form_Task_Delete', |
| 64 | 'result' => FALSE, |
| 65 | ), |
| 66 | self::TASK_PRINT => array( |
| 67 | 'title' => ts('Print selected rows'), |
| 68 | 'class' => 'CRM_Event_Form_Task_Print', |
| 69 | 'result' => FALSE, |
| 70 | ), |
| 71 | self::TASK_EXPORT => array( |
| 72 | 'title' => ts('Export participants'), |
| 73 | 'class' => array( |
| 74 | 'CRM_Export_Form_Select', |
| 75 | 'CRM_Export_Form_Map', |
| 76 | ), |
| 77 | 'result' => FALSE, |
| 78 | ), |
| 79 | self::BATCH_UPDATE => array( |
| 80 | 'title' => ts('Update multiple participants'), |
| 81 | 'class' => array( |
| 82 | 'CRM_Event_Form_Task_PickProfile', |
| 83 | 'CRM_Event_Form_Task_Batch', |
| 84 | ), |
| 85 | 'result' => TRUE, |
| 86 | ), |
| 87 | self::CANCEL_REGISTRATION => array( |
| 88 | 'title' => ts('Cancel registration'), |
| 89 | 'class' => 'CRM_Event_Form_Task_Cancel', |
| 90 | 'result' => FALSE, |
| 91 | ), |
| 92 | self::TASK_EMAIL => array( |
| 93 | 'title' => ts('Email - send now (to %1 or less)', array( |
| 94 | 1 => Civi::settings() |
| 95 | ->get('simple_mail_limit'), |
| 96 | )), |
| 97 | 'class' => 'CRM_Event_Form_Task_Email', |
| 98 | 'result' => TRUE, |
| 99 | ), |
| 100 | self::SAVE_SEARCH => array( |
| 101 | 'title' => ts('Group - create smart group'), |
| 102 | 'class' => 'CRM_Event_Form_Task_SaveSearch', |
| 103 | 'result' => TRUE, |
| 104 | ), |
| 105 | self::SAVE_SEARCH_UPDATE => array( |
| 106 | 'title' => ts('Group - update smart group'), |
| 107 | 'class' => 'CRM_Event_Form_Task_SaveSearch_Update', |
| 108 | 'result' => TRUE, |
| 109 | ), |
| 110 | self::PARTICIPANT_STATUS => array( |
| 111 | 'title' => ts('Participant status - change'), |
| 112 | 'class' => 'CRM_Event_Form_Task_ParticipantStatus', |
| 113 | 'result' => TRUE, |
| 114 | ), |
| 115 | self::LABEL_CONTACTS => array( |
| 116 | 'title' => ts('Name badges - print'), |
| 117 | 'class' => 'CRM_Event_Form_Task_Badge', |
| 118 | 'result' => FALSE, |
| 119 | ), |
| 120 | self::PDF_LETTER => array( |
| 121 | 'title' => ts('PDF letter - print for participants'), |
| 122 | 'class' => 'CRM_Event_Form_Task_PDF', |
| 123 | 'result' => TRUE, |
| 124 | ), |
| 125 | self::GROUP_ADD => array( |
| 126 | 'title' => ts('Group - add contacts'), |
| 127 | 'class' => 'CRM_Event_Form_Task_AddToGroup', |
| 128 | 'result' => FALSE, |
| 129 | ), |
| 130 | ); |
| 131 | |
| 132 | //CRM-4418, check for delete |
| 133 | if (!CRM_Core_Permission::check('delete in CiviEvent')) { |
| 134 | unset(self::$_tasks[self::TASK_DELETE]); |
| 135 | } |
| 136 | //CRM-12920 - check for edit permission |
| 137 | if (!CRM_Core_Permission::check('edit event participants')) { |
| 138 | unset(self::$_tasks[self::BATCH_UPDATE], self::$_tasks[self::CANCEL_REGISTRATION], self::$_tasks[self::PARTICIPANT_STATUS]); |
| 139 | } |
| 140 | |
| 141 | parent::tasks(); |
| 142 | } |
| 143 | |
| 144 | return self::$_tasks; |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Show tasks selectively based on the permission level |
| 149 | * of the user |
| 150 | * |
| 151 | * @param int $permission |
| 152 | * @param array $params |
| 153 | * |
| 154 | * @return array |
| 155 | * set of tasks that are valid for the user |
| 156 | */ |
| 157 | public static function permissionedTaskTitles($permission, $params = array()) { |
| 158 | if (($permission == CRM_Core_Permission::EDIT) |
| 159 | || CRM_Core_Permission::check('edit event participants') |
| 160 | ) { |
| 161 | $tasks = self::taskTitles(); |
| 162 | } |
| 163 | else { |
| 164 | $tasks = array( |
| 165 | self::TASK_EXPORT => self::$_tasks[self::TASK_EXPORT]['title'], |
| 166 | self::TASK_EMAIL => self::$_tasks[self::TASK_EMAIL]['title'], |
| 167 | ); |
| 168 | |
| 169 | //CRM-4418, |
| 170 | if (CRM_Core_Permission::check('delete in CiviEvent')) { |
| 171 | $tasks[self::TASK_DELETE] = self::$_tasks[self::TASK_DELETE]['title']; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params); |
| 176 | return $tasks; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * These tasks are the core set of tasks that the user can perform |
| 181 | * on participants |
| 182 | * |
| 183 | * @param int $value |
| 184 | * |
| 185 | * @return array |
| 186 | * the set of tasks for a group of participants |
| 187 | */ |
| 188 | public static function getTask($value) { |
| 189 | self::tasks(); |
| 190 | if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) { |
| 191 | // make the print task by default |
| 192 | $value = self::TASK_PRINT; |
| 193 | } |
| 194 | return parent::getTask($value); |
| 195 | } |
| 196 | |
| 197 | } |