copyright and version fixes
[civicrm-core.git] / CRM / Member / Task.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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(
73 'title' => ts('Delete Members'),
74 'class' => 'CRM_Member_Form_Task_Delete',
75 'result' => FALSE,
76 ),
77 2 => array(
78 'title' => ts('Print Selected Rows'),
79 'class' => 'CRM_Member_Form_Task_Print',
80 'result' => FALSE,
81 ),
82 3 => array(
83 'title' => ts('Export Members'),
84 'class' => array(
85 'CRM_Export_Form_Select',
86 'CRM_Export_Form_Map',
87 ),
88 'result' => FALSE,
89 ),
90 4 => array(
91 'title' => ts('Send Email to Contacts'),
92 'class' => 'CRM_Member_Form_Task_Email',
93 'result' => TRUE,
94 ),
95 5 => array(
96 'title' => ts('Batch Update Members Via Profile'),
97 'class' => array(
98 'CRM_Member_Form_Task_PickProfile',
99 'CRM_Member_Form_Task_Batch',
100 ),
101 'result' => TRUE,
102 ),
103 6 => array(
104 'title' => ts('Mailing Labels'),
105 'class' => array(
106 'CRM_Member_Form_Task_Label',
107 ),
108 'result' => TRUE,
109 ),
110 7 => array(
111 'title' => ts('Print PDF Letters for Memberships'),
112 'class' => 'CRM_Member_Form_Task_PDFLetter',
113 'result' => FALSE,
114 ),
115 );
116
117 //CRM-4418, check for delete
118 if (!CRM_Core_Permission::check('delete in CiviMember')) {
119 unset(self::$_tasks[1]);
120 }
121 }
122 CRM_Utils_Hook::searchTasks('membership', self::$_tasks);
123 asort(self::$_tasks);
124 return self::$_tasks;
125 }
126
127 /**
128 * These tasks are the core set of task titles
129 * on members
130 *
131 * @return array the set of task titles
132 * @static
133 * @access public
134 */
135 static function &taskTitles() {
136 self::tasks();
137 $titles = array();
138 foreach (self::$_tasks as $id => $value) {
139 $titles[$id] = $value['title'];
140 }
141 return $titles;
142 }
143
144 /**
145 * show tasks selectively based on the permission level
146 * of the user
147 *
148 * @param int $permission
149 *
150 * @return array set of tasks that are valid for the user
151 * @access public
152 */
153 static function &permissionedTaskTitles($permission) {
154 $tasks = array();
155 if (($permission == CRM_Core_Permission::EDIT)
156 || CRM_Core_Permission::check('edit memberships')
157 ) {
158 $tasks = self::taskTitles();
159 }
160 else {
161 $tasks = array(
162 3 => self::$_tasks[3]['title'],
163 4 => self::$_tasks[4]['title'],
164 );
165 //CRM-4418,
166 if (CRM_Core_Permission::check('delete in CiviMember')) {
167 $tasks[1] = self::$_tasks[1]['title'];
168 }
169 }
170 return $tasks;
171 }
172
173 /**
174 * These tasks are the core set of tasks that the user can perform
175 * on members
176 *
177 * @param int $value
178 *
179 * @return array the set of tasks for a group of members
180 * @static
181 * @access public
182 */
183 static function getTask($value) {
184 self::tasks();
185 if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
186 // make the print task by default
187 $value = 2;
188 }
189 return array(
190 self::$_tasks[$value]['class'],
191 self::$_tasks[$value]['result'],
192 );
193 }
194 }
195