Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
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 | * This class provides the functionality for batch profile update for event participations | |
38 | */ | |
39 | class CRM_Event_Form_Task_PickProfile extends CRM_Event_Form_Task { | |
40 | ||
41 | /** | |
100fef9d | 42 | * The title of the group |
6a488035 TO |
43 | * |
44 | * @var string | |
45 | */ | |
46 | protected $_title; | |
47 | ||
48 | /** | |
100fef9d | 49 | * Maximum event participations that should be allowed to update |
6a488035 TO |
50 | * |
51 | */ | |
52 | protected $_maxParticipations = 100; | |
53 | ||
54 | /** | |
100fef9d | 55 | * Variable to store redirect path |
6a488035 TO |
56 | * |
57 | */ | |
58 | protected $_userContext; | |
59 | ||
60 | /** | |
100fef9d | 61 | * Build all the data structures needed to build the form |
6a488035 TO |
62 | * |
63 | * @return void | |
64 | * @access public | |
03e04002 | 65 | */ |
6a488035 | 66 | function preProcess() { |
c490a46a | 67 | // initialize the task and row fields |
6a488035 TO |
68 | parent::preProcess(); |
69 | ||
70 | $session = CRM_Core_Session::singleton(); | |
71 | $this->_userContext = $session->readUserContext(); | |
72 | ||
73 | CRM_Utils_System::setTitle(ts('Batch Update for Event Participants')); | |
74 | ||
75 | $validate = FALSE; | |
76 | //validations | |
77 | if (count($this->_participantIds) > $this->_maxParticipations) { | |
78 | CRM_Core_Session::setStatus("The maximum number of event participations you can select for Batch Update is {$this->_maxParticipations}. You have selected " . count($this->_participantIds) . ". Please select fewer participantions from your search results and try again."); | |
79 | $validate = TRUE; | |
80 | } | |
81 | ||
82 | // then redirect | |
83 | if ($validate) { | |
84 | CRM_Utils_System::redirect($this->_userContext); | |
85 | } | |
86 | } | |
87 | ||
88 | /** | |
c490a46a | 89 | * Build the form object |
6a488035 TO |
90 | * |
91 | * @access public | |
92 | * | |
93 | * @return void | |
94 | */ | |
95 | function buildQuickForm() { | |
96 | $types = array('Participant'); | |
97 | $profiles = CRM_Core_BAO_UFGroup::getProfiles($types, TRUE); | |
98 | ||
99 | if (empty($profiles)) { | |
100 | CRM_Core_Session::setStatus("To use Batch Update for event participants, you need to configure a profile containing only Participant fields (e.g. Participant Status, Participant Role, etc.). Configure a profile at 'Administer CiviCRM >> Customize >> CiviCRM Profile'."); | |
101 | CRM_Utils_System::redirect($this->_userContext); | |
102 | } | |
103 | ||
104 | $ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'), | |
105 | array( | |
106 | '' => ts('- select profile -')) + $profiles, TRUE | |
107 | ); | |
108 | $this->addDefaultButtons(ts('Continue >>')); | |
109 | } | |
110 | ||
111 | /** | |
112 | * Add local and global form rules | |
113 | * | |
114 | * @access protected | |
115 | * | |
116 | * @return void | |
117 | */ | |
118 | function addRules() { | |
119 | $this->addFormRule(array('CRM_Event_Form_Task_PickProfile', 'formRule')); | |
120 | } | |
121 | ||
122 | /** | |
100fef9d | 123 | * Global validation rules for the form |
6a488035 TO |
124 | * |
125 | * @param array $fields posted values of the form | |
126 | * | |
127 | * @return array list of errors to be posted back to the form | |
128 | * @static | |
129 | * @access public | |
130 | */ | |
131 | static function formRule($fields) { | |
132 | return TRUE; | |
133 | } | |
134 | ||
135 | /** | |
100fef9d | 136 | * Process the form after the input has been submitted and validated |
6a488035 TO |
137 | * |
138 | * @access public | |
139 | * | |
355ba699 | 140 | * @return void |
6a488035 TO |
141 | */ |
142 | public function postProcess() { | |
143 | $params = $this->exportValues(); | |
144 | ||
145 | $this->set('ufGroupId', $params['uf_group_id']); | |
146 | ||
147 | // also reset the batch page so it gets new values from the db | |
148 | $this->controller->resetPage('Batch'); | |
149 | } | |
6a488035 TO |
150 | } |
151 |