Merge pull request #18623 from eileenmcnaughton/rene
[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 'result' => FALSE,
48 ],
49 self::TASK_PRINT => [
50 'title' => ts('Print selected rows'),
51 'class' => 'CRM_Member_Form_Task_Print',
52 'result' => FALSE,
53 ],
54 self::TASK_EXPORT => [
55 'title' => ts('Export members'),
56 'class' => [
57 'CRM_Member_Export_Form_Select',
58 'CRM_Member_Export_Form_Map',
59 ],
60 'result' => FALSE,
61 ],
62 self::TASK_EMAIL => [
63 'title' => ts('Email - send now (to %1 or less)', [
64 1 => Civi::settings()
65 ->get('simple_mail_limit'),
66 ]),
67 'class' => 'CRM_Member_Form_Task_Email',
68 'result' => TRUE,
69 ],
70 self::BATCH_UPDATE => [
71 'title' => ts('Update multiple memberships'),
72 'class' => [
73 'CRM_Member_Form_Task_PickProfile',
74 'CRM_Member_Form_Task_Batch',
75 ],
76 'result' => TRUE,
77 ],
78 self::LABEL_MEMBERS => [
79 'title' => ts('Mailing labels - print'),
80 'class' => [
81 'CRM_Member_Form_Task_Label',
82 ],
83 'result' => TRUE,
84 ],
85 self::PDF_LETTER => [
86 'title' => ts('Print/merge document for memberships'),
87 'class' => 'CRM_Member_Form_Task_PDFLetter',
88 'result' => FALSE,
89 ],
90 self::SAVE_SEARCH => [
91 'title' => ts('Group - create smart group'),
92 'class' => 'CRM_Contact_Form_Task_SaveSearch',
93 'result' => TRUE,
94 ],
95 self::SAVE_SEARCH_UPDATE => [
96 'title' => ts('Group - update smart group'),
97 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update',
98 'result' => TRUE,
99 ],
100 ];
101
102 //CRM-4418, check for delete
103 if (!CRM_Core_Permission::check('delete in CiviMember')) {
104 unset(self::$_tasks[self::TASK_DELETE]);
105 }
106 //CRM-12920 - check for edit permission
107 if (!CRM_Core_Permission::check('edit memberships')) {
108 unset(self::$_tasks[self::BATCH_UPDATE]);
109 }
110
111 parent::tasks();
112
113 return self::$_tasks;
114 }
115
116 /**
117 * These tasks are the core set of task titles
118 * on members
119 *
120 * @return array
121 * the set of task titles
122 */
123 public static function taskTitles() {
124 return parent::taskTitles();
125 }
126
127 /**
128 * Show tasks selectively based on the permission level
129 * 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 || CRM_Core_Permission::check('edit memberships')
140 ) {
141 $tasks = self::taskTitles();
142 }
143 else {
144 $tasks = [
145 self::TASK_EXPORT => self::$_tasks[self::TASK_EXPORT]['title'],
146 self::TASK_EMAIL => self::$_tasks[self::TASK_EMAIL]['title'],
147 ];
148 //CRM-4418,
149 if (CRM_Core_Permission::check('delete in CiviMember')) {
150 $tasks[self::TASK_DELETE] = self::$_tasks[self::TASK_DELETE]['title'];
151 }
152 }
153
154 $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
155 return $tasks;
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 self::tasks();
169 if (!$value || empty(self::$_tasks[$value])) {
170 // Make the print task the default
171 $value = self::TASK_PRINT;
172 }
173 return parent::getTask($value);
174 }
175
176 }