Merge pull request #18544 from magnolia61/participant_status_notification_default
[civicrm-core.git] / CRM / Member / Task.php
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 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * class to represent the actions that can be performed on a group of
20 * contacts (CiviMember)
21 * used by the search forms
22 *
23 */
24 class CRM_Member_Task extends CRM_Core_Task {
25 /**
26 * Member tasks
27 */
28 const LABEL_MEMBERS = 201;
29
30 /**
31 * @var string
32 */
33 public static $objectType = 'membership';
34
35 /**
36 * These tasks are the core set of tasks that the user can perform
37 * on a contact / group of contacts
38 *
39 * @return array
40 * the set of tasks for a group of contacts
41 */
42 public static function tasks() {
43 if (!self::$_tasks) {
44 self::$_tasks = [
45 self::TASK_DELETE => [
46 'title' => ts('Delete memberships'),
47 'class' => 'CRM_Member_Form_Task_Delete',
48 'result' => FALSE,
49 ],
50 self::TASK_PRINT => [
51 'title' => ts('Print selected rows'),
52 'class' => 'CRM_Member_Form_Task_Print',
53 'result' => FALSE,
54 ],
55 self::TASK_EXPORT => [
56 'title' => ts('Export members'),
57 'class' => [
58 'CRM_Member_Export_Form_Select',
59 'CRM_Member_Export_Form_Map',
60 ],
61 'result' => FALSE,
62 ],
63 self::TASK_EMAIL => [
64 'title' => ts('Email - send now (to %1 or less)', [
65 1 => Civi::settings()
66 ->get('simple_mail_limit'),
67 ]),
68 'class' => 'CRM_Member_Form_Task_Email',
69 'result' => TRUE,
70 ],
71 self::BATCH_UPDATE => [
72 'title' => ts('Update multiple memberships'),
73 'class' => [
74 'CRM_Member_Form_Task_PickProfile',
75 'CRM_Member_Form_Task_Batch',
76 ],
77 'result' => TRUE,
78 ],
79 self::LABEL_MEMBERS => [
80 'title' => ts('Mailing labels - print'),
81 'class' => [
82 'CRM_Member_Form_Task_Label',
83 ],
84 'result' => TRUE,
85 ],
86 self::PDF_LETTER => [
87 'title' => ts('Print/merge document for memberships'),
88 'class' => 'CRM_Member_Form_Task_PDFLetter',
89 'result' => FALSE,
90 ],
91 self::SAVE_SEARCH => [
92 'title' => ts('Group - create smart group'),
93 'class' => 'CRM_Contact_Form_Task_SaveSearch',
94 'result' => TRUE,
95 ],
96 self::SAVE_SEARCH_UPDATE => [
97 'title' => ts('Group - update smart group'),
98 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update',
99 'result' => TRUE,
100 ],
101 ];
102
103 //CRM-4418, check for delete
104 if (!CRM_Core_Permission::check('delete in CiviMember')) {
105 unset(self::$_tasks[self::TASK_DELETE]);
106 }
107 //CRM-12920 - check for edit permission
108 if (!CRM_Core_Permission::check('edit memberships')) {
109 unset(self::$_tasks[self::BATCH_UPDATE]);
110 }
111
112 parent::tasks();
113 }
114
115 return self::$_tasks;
116 }
117
118 /**
119 * These tasks are the core set of task titles
120 * on members
121 *
122 * @return array
123 * the set of task titles
124 */
125 public static function taskTitles() {
126 return parent::taskTitles();
127 }
128
129 /**
130 * Show tasks selectively based on the permission level
131 * of the user
132 *
133 * @param int $permission
134 * @param array $params
135 *
136 * @return array
137 * set of tasks that are valid for the user
138 */
139 public static function permissionedTaskTitles($permission, $params = []) {
140 if (($permission == CRM_Core_Permission::EDIT)
141 || CRM_Core_Permission::check('edit memberships')
142 ) {
143 $tasks = self::taskTitles();
144 }
145 else {
146 $tasks = [
147 self::TASK_EXPORT => self::$_tasks[self::TASK_EXPORT]['title'],
148 self::TASK_EMAIL => self::$_tasks[self::TASK_EMAIL]['title'],
149 ];
150 //CRM-4418,
151 if (CRM_Core_Permission::check('delete in CiviMember')) {
152 $tasks[self::TASK_DELETE] = self::$_tasks[self::TASK_DELETE]['title'];
153 }
154 }
155
156 $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
157 return $tasks;
158 }
159
160 /**
161 * These tasks are the core set of tasks that the user can perform
162 * on members
163 *
164 * @param int $value
165 *
166 * @return array
167 * the set of tasks for a group of members
168 */
169 public static function getTask($value) {
170 self::tasks();
171 if (!$value || empty(self::$_tasks[$value])) {
172 // Make the print task the default
173 $value = self::TASK_PRINT;
174 }
175 return parent::getTask($value);
176 }
177
178 }