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