Merge pull request #2901 from eileenmcnaughton/E-notice
[civicrm-core.git] / CRM / Member / Task.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2013
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 */
42 class CRM_Member_Task {
43 CONST DELETE_MEMBERS = 1, PRINT_MEMBERS = 2, EXPORT_MEMBERS = 3, EMAIL_CONTACTS = 4, BATCH_MEMBERS = 5;
44
45 /**
46 * the task array
47 *
48 * @var array
49 * @static
50 */
51 static $_tasks = NULL;
52
53 /**
54 * the optional task array
55 *
56 * @var array
57 * @static
58 */
59 static $_optionalTasks = NULL;
60
61 /**
62 * These tasks are the core set of tasks that the user can perform
63 * on a contact / group of contacts
64 *
65 * @return array the set of tasks for a group of contacts
66 * @static
67 * @access public
68 */
69 static function &tasks() {
70 if (!(self::$_tasks)) {
71 self::$_tasks = array(
72 1 => array('title' => ts('Delete Members'),
73 'class' => 'CRM_Member_Form_Task_Delete',
74 'result' => FALSE,
75 ),
76 2 => array('title' => ts('Print Memberships'),
77 'class' => 'CRM_Member_Form_Task_Print',
78 'result' => FALSE,
79 ),
80 3 => array('title' => ts('Export Members'),
81 'class' => array(
82 'CRM_Export_Form_Select',
83 'CRM_Export_Form_Map',
84 ),
85 'result' => FALSE,
86 ),
87 4 => array('title' => ts('Send Email to Contacts'),
88 'class' => 'CRM_Member_Form_Task_Email',
89 'result' => TRUE,
90 ),
91 5 => array('title' => ts('Batch Update Members Via Profile'),
92 'class' => array(
93 'CRM_Member_Form_Task_PickProfile',
94 'CRM_Member_Form_Task_Batch',
95 ),
96 'result' => TRUE,
97 ),
98 6 => array('title' => ts('Mailing Labels'),
99 'class' => array(
100 'CRM_Member_Form_Task_Label',
101 ),
102 'result' => TRUE,
103 ),
104 7 => array('title' => ts('Print PDF Letters for Memberships'),
105 'class' => 'CRM_Member_Form_Task_PDFLetter',
106 'result' => FALSE,
107 ),
108 );
109
110 //CRM-4418, check for delete
111 if (!CRM_Core_Permission::check('delete in CiviMember')) {
112 unset(self::$_tasks[1]);
113 }
114 }
115 CRM_Utils_Hook::searchTasks('membership', self::$_tasks);
116 asort(self::$_tasks);
117 return self::$_tasks;
118 }
119
120 /**
121 * These tasks are the core set of task titles
122 * on members
123 *
124 * @return array the set of task titles
125 * @static
126 * @access public
127 */
128 static function &taskTitles() {
129 self::tasks();
130 $titles = array();
131 foreach (self::$_tasks as $id => $value) {
132 // skip Print Membership task
133 if ($id != 2) {
134 $titles[$id] = $value['title'];
135 }
136 }
137 return $titles;
138 }
139
140 /**
141 * show tasks selectively based on the permission level
142 * of the user
143 *
144 * @param int $permission
145 *
146 * @return array set of tasks that are valid for the user
147 * @access public
148 */
149 static function &permissionedTaskTitles($permission) {
150 $tasks = array();
151 if (($permission == CRM_Core_Permission::EDIT)
152 || CRM_Core_Permission::check('edit memberships')
153 ) {
154 $tasks = self::taskTitles();
155 }
156 else {
157 $tasks = array(
158 3 => self::$_tasks[3]['title'],
159 4 => self::$_tasks[4]['title'],
160 );
161 //CRM-4418,
162 if (CRM_Core_Permission::check('delete in CiviMember')) {
163 $tasks[1] = self::$_tasks[1]['title'];
164 }
165 }
166 return $tasks;
167 }
168
169 /**
170 * These tasks are the core set of tasks that the user can perform
171 * on members
172 *
173 * @param int $value
174 *
175 * @return array the set of tasks for a group of members
176 * @static
177 * @access public
178 */
179 static function getTask($value) {
180 self::tasks();
181 if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
182 // make the print task by default
183 $value = 2;
184 }
185 return array(
186 self::$_tasks[$value]['class'],
187 self::$_tasks[$value]['result'],
188 );
189 }
190 }
191