Merge pull request #23743 from totten/master-queue-runas
[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 self::$_tasks = [
44 self::TASK_DELETE => [
45 'title' => ts('Delete memberships'),
46 'class' => 'CRM_Member_Form_Task_Delete',
47 'permissions' => ['delete in CiviMember'],
48 'result' => FALSE,
49 // Hopefully transitional key - if permission to edit the contact also required.
50 'requires_edit_contact_permission' => FALSE,
51 ],
52 self::TASK_PRINT => [
53 'title' => ts('Print selected rows'),
54 'class' => 'CRM_Member_Form_Task_Print',
55 'result' => FALSE,
56 'permissions' => [['view memberships', 'edit memberships']],
57 // Transitional key. May change.
58 'requires_edit_contact_permission' => FALSE,
59 ],
60 self::TASK_EXPORT => [
61 'title' => ts('Export members'),
62 'class' => [
63 'CRM_Member_Export_Form_Select',
64 'CRM_Member_Export_Form_Map',
65 ],
66 'permissions' => [['view memberships', 'edit memberships']],
67 // Transitional key. May change.
68 'requires_edit_contact_permission' => FALSE,
69 'result' => FALSE,
70 ],
71 self::TASK_EMAIL => [
72 'title' => ts('Email - send now (to %1 or less)', [
73 1 => Civi::settings()
74 ->get('simple_mail_limit'),
75 ]),
76 'class' => 'CRM_Member_Form_Task_Email',
77 'result' => TRUE,
78 'permissions' => ['edit memberships'],
79 // Transitional key. May change.
80 'requires_edit_contact_permission' => TRUE,
81 ],
82 self::BATCH_UPDATE => [
83 'title' => ts('Update multiple memberships'),
84 'class' => [
85 'CRM_Member_Form_Task_PickProfile',
86 'CRM_Member_Form_Task_Batch',
87 ],
88 'permissions' => ['edit memberships'],
89 // Transitional key. May change.
90 'requires_edit_contact_permission' => TRUE,
91 'result' => TRUE,
92 ],
93 self::LABEL_MEMBERS => [
94 'title' => ts('Mailing labels - print'),
95 'class' => [
96 'CRM_Member_Form_Task_Label',
97 ],
98 'permissions' => ['edit memberships'],
99 // Transitional key. May change.
100 'requires_edit_contact_permission' => TRUE,
101 'result' => TRUE,
102 ],
103 self::PDF_LETTER => [
104 'title' => ts('Print/merge document for memberships'),
105 'class' => 'CRM_Member_Form_Task_PDFLetter',
106 'result' => FALSE,
107 'permissions' => ['edit memberships'],
108 // Transitional key. May change.
109 'requires_edit_contact_permission' => TRUE,
110 ],
111 self::SAVE_SEARCH => [
112 'title' => ts('Group - create smart group'),
113 'class' => 'CRM_Contact_Form_Task_SaveSearch',
114 'result' => TRUE,
115 'permissions' => ['edit groups'],
116 // Transitional key. May change.
117 'requires_edit_contact_permission' => FALSE,
118 ],
119 self::SAVE_SEARCH_UPDATE => [
120 'title' => ts('Group - update smart group'),
121 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update',
122 'result' => TRUE,
123 'permissions' => ['edit groups'],
124 // Transitional key. May change.
125 'requires_edit_contact_permission' => FALSE,
126 ],
127 ];
128 parent::tasks();
129 return self::$_tasks;
130 }
131
132 /**
133 * These tasks are the core set of task titles
134 * on members
135 *
136 * @return array
137 * the set of task titles
138 */
139 public static function taskTitles() {
140 return parent::taskTitles();
141 }
142
143 /**
144 * Show tasks selectively based on the permission level
145 * of the user
146 *
147 * @param int $permission
148 * @param array $params
149 *
150 * @return array
151 * set of tasks that are valid for the user
152 */
153 public static function permissionedTaskTitles($permission, $params = []) {
154 $tasks = self::getTitlesFilteredByPermission(self::tasks(), $permission === CRM_Core_Permission::EDIT);
155 return parent::corePermissionedTaskTitles($tasks, $permission, $params);
156 }
157
158 /**
159 * These tasks are the core set of tasks that the user can perform
160 * on members
161 *
162 * @param int $value
163 *
164 * @return array
165 * the set of tasks for a group of members
166 */
167 public static function getTask($value) {
168 if (!$value || empty(self::tasks()[$value])) {
169 // Make the print task the default
170 $value = self::TASK_PRINT;
171 }
172 return parent::getTask($value);
173 }
174
175 }