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