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