Merge pull request #23221 from eileenmcnaughton/mapField
[civicrm-core.git] / CRM / Event / Form / Task / PickProfile.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
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 /**
24 * The title of the group.
25 *
26 * @var string
27 */
28 protected $_title;
29
30 /**
31 * Maximum event participations that should be allowed to update.
32 * @var int
33 */
34 protected $_maxParticipations = 100;
35
36 /**
37 * Variable to store redirect path.
38 * @var string
39 */
40 protected $_userContext;
41
42 /**
43 * Build all the data structures needed to build the form.
44 *
45 * @return void
46 */
47 public function preProcess() {
48 // initialize the task and row fields
49 parent::preProcess();
50
51 $session = CRM_Core_Session::singleton();
52 $this->_userContext = $session->readUserContext();
53
54 $this->setTitle(ts('Update multiple participants'));
55
56 $validate = FALSE;
57 //validations
58 if (count($this->_participantIds) > $this->_maxParticipations) {
59 CRM_Core_Session::setStatus(ts("The maximum number of records you can select for Update multiple participants is %1. You have selected %2. Please select fewer participants from your search results and try again.", [
60 1 => $this->_maxParticipations,
61 2 => count($this->_participantIds),
62 ]));
63 $validate = TRUE;
64 }
65
66 // then redirect
67 if ($validate) {
68 CRM_Utils_System::redirect($this->_userContext);
69 }
70 }
71
72 /**
73 * Build the form object.
74 *
75 *
76 * @return void
77 */
78 public function buildQuickForm() {
79 $types = ['Participant'];
80 $profiles = CRM_Core_BAO_UFGroup::getProfiles($types, TRUE);
81
82 if (empty($profiles)) {
83 CRM_Core_Session::setStatus(ts("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'."));
84 CRM_Utils_System::redirect($this->_userContext);
85 }
86
87 $ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'),
88 [
89 '' => ts('- select profile -'),
90 ] + $profiles, TRUE
91 );
92 $this->addDefaultButtons(ts('Continue'));
93 }
94
95 /**
96 * Add local and global form rules.
97 *
98 *
99 * @return void
100 */
101 public function addRules() {
102 $this->addFormRule(['CRM_Event_Form_Task_PickProfile', 'formRule']);
103 }
104
105 /**
106 * Global validation rules for the form.
107 *
108 * @param array $fields
109 * Posted values of the form.
110 *
111 * @return array
112 * list of errors to be posted back to the form
113 */
114 public static function formRule($fields) {
115 return TRUE;
116 }
117
118 /**
119 * Process the form after the input has been submitted and validated.
120 *
121 *
122 * @return void
123 */
124 public function postProcess() {
125 $params = $this->exportValues();
126
127 $this->set('ufGroupId', $params['uf_group_id']);
128
129 // also reset the batch page so it gets new values from the db
130 $this->controller->resetPage('Batch');
131 }
132
133 }