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