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