INFRA-132 - Comment grammar cleanup
[civicrm-core.git] / CRM / Member / Task.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
06b69b18 31 * @copyright CiviCRM LLC (c) 2004-2014
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
49 * @static
50 */
51 static $_tasks = NULL;
52
53 /**
100fef9d 54 * The optional task array
6a488035
TO
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
6a488035 67 */
00be9182 68 public static function &tasks() {
6a488035
TO
69 if (!(self::$_tasks)) {
70 self::$_tasks = array(
23546577 71 1 => array(
04c56698 72 'title' => ts('Delete Memberships'),
6a488035
TO
73 'class' => 'CRM_Member_Form_Task_Delete',
74 'result' => FALSE,
75 ),
23546577
CW
76 2 => array(
77 'title' => ts('Print Selected Rows'),
6a488035
TO
78 'class' => 'CRM_Member_Form_Task_Print',
79 'result' => FALSE,
80 ),
23546577
CW
81 3 => array(
82 'title' => ts('Export Members'),
6a488035
TO
83 'class' => array(
84 'CRM_Export_Form_Select',
85 'CRM_Export_Form_Map',
86 ),
87 'result' => FALSE,
88 ),
23546577
CW
89 4 => array(
90 'title' => ts('Send Email to Contacts'),
6a488035
TO
91 'class' => 'CRM_Member_Form_Task_Email',
92 'result' => TRUE,
93 ),
23546577
CW
94 5 => array(
95 'title' => ts('Batch Update Members Via Profile'),
6a488035
TO
96 'class' => array(
97 'CRM_Member_Form_Task_PickProfile',
98 'CRM_Member_Form_Task_Batch',
99 ),
100 'result' => TRUE,
101 ),
23546577
CW
102 6 => array(
103 'title' => ts('Mailing Labels'),
2d3e3c7b 104 'class' => array(
105 'CRM_Member_Form_Task_Label',
106 ),
107 'result' => TRUE,
108 ),
23546577
CW
109 7 => array(
110 'title' => ts('Print PDF Letters for Memberships'),
2d3e3c7b 111 'class' => 'CRM_Member_Form_Task_PDFLetter',
112 'result' => FALSE,
113 ),
6a488035
TO
114 );
115
116 //CRM-4418, check for delete
117 if (!CRM_Core_Permission::check('delete in CiviMember')) {
118 unset(self::$_tasks[1]);
119 }
447c72b5 120 //CRM-12920 - check for edit permission
481a74f4 121 if (!CRM_Core_Permission::check('edit memberships')) {
447c72b5
PC
122 unset(self::$_tasks[5]);
123 }
6a488035
TO
124 }
125 CRM_Utils_Hook::searchTasks('membership', self::$_tasks);
126 asort(self::$_tasks);
127 return self::$_tasks;
128 }
129
130 /**
131 * These tasks are the core set of task titles
132 * on members
133 *
134 * @return array the set of task titles
135 * @static
6a488035 136 */
00be9182 137 public static function &taskTitles() {
6a488035
TO
138 self::tasks();
139 $titles = array();
140 foreach (self::$_tasks as $id => $value) {
e341bbee 141 $titles[$id] = $value['title'];
6a488035
TO
142 }
143 return $titles;
144 }
145
146 /**
100fef9d 147 * Show tasks selectively based on the permission level
6a488035
TO
148 * of the user
149 *
150 * @param int $permission
151 *
152 * @return array set of tasks that are valid for the user
6a488035 153 */
00be9182 154 public static function &permissionedTaskTitles($permission) {
6a488035
TO
155 $tasks = array();
156 if (($permission == CRM_Core_Permission::EDIT)
157 || CRM_Core_Permission::check('edit memberships')
158 ) {
159 $tasks = self::taskTitles();
160 }
161 else {
162 $tasks = array(
163 3 => self::$_tasks[3]['title'],
164 4 => self::$_tasks[4]['title'],
165 );
166 //CRM-4418,
167 if (CRM_Core_Permission::check('delete in CiviMember')) {
168 $tasks[1] = self::$_tasks[1]['title'];
169 }
170 }
171 return $tasks;
172 }
173
174 /**
175 * These tasks are the core set of tasks that the user can perform
176 * on members
177 *
178 * @param int $value
179 *
180 * @return array the set of tasks for a group of members
181 * @static
6a488035 182 */
00be9182 183 public static function getTask($value) {
6a488035
TO
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}