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 | */ |
17 | ||
18 | /** | |
19 | * This class provides the functionality for batch profile update for event participations | |
20 | */ | |
21 | class CRM_Event_Form_Task_PickProfile extends CRM_Event_Form_Task { | |
22 | ||
23 | /** | |
66f9e52b | 24 | * The title of the group. |
6a488035 TO |
25 | * |
26 | * @var string | |
27 | */ | |
28 | protected $_title; | |
29 | ||
30 | /** | |
66f9e52b | 31 | * Maximum event participations that should be allowed to update. |
90b461f1 | 32 | * @var int |
6a488035 TO |
33 | */ |
34 | protected $_maxParticipations = 100; | |
35 | ||
36 | /** | |
66f9e52b | 37 | * Variable to store redirect path. |
90b461f1 | 38 | * @var string |
6a488035 TO |
39 | */ |
40 | protected $_userContext; | |
41 | ||
42 | /** | |
66f9e52b | 43 | * Build all the data structures needed to build the form. |
6a488035 TO |
44 | * |
45 | * @return void | |
03e04002 | 46 | */ |
00be9182 | 47 | public function preProcess() { |
c490a46a | 48 | // initialize the task and row fields |
6a488035 TO |
49 | parent::preProcess(); |
50 | ||
51 | $session = CRM_Core_Session::singleton(); | |
52 | $this->_userContext = $session->readUserContext(); | |
53 | ||
b581842f | 54 | CRM_Utils_System::setTitle(ts('Update multiple participants')); |
6a488035 TO |
55 | |
56 | $validate = FALSE; | |
57 | //validations | |
58 | if (count($this->_participantIds) > $this->_maxParticipations) { | |
b581842f | 59 | 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 |
60 | $validate = TRUE; |
61 | } | |
62 | ||
63 | // then redirect | |
64 | if ($validate) { | |
65 | CRM_Utils_System::redirect($this->_userContext); | |
66 | } | |
67 | } | |
68 | ||
69 | /** | |
66f9e52b | 70 | * Build the form object. |
6a488035 | 71 | * |
6a488035 TO |
72 | * |
73 | * @return void | |
74 | */ | |
00be9182 | 75 | public function buildQuickForm() { |
be2fb01f | 76 | $types = ['Participant']; |
6a488035 TO |
77 | $profiles = CRM_Core_BAO_UFGroup::getProfiles($types, TRUE); |
78 | ||
79 | if (empty($profiles)) { | |
b581842f | 80 | 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 |
81 | CRM_Utils_System::redirect($this->_userContext); |
82 | } | |
83 | ||
84 | $ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'), | |
be2fb01f | 85 | [ |
acb1052e | 86 | '' => ts('- select profile -'), |
be2fb01f | 87 | ] + $profiles, TRUE |
6a488035 | 88 | ); |
f212d37d | 89 | $this->addDefaultButtons(ts('Continue')); |
6a488035 TO |
90 | } |
91 | ||
92 | /** | |
66f9e52b | 93 | * Add local and global form rules. |
6a488035 | 94 | * |
6a488035 TO |
95 | * |
96 | * @return void | |
97 | */ | |
00be9182 | 98 | public function addRules() { |
be2fb01f | 99 | $this->addFormRule(['CRM_Event_Form_Task_PickProfile', 'formRule']); |
6a488035 TO |
100 | } |
101 | ||
102 | /** | |
66f9e52b | 103 | * Global validation rules for the form. |
6a488035 | 104 | * |
d4dd1e85 TO |
105 | * @param array $fields |
106 | * Posted values of the form. | |
6a488035 | 107 | * |
a6c01b45 CW |
108 | * @return array |
109 | * list of errors to be posted back to the form | |
6a488035 | 110 | */ |
00be9182 | 111 | public static function formRule($fields) { |
6a488035 TO |
112 | return TRUE; |
113 | } | |
114 | ||
115 | /** | |
66f9e52b | 116 | * Process the form after the input has been submitted and validated. |
6a488035 | 117 | * |
6a488035 | 118 | * |
355ba699 | 119 | * @return void |
6a488035 TO |
120 | */ |
121 | public function postProcess() { | |
122 | $params = $this->exportValues(); | |
123 | ||
124 | $this->set('ufGroupId', $params['uf_group_id']); | |
125 | ||
126 | // also reset the batch page so it gets new values from the db | |
127 | $this->controller->resetPage('Batch'); | |
128 | } | |
96025800 | 129 | |
6a488035 | 130 | } |