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