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