Merge pull request #6949 from totten/master-report-dashlet
[civicrm-core.git] / CRM / Campaign / Task.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
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 */
33
34 /**
35 * class to represent the actions that can be performed on a group of voters.
36 *
37 * Used by the search forms.
38 */
39 class CRM_Campaign_Task {
40 const INTERVIEW = 1, RESERVE = 2, RELEASE = 3, PRINT_VOTERS = 4;
41
42 /**
43 * The task array
44 *
45 * @var array
46 */
47 static $_tasks = NULL;
48
49 /**
50 * The optional task array
51 *
52 * @var array
53 */
54 static $_optionalTasks = NULL;
55
56 /**
57 * These tasks are the core set of tasks that the user can perform
58 * on a voter / group of voters
59 *
60 * @return array
61 * the set of tasks for a group of voters.
62 */
63 public static function &tasks() {
64 if (!(self::$_tasks)) {
65 self::$_tasks = array(
66 1 => array(
67 'title' => ts('Record Respondents Interview'),
68 'class' => array(
69 'CRM_Campaign_Form_Task_Interview',
70 'CRM_Campaign_Form_Task_Release',
71 ),
72 'result' => FALSE,
73 ),
74 2 => array(
75 'title' => ts('Reserve Respondents'),
76 'class' => array(
77 'CRM_Campaign_Form_Task_Reserve',
78 'CRM_Campaign_Form_Task_Interview',
79 'CRM_Campaign_Form_Task_Release',
80 ),
81 'result' => FALSE,
82 ),
83 3 => array(
84 'title' => ts('Release Respondents'),
85 'class' => 'CRM_Campaign_Form_Task_Release',
86 'result' => FALSE,
87 ),
88 4 => array(
89 'title' => ts('Print Respondents'),
90 'class' => 'CRM_Campaign_Form_Task_Print',
91 'result' => FALSE,
92 ),
93 );
94 }
95
96 CRM_Utils_Hook::searchTasks('campaign', self::$_tasks);
97
98 asort(self::$_tasks);
99
100 return self::$_tasks;
101 }
102
103 /**
104 * These tasks are the core set of task titles
105 * on voters.
106 *
107 * @return array
108 * the set of task titles
109 */
110 public static function &taskTitles() {
111 self::tasks();
112 $titles = array();
113 foreach (self::$_tasks as $id => $value) {
114 $titles[$id] = $value['title'];
115 }
116
117 return $titles;
118 }
119
120 /**
121 * Show tasks selectively based on the permission level
122 * of the user
123 *
124 * @param int $permission
125 *
126 * @return array
127 * set of tasks that are valid for the user
128 */
129 public static function &permissionedTaskTitles($permission) {
130 $tasks = self::taskTitles();
131
132 return $tasks;
133 }
134
135 /**
136 * These tasks are the core set of tasks that the user can perform
137 * on voters.
138 *
139 * @param int $value
140 *
141 * @return array
142 * the set of tasks for a group of voters.
143 */
144 public static function getTask($value) {
145 self::tasks();
146 if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
147 // make the interview task by default
148 $value = 1;
149 }
150
151 return array(
152 self::$_tasks[$value]['class'],
153 self::$_tasks[$value]['result'],
154 );
155 }
156
157 }