Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | * $Id$ |
17 | * | |
18 | */ | |
19 | ||
20 | /** | |
21 | * This class provides the functionality for batch profile update for event participations | |
22 | */ | |
23 | class CRM_Event_Form_Task_PickProfile extends CRM_Event_Form_Task { | |
24 | ||
25 | /** | |
66f9e52b | 26 | * The title of the group. |
6a488035 TO |
27 | * |
28 | * @var string | |
29 | */ | |
30 | protected $_title; | |
31 | ||
32 | /** | |
66f9e52b | 33 | * Maximum event participations that should be allowed to update. |
90b461f1 | 34 | * @var int |
6a488035 TO |
35 | */ |
36 | protected $_maxParticipations = 100; | |
37 | ||
38 | /** | |
66f9e52b | 39 | * Variable to store redirect path. |
90b461f1 | 40 | * @var string |
6a488035 TO |
41 | */ |
42 | protected $_userContext; | |
43 | ||
44 | /** | |
66f9e52b | 45 | * Build all the data structures needed to build the form. |
6a488035 TO |
46 | * |
47 | * @return void | |
03e04002 | 48 | */ |
00be9182 | 49 | public function preProcess() { |
c490a46a | 50 | // initialize the task and row fields |
6a488035 TO |
51 | parent::preProcess(); |
52 | ||
53 | $session = CRM_Core_Session::singleton(); | |
54 | $this->_userContext = $session->readUserContext(); | |
55 | ||
b581842f | 56 | CRM_Utils_System::setTitle(ts('Update multiple participants')); |
6a488035 TO |
57 | |
58 | $validate = FALSE; | |
59 | //validations | |
60 | if (count($this->_participantIds) > $this->_maxParticipations) { | |
b581842f | 61 | CRM_Core_Session::setStatus("The maximum number of records you can select for Update multiple participants is {$this->_maxParticipations}. You have selected " . count($this->_participantIds) . ". Please select fewer participantions from your search results and try again."); |
6a488035 TO |
62 | $validate = TRUE; |
63 | } | |
64 | ||
65 | // then redirect | |
66 | if ($validate) { | |
67 | CRM_Utils_System::redirect($this->_userContext); | |
68 | } | |
69 | } | |
70 | ||
71 | /** | |
66f9e52b | 72 | * Build the form object. |
6a488035 | 73 | * |
6a488035 TO |
74 | * |
75 | * @return void | |
76 | */ | |
00be9182 | 77 | public function buildQuickForm() { |
be2fb01f | 78 | $types = ['Participant']; |
6a488035 TO |
79 | $profiles = CRM_Core_BAO_UFGroup::getProfiles($types, TRUE); |
80 | ||
81 | if (empty($profiles)) { | |
b581842f | 82 | CRM_Core_Session::setStatus("To use Update multiple 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'."); |
6a488035 TO |
83 | CRM_Utils_System::redirect($this->_userContext); |
84 | } | |
85 | ||
86 | $ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'), | |
be2fb01f | 87 | [ |
acb1052e | 88 | '' => ts('- select profile -'), |
be2fb01f | 89 | ] + $profiles, TRUE |
6a488035 | 90 | ); |
f212d37d | 91 | $this->addDefaultButtons(ts('Continue')); |
6a488035 TO |
92 | } |
93 | ||
94 | /** | |
66f9e52b | 95 | * Add local and global form rules. |
6a488035 | 96 | * |
6a488035 TO |
97 | * |
98 | * @return void | |
99 | */ | |
00be9182 | 100 | public function addRules() { |
be2fb01f | 101 | $this->addFormRule(['CRM_Event_Form_Task_PickProfile', 'formRule']); |
6a488035 TO |
102 | } |
103 | ||
104 | /** | |
66f9e52b | 105 | * Global validation rules for the form. |
6a488035 | 106 | * |
d4dd1e85 TO |
107 | * @param array $fields |
108 | * Posted values of the form. | |
6a488035 | 109 | * |
a6c01b45 CW |
110 | * @return array |
111 | * list of errors to be posted back to the form | |
6a488035 | 112 | */ |
00be9182 | 113 | public static function formRule($fields) { |
6a488035 TO |
114 | return TRUE; |
115 | } | |
116 | ||
117 | /** | |
66f9e52b | 118 | * Process the form after the input has been submitted and validated. |
6a488035 | 119 | * |
6a488035 | 120 | * |
355ba699 | 121 | * @return void |
6a488035 TO |
122 | */ |
123 | public function postProcess() { | |
124 | $params = $this->exportValues(); | |
125 | ||
126 | $this->set('ufGroupId', $params['uf_group_id']); | |
127 | ||
128 | // also reset the batch page so it gets new values from the db | |
129 | $this->controller->resetPage('Batch'); | |
130 | } | |
96025800 | 131 | |
6a488035 | 132 | } |