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