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