fix re-use of variable
[civicrm-core.git] / CRM / Campaign / 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
38 * group of voters.
39 * used by the search forms
40 *
41 */
42class CRM_Campaign_Task {
7da04cde 43 const INTERVIEW = 1, RESERVE = 2, RELEASE = 3, PRINT_VOTERS = 4;
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 voter / group of voters
64 *
a6c01b45
CW
65 * @return array
66 * the set of tasks for a group of voters.
6a488035 67 * @static
6a488035 68 */
00be9182 69 public static function &tasks() {
6a488035 70 if (!(self::$_tasks)) {
94880218 71 self::$_tasks = array(
353ffa53
TO
72 1 => array(
73 'title' => ts('Record Respondents Interview'),
6a488035
TO
74 'class' => array(
75 'CRM_Campaign_Form_Task_Interview',
76 'CRM_Campaign_Form_Task_Release',
77 ),
78 'result' => FALSE,
79 ),
23546577
CW
80 2 => array(
81 'title' => ts('Reserve Respondents'),
6a488035
TO
82 'class' => array(
83 'CRM_Campaign_Form_Task_Reserve',
84 'CRM_Campaign_Form_Task_Interview',
85 'CRM_Campaign_Form_Task_Release',
86 ),
87 'result' => FALSE,
88 ),
23546577
CW
89 3 => array(
90 'title' => ts('Release Respondents'),
6a488035
TO
91 'class' => 'CRM_Campaign_Form_Task_Release',
92 'result' => FALSE,
93 ),
23546577
CW
94 4 => array(
95 'title' => ts('Print Respondents'),
6a488035
TO
96 'class' => 'CRM_Campaign_Form_Task_Print',
97 'result' => FALSE,
98 ),
99 );
100 }
101
102 CRM_Utils_Hook::searchTasks('campaign', self::$_tasks);
103
104 asort(self::$_tasks);
105
106 return self::$_tasks;
107 }
108
109 /**
110 * These tasks are the core set of task titles
111 * on voters.
112 *
a6c01b45
CW
113 * @return array
114 * the set of task titles
6a488035 115 * @static
6a488035 116 */
00be9182 117 public static function &taskTitles() {
6a488035
TO
118 self::tasks();
119 $titles = array();
120 foreach (self::$_tasks as $id => $value) {
121 $titles[$id] = $value['title'];
122 }
123
124 return $titles;
125 }
126
127 /**
100fef9d 128 * Show tasks selectively based on the permission level
6a488035
TO
129 * of the user
130 *
131 * @param int $permission
132 *
a6c01b45
CW
133 * @return array
134 * set of tasks that are valid for the user
6a488035 135 */
00be9182 136 public static function &permissionedTaskTitles($permission) {
6a488035
TO
137 $tasks = self::taskTitles();
138
139 return $tasks;
140 }
141
142 /**
143 * These tasks are the core set of tasks that the user can perform
144 * on voters.
145 *
146 * @param int $value
147 *
a6c01b45
CW
148 * @return array
149 * the set of tasks for a group of voters.
6a488035 150 * @static
6a488035 151 */
00be9182 152 public static function getTask($value) {
6a488035
TO
153 self::tasks();
154 if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
155 // make the interview task by default
156 $value = 1;
157 }
158
159 return array(
160 self::$_tasks[$value]['class'],
161 self::$_tasks[$value]['result'],
162 );
163 }
164}