Merge pull request #19421 from eileenmcnaughton/act2
[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 42 public static function tasks() {
14abd3ea 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',
be2fb01f 59 ],
14abd3ea 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',
be2fb01f 75 ],
14abd3ea 76 'result' => TRUE,
77 ],
78 self::LABEL_MEMBERS => [
79 'title' => ts('Mailing labels - print'),
80 'class' => [
81 'CRM_Member_Form_Task_Label',
be2fb01f 82 ],
14abd3ea 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 ];
4d73a5a7 101
14abd3ea 102 //CRM-4418, check for delete
103 if (!CRM_Core_Permission::check('delete in CiviMember')) {
104 unset(self::$_tasks[self::TASK_DELETE]);
6a488035 105 }
14abd3ea 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();
4d73a5a7 112
6a488035
TO
113 return self::$_tasks;
114 }
115
116 /**
117 * These tasks are the core set of task titles
118 * on members
119 *
a6c01b45
CW
120 * @return array
121 * the set of task titles
6a488035 122 */
e335ab3b
MW
123 public static function taskTitles() {
124 return parent::taskTitles();
6a488035
TO
125 }
126
127 /**
100fef9d 128 * Show tasks selectively based on the permission level
6a488035
TO
129 * of the user
130 *
131 * @param int $permission
e335ab3b 132 * @param array $params
6a488035 133 *
a6c01b45
CW
134 * @return array
135 * set of tasks that are valid for the user
6a488035 136 */
be2fb01f 137 public static function permissionedTaskTitles($permission, $params = []) {
6a488035
TO
138 if (($permission == CRM_Core_Permission::EDIT)
139 || CRM_Core_Permission::check('edit memberships')
140 ) {
141 $tasks = self::taskTitles();
142 }
143 else {
be2fb01f 144 $tasks = [
e335ab3b
MW
145 self::TASK_EXPORT => self::$_tasks[self::TASK_EXPORT]['title'],
146 self::TASK_EMAIL => self::$_tasks[self::TASK_EMAIL]['title'],
be2fb01f 147 ];
6a488035
TO
148 //CRM-4418,
149 if (CRM_Core_Permission::check('delete in CiviMember')) {
e335ab3b 150 $tasks[self::TASK_DELETE] = self::$_tasks[self::TASK_DELETE]['title'];
6a488035
TO
151 }
152 }
e335ab3b
MW
153
154 $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
6a488035
TO
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 *
a6c01b45
CW
164 * @return array
165 * the set of tasks for a group of members
6a488035 166 */
00be9182 167 public static function getTask($value) {
6a488035 168 self::tasks();
b99f3e96 169 if (!$value || empty(self::$_tasks[$value])) {
e335ab3b
MW
170 // Make the print task the default
171 $value = self::TASK_PRINT;
6a488035 172 }
e335ab3b 173 return parent::getTask($value);
6a488035 174 }
96025800 175
6a488035 176}