CRM-12332 and fix spelling
[civicrm-core.git] / CRM / Member / Task.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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 */
42class 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 );
99
100 //CRM-4418, check for delete
101 if (!CRM_Core_Permission::check('delete in CiviMember')) {
102 unset(self::$_tasks[1]);
103 }
104 }
105 CRM_Utils_Hook::searchTasks('membership', self::$_tasks);
106 asort(self::$_tasks);
107 return self::$_tasks;
108 }
109
110 /**
111 * These tasks are the core set of task titles
112 * on members
113 *
114 * @return array the set of task titles
115 * @static
116 * @access public
117 */
118 static function &taskTitles() {
119 self::tasks();
120 $titles = array();
121 foreach (self::$_tasks as $id => $value) {
122 // skip Print Membership task
123 if ($id != 2) {
124 $titles[$id] = $value['title'];
125 }
126 }
127 return $titles;
128 }
129
130 /**
131 * show tasks selectively based on the permission level
132 * of the user
133 *
134 * @param int $permission
135 *
136 * @return array set of tasks that are valid for the user
137 * @access public
138 */
139 static function &permissionedTaskTitles($permission) {
140 $tasks = array();
141 if (($permission == CRM_Core_Permission::EDIT)
142 || CRM_Core_Permission::check('edit memberships')
143 ) {
144 $tasks = self::taskTitles();
145 }
146 else {
147 $tasks = array(
148 3 => self::$_tasks[3]['title'],
149 4 => self::$_tasks[4]['title'],
150 );
151 //CRM-4418,
152 if (CRM_Core_Permission::check('delete in CiviMember')) {
153 $tasks[1] = self::$_tasks[1]['title'];
154 }
155 }
156 return $tasks;
157 }
158
159 /**
160 * These tasks are the core set of tasks that the user can perform
161 * on members
162 *
163 * @param int $value
164 *
165 * @return array the set of tasks for a group of members
166 * @static
167 * @access public
168 */
169 static function getTask($value) {
170 self::tasks();
171 if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
172 // make the print task by default
173 $value = 2;
174 }
175 return array(
176 self::$_tasks[$value]['class'],
177 self::$_tasks[$value]['result'],
178 );
179 }
180}
181