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