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