commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / CRM / Member / Task.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
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 */
50 static $_tasks = NULL;
51
52 /**
53 * The optional task array
54 *
55 * @var array
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 *
63 * @return array
64 * the set of tasks for a group of contacts
65 */
66 public static function &tasks() {
67 if (!(self::$_tasks)) {
68 self::$_tasks = array(
69 1 => array(
70 'title' => ts('Delete Memberships'),
71 'class' => 'CRM_Member_Form_Task_Delete',
72 'result' => FALSE,
73 ),
74 2 => array(
75 'title' => ts('Print Selected Rows'),
76 'class' => 'CRM_Member_Form_Task_Print',
77 'result' => FALSE,
78 ),
79 3 => array(
80 '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(
88 'title' => ts('Send Email to Contacts'),
89 'class' => 'CRM_Member_Form_Task_Email',
90 'result' => TRUE,
91 ),
92 5 => array(
93 'title' => ts('Batch Update Members Via Profile'),
94 'class' => array(
95 'CRM_Member_Form_Task_PickProfile',
96 'CRM_Member_Form_Task_Batch',
97 ),
98 'result' => TRUE,
99 ),
100 6 => array(
101 'title' => ts('Mailing Labels'),
102 'class' => array(
103 'CRM_Member_Form_Task_Label',
104 ),
105 'result' => TRUE,
106 ),
107 7 => array(
108 'title' => ts('Print PDF Letters for Memberships'),
109 'class' => 'CRM_Member_Form_Task_PDFLetter',
110 'result' => FALSE,
111 ),
112 );
113
114 //CRM-4418, check for delete
115 if (!CRM_Core_Permission::check('delete in CiviMember')) {
116 unset(self::$_tasks[1]);
117 }
118 //CRM-12920 - check for edit permission
119 if (!CRM_Core_Permission::check('edit memberships')) {
120 unset(self::$_tasks[5]);
121 }
122 }
123 CRM_Utils_Hook::searchTasks('membership', self::$_tasks);
124 asort(self::$_tasks);
125 return self::$_tasks;
126 }
127
128 /**
129 * These tasks are the core set of task titles
130 * on members
131 *
132 * @return array
133 * the set of task titles
134 */
135 public 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
151 * set of tasks that are valid for the user
152 */
153 public 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
180 * the set of tasks for a group of members
181 */
182 public static function getTask($value) {
183 self::tasks();
184 if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
185 // make the print task by default
186 $value = 2;
187 }
188 return array(
189 self::$_tasks[$value]['class'],
190 self::$_tasks[$value]['result'],
191 );
192 }
193
194 }