| 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 used by the search forms. |
| 19 | */ |
| 20 | class CRM_Activity_Task extends CRM_Core_Task { |
| 21 | |
| 22 | public static $objectType = 'activity'; |
| 23 | |
| 24 | /** |
| 25 | * These tasks are the core set of tasks that the user can perform |
| 26 | * on a contact / group of contacts. |
| 27 | * |
| 28 | * @return array |
| 29 | * the set of tasks for a group of contacts |
| 30 | */ |
| 31 | public static function tasks() { |
| 32 | if (!(self::$_tasks)) { |
| 33 | self::$_tasks = [ |
| 34 | self::TASK_DELETE => [ |
| 35 | 'title' => ts('Delete activities'), |
| 36 | 'class' => 'CRM_Activity_Form_Task_Delete', |
| 37 | 'result' => FALSE, |
| 38 | ], |
| 39 | self::TASK_PRINT => [ |
| 40 | 'title' => ts('Print selected rows'), |
| 41 | 'class' => 'CRM_Activity_Form_Task_Print', |
| 42 | 'result' => FALSE, |
| 43 | ], |
| 44 | self::TASK_EXPORT => [ |
| 45 | 'title' => ts('Export activities'), |
| 46 | 'class' => [ |
| 47 | 'CRM_Activity_Export_Form_Select', |
| 48 | 'CRM_Activity_Export_Form_Map', |
| 49 | ], |
| 50 | 'result' => FALSE, |
| 51 | ], |
| 52 | self::BATCH_UPDATE => [ |
| 53 | 'title' => ts('Update multiple activities'), |
| 54 | 'class' => [ |
| 55 | 'CRM_Activity_Form_Task_PickProfile', |
| 56 | 'CRM_Activity_Form_Task_Batch', |
| 57 | ], |
| 58 | 'result' => FALSE, |
| 59 | ], |
| 60 | self::TASK_EMAIL => [ |
| 61 | 'title' => ts('Email - send now (to %1 or less)', [ |
| 62 | 1 => Civi::settings() |
| 63 | ->get('simple_mail_limit'), |
| 64 | ]), |
| 65 | 'class' => [ |
| 66 | 'CRM_Activity_Form_Task_PickOption', |
| 67 | 'CRM_Activity_Form_Task_Email', |
| 68 | ], |
| 69 | 'result' => FALSE, |
| 70 | ], |
| 71 | self::PDF_LETTER => [ |
| 72 | 'title' => ts('Print/merge Document'), |
| 73 | 'class' => 'CRM_Activity_Form_Task_PDF', |
| 74 | 'result' => FALSE, |
| 75 | ], |
| 76 | self::TASK_SMS => [ |
| 77 | 'title' => ts('SMS - send reply'), |
| 78 | 'class' => 'CRM_Activity_Form_Task_SMS', |
| 79 | 'result' => FALSE, |
| 80 | ], |
| 81 | self::TAG_ADD => [ |
| 82 | 'title' => ts('Tag - add to activities'), |
| 83 | 'class' => 'CRM_Activity_Form_Task_AddToTag', |
| 84 | 'result' => FALSE, |
| 85 | ], |
| 86 | self::TAG_REMOVE => [ |
| 87 | 'title' => ts('Tag - remove from activities'), |
| 88 | 'class' => 'CRM_Activity_Form_Task_RemoveFromTag', |
| 89 | 'result' => FALSE, |
| 90 | ], |
| 91 | ]; |
| 92 | |
| 93 | $config = CRM_Core_Config::singleton(); |
| 94 | if (in_array('CiviCase', $config->enableComponents)) { |
| 95 | if (CRM_Core_Permission::check('access all cases and activities') || |
| 96 | CRM_Core_Permission::check('access my cases and activities') |
| 97 | ) { |
| 98 | self::$_tasks[self::TASK_SMS] = [ |
| 99 | 'title' => ts('File on case'), |
| 100 | 'class' => 'CRM_Activity_Form_Task_FileOnCase', |
| 101 | 'result' => FALSE, |
| 102 | ]; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // CRM-4418, check for delete |
| 107 | if (!CRM_Core_Permission::check('delete activities')) { |
| 108 | unset(self::$_tasks[self::TASK_DELETE]); |
| 109 | } |
| 110 | |
| 111 | parent::tasks(); |
| 112 | } |
| 113 | |
| 114 | return self::$_tasks; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Show tasks selectively based on the permission level of the user. |
| 119 | * |
| 120 | * @param int $permission |
| 121 | * @param array $params |
| 122 | * |
| 123 | * @return array |
| 124 | * set of tasks that are valid for the user |
| 125 | */ |
| 126 | public static function permissionedTaskTitles($permission, $params = []) { |
| 127 | if ($permission == CRM_Core_Permission::EDIT) { |
| 128 | $tasks = self::taskTitles(); |
| 129 | } |
| 130 | else { |
| 131 | $tasks = [ |
| 132 | self::TASK_EXPORT => self::$_tasks[self::TASK_EXPORT]['title'], |
| 133 | ]; |
| 134 | |
| 135 | //CRM-4418, |
| 136 | if (CRM_Core_Permission::check('delete activities')) { |
| 137 | $tasks[self::TASK_DELETE] = self::$_tasks[self::TASK_DELETE]['title']; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params); |
| 142 | return $tasks; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * These tasks are the core set of tasks that the user can perform on activity. |
| 147 | * |
| 148 | * @param int $value |
| 149 | * |
| 150 | * @return array |
| 151 | * the set of tasks for a group of activity |
| 152 | */ |
| 153 | public static function getTask($value) { |
| 154 | self::tasks(); |
| 155 | if (!$value || empty(self::$_tasks[$value])) { |
| 156 | // make the print task by default |
| 157 | $value = self::TASK_PRINT; |
| 158 | } |
| 159 | |
| 160 | return [ |
| 161 | self::$_tasks[$value]['class'], |
| 162 | self::$_tasks[$value]['result'], |
| 163 | ]; |
| 164 | } |
| 165 | |
| 166 | } |