Commit | Line | Data |
---|---|---|
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 | 24 | class 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', | |
61fad6d6 | 47 | 'permissions' => ['delete in CiviMember'], |
14abd3ea | 48 | 'result' => FALSE, |
61fad6d6 EM |
49 | // Hopefully transitional key - if permission to edit the contact also required. |
50 | 'requires_edit_contact_permission' => FALSE, | |
14abd3ea | 51 | ], |
52 | self::TASK_PRINT => [ | |
53 | 'title' => ts('Print selected rows'), | |
54 | 'class' => 'CRM_Member_Form_Task_Print', | |
55 | 'result' => FALSE, | |
61fad6d6 EM |
56 | 'permissions' => [['view memberships', 'edit memberships']], |
57 | // Transitional key. May change. | |
58 | 'requires_edit_contact_permission' => FALSE, | |
14abd3ea | 59 | ], |
60 | self::TASK_EXPORT => [ | |
61 | 'title' => ts('Export members'), | |
62 | 'class' => [ | |
63 | 'CRM_Member_Export_Form_Select', | |
64 | 'CRM_Member_Export_Form_Map', | |
be2fb01f | 65 | ], |
61fad6d6 EM |
66 | 'permissions' => [['view memberships', 'edit memberships']], |
67 | // Transitional key. May change. | |
68 | 'requires_edit_contact_permission' => FALSE, | |
14abd3ea | 69 | 'result' => FALSE, |
70 | ], | |
71 | self::TASK_EMAIL => [ | |
72 | 'title' => ts('Email - send now (to %1 or less)', [ | |
73 | 1 => Civi::settings() | |
74 | ->get('simple_mail_limit'), | |
75 | ]), | |
76 | 'class' => 'CRM_Member_Form_Task_Email', | |
77 | 'result' => TRUE, | |
61fad6d6 EM |
78 | 'permissions' => ['edit memberships'], |
79 | // Transitional key. May change. | |
80 | 'requires_edit_contact_permission' => TRUE, | |
14abd3ea | 81 | ], |
82 | self::BATCH_UPDATE => [ | |
83 | 'title' => ts('Update multiple memberships'), | |
84 | 'class' => [ | |
85 | 'CRM_Member_Form_Task_PickProfile', | |
86 | 'CRM_Member_Form_Task_Batch', | |
be2fb01f | 87 | ], |
61fad6d6 EM |
88 | 'permissions' => ['edit memberships'], |
89 | // Transitional key. May change. | |
90 | 'requires_edit_contact_permission' => TRUE, | |
14abd3ea | 91 | 'result' => TRUE, |
92 | ], | |
93 | self::LABEL_MEMBERS => [ | |
94 | 'title' => ts('Mailing labels - print'), | |
95 | 'class' => [ | |
96 | 'CRM_Member_Form_Task_Label', | |
be2fb01f | 97 | ], |
61fad6d6 EM |
98 | 'permissions' => ['edit memberships'], |
99 | // Transitional key. May change. | |
100 | 'requires_edit_contact_permission' => TRUE, | |
14abd3ea | 101 | 'result' => TRUE, |
102 | ], | |
103 | self::PDF_LETTER => [ | |
104 | 'title' => ts('Print/merge document for memberships'), | |
105 | 'class' => 'CRM_Member_Form_Task_PDFLetter', | |
106 | 'result' => FALSE, | |
61fad6d6 EM |
107 | 'permissions' => ['edit memberships'], |
108 | // Transitional key. May change. | |
109 | 'requires_edit_contact_permission' => TRUE, | |
14abd3ea | 110 | ], |
111 | self::SAVE_SEARCH => [ | |
112 | 'title' => ts('Group - create smart group'), | |
113 | 'class' => 'CRM_Contact_Form_Task_SaveSearch', | |
114 | 'result' => TRUE, | |
61fad6d6 EM |
115 | 'permissions' => ['edit groups'], |
116 | // Transitional key. May change. | |
117 | 'requires_edit_contact_permission' => FALSE, | |
14abd3ea | 118 | ], |
119 | self::SAVE_SEARCH_UPDATE => [ | |
120 | 'title' => ts('Group - update smart group'), | |
121 | 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update', | |
122 | 'result' => TRUE, | |
61fad6d6 EM |
123 | 'permissions' => ['edit groups'], |
124 | // Transitional key. May change. | |
125 | 'requires_edit_contact_permission' => FALSE, | |
14abd3ea | 126 | ], |
127 | ]; | |
14abd3ea | 128 | parent::tasks(); |
6a488035 TO |
129 | return self::$_tasks; |
130 | } | |
131 | ||
132 | /** | |
133 | * These tasks are the core set of task titles | |
134 | * on members | |
135 | * | |
a6c01b45 CW |
136 | * @return array |
137 | * the set of task titles | |
6a488035 | 138 | */ |
e335ab3b MW |
139 | public static function taskTitles() { |
140 | return parent::taskTitles(); | |
6a488035 TO |
141 | } |
142 | ||
143 | /** | |
100fef9d | 144 | * Show tasks selectively based on the permission level |
6a488035 TO |
145 | * of the user |
146 | * | |
147 | * @param int $permission | |
e335ab3b | 148 | * @param array $params |
6a488035 | 149 | * |
a6c01b45 CW |
150 | * @return array |
151 | * set of tasks that are valid for the user | |
6a488035 | 152 | */ |
be2fb01f | 153 | public static function permissionedTaskTitles($permission, $params = []) { |
95913c71 | 154 | $tasks = self::getTitlesFilteredByPermission(self::tasks(), $permission === CRM_Core_Permission::EDIT); |
61fad6d6 | 155 | return parent::corePermissionedTaskTitles($tasks, $permission, $params); |
6a488035 TO |
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) { |
95913c71 | 168 | if (!$value || empty(self::tasks()[$value])) { |
e335ab3b MW |
169 | // Make the print task the default |
170 | $value = self::TASK_PRINT; | |
6a488035 | 171 | } |
e335ab3b | 172 | return parent::getTask($value); |
6a488035 | 173 | } |
96025800 | 174 | |
6a488035 | 175 | } |