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 | /** | |
6a488035 | 13 | * @package CRM |
ca5cec67 | 14 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
15 | */ |
16 | ||
17 | /** | |
3bdf1f3a | 18 | * This class generates form components for processing Event. |
6a488035 TO |
19 | */ |
20 | class CRM_Event_Form_ManageEvent_EventInfo extends CRM_Event_Form_ManageEvent { | |
21 | ||
22 | /** | |
66f9e52b | 23 | * Event type. |
90b461f1 | 24 | * @var int |
6a488035 TO |
25 | */ |
26 | protected $_eventType = NULL; | |
27 | ||
28 | /** | |
66f9e52b | 29 | * Set variables up before form is built. |
6a488035 | 30 | */ |
00be9182 | 31 | public function preProcess() { |
2a4e505f | 32 | parent::preProcess(); |
e4b857f8 | 33 | $this->setSelectedChild('settings'); |
6a488035 | 34 | |
8c605c27 MD |
35 | $entityID = $this->_id ?: $this->_templateId; |
36 | if ($entityID) { | |
37 | $this->assign('entityID', $entityID); | |
6a488035 | 38 | $eventType = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', |
8c605c27 | 39 | $entityID, |
6a488035 TO |
40 | 'event_type_id' |
41 | ); | |
42 | } | |
43 | else { | |
44 | $eventType = 'null'; | |
45 | } | |
46 | ||
47 | $showLocation = FALSE; | |
48 | // when custom data is included in this page | |
a7488080 | 49 | if (!empty($_POST['hidden_custom'])) { |
6a488035 TO |
50 | $this->set('type', 'Event'); |
51 | $this->set('subType', CRM_Utils_Array::value('event_type_id', $_POST)); | |
d6dd7344 | 52 | $this->assign('customDataSubType', CRM_Utils_Array::value('event_type_id', $_POST)); |
5fdec754 | 53 | $this->set('entityId', $entityID); |
6a488035 | 54 | |
5fdec754 | 55 | CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_eventType, 1, 'Event', $entityID); |
6a488035 TO |
56 | CRM_Custom_Form_CustomData::buildQuickForm($this); |
57 | CRM_Custom_Form_CustomData::setDefaultValues($this); | |
58 | } | |
59 | } | |
60 | ||
61 | /** | |
3bdf1f3a | 62 | * Set default values for the form. |
6a488035 | 63 | * |
3bdf1f3a | 64 | * For edit/view mode he default values are retrieved from the database. |
6a488035 | 65 | */ |
00be9182 | 66 | public function setDefaultValues() { |
6a488035 TO |
67 | $defaults = parent::setDefaultValues(); |
68 | ||
69 | // in update mode, we need to set custom data subtype to tpl | |
a7488080 | 70 | if (!empty($defaults['event_type_id'])) { |
6a488035 TO |
71 | $this->assign('customDataSubType', $defaults['event_type_id']); |
72 | } | |
73 | ||
74 | $this->_showHide = new CRM_Core_ShowHideBlocks(); | |
75 | // Show waitlist features or event_full_text if max participants set | |
a7488080 | 76 | if (!empty($defaults['max_participants'])) { |
6a488035 | 77 | $this->_showHide->addShow('id-waitlist'); |
a7488080 | 78 | if (!empty($defaults['has_waitlist'])) { |
6a488035 TO |
79 | $this->_showHide->addShow('id-waitlist-text'); |
80 | $this->_showHide->addHide('id-event_full'); | |
81 | } | |
82 | else { | |
83 | $this->_showHide->addHide('id-waitlist-text'); | |
84 | $this->_showHide->addShow('id-event_full'); | |
85 | } | |
86 | } | |
87 | else { | |
88 | $this->_showHide->addHide('id-event_full'); | |
89 | $this->_showHide->addHide('id-waitlist'); | |
90 | $this->_showHide->addHide('id-waitlist-text'); | |
91 | } | |
92 | ||
93 | $this->_showHide->addToTemplate(); | |
94 | $this->assign('elemType', 'table-row'); | |
95 | ||
96 | $this->assign('description', CRM_Utils_Array::value('description', $defaults)); | |
97 | ||
98 | // Provide suggested text for event full and waitlist messages if they're empty | |
99 | $defaults['event_full_text'] = CRM_Utils_Array::value('event_full_text', $defaults, ts('This event is currently full.')); | |
100 | ||
101 | $defaults['waitlist_text'] = CRM_Utils_Array::value('waitlist_text', $defaults, ts('This event is currently full. However you can register now and get added to a waiting list. You will be notified if spaces become available.')); | |
10672453 | 102 | $defaults['template_id'] = $this->_templateId; |
cedee7b0 | 103 | |
6a488035 TO |
104 | return $defaults; |
105 | } | |
106 | ||
107 | /** | |
66f9e52b | 108 | * Build the form object. |
6a488035 TO |
109 | */ |
110 | public function buildQuickForm() { | |
6a488035 TO |
111 | //need to assign custom data type and subtype to the template |
112 | $this->assign('customDataType', 'Event'); | |
113 | if ($this->_eventType) { | |
114 | $this->assign('customDataSubType', $this->_eventType); | |
115 | } | |
6a488035 TO |
116 | |
117 | $this->_first = TRUE; | |
118 | $this->applyFilter('__ALL__', 'trim'); | |
119 | $attributes = CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event'); | |
120 | ||
121 | if ($this->_isTemplate) { | |
122 | $this->add('text', 'template_title', ts('Template Title'), $attributes['template_title'], TRUE); | |
123 | } | |
124 | ||
125 | if ($this->_action & CRM_Core_Action::ADD) { | |
126 | $eventTemplates = CRM_Event_PseudoConstant::eventTemplates(); | |
127 | if (CRM_Utils_System::isNull($eventTemplates) && !$this->_isTemplate) { | |
be2fb01f CW |
128 | $url = CRM_Utils_System::url('civicrm/admin/eventTemplate', ['reset' => 1]); |
129 | CRM_Core_Session::setStatus(ts('If you find that you are creating multiple events with similar settings, you may want to use the <a href="%1">Event Templates</a> feature to streamline your workflow.', [1 => $url]), ts('Tip'), 'info'); | |
6a488035 TO |
130 | } |
131 | if (!CRM_Utils_System::isNull($eventTemplates)) { | |
be2fb01f | 132 | $this->add('select', 'template_id', ts('From Template'), ['' => ts('- select -')] + $eventTemplates, FALSE, ['class' => 'crm-select2 huge']); |
6a488035 | 133 | } |
bfd83a87 CW |
134 | // Make sure this form redirects properly |
135 | $this->preventAjaxSubmit(); | |
6a488035 TO |
136 | } |
137 | ||
138 | // add event title, make required if this is not a template | |
139 | $this->add('text', 'title', ts('Event Title'), $attributes['event_title'], !$this->_isTemplate); | |
140 | ||
e1462487 | 141 | $this->addSelect('event_type_id', |
be2fb01f | 142 | ['onChange' => "CRM.buildCustomData( 'Event', this.value );"], |
e1462487 | 143 | TRUE |
6a488035 TO |
144 | ); |
145 | ||
146 | //CRM-7362 --add campaigns. | |
147 | $campaignId = NULL; | |
148 | if ($this->_id) { | |
149 | $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'campaign_id'); | |
150 | } | |
151 | CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId); | |
152 | ||
be2fb01f | 153 | $this->addSelect('default_role_id', [], TRUE); |
6a488035 | 154 | |
be2fb01f | 155 | $this->addSelect('participant_listing_id', ['placeholder' => ts('Disabled'), 'option_url' => NULL]); |
6a488035 TO |
156 | |
157 | $this->add('textarea', 'summary', ts('Event Summary'), $attributes['summary']); | |
be2fb01f | 158 | $this->add('wysiwyg', 'description', ts('Complete Description'), $attributes['event_description'] + ['preset' => 'civievent']); |
0781df9b | 159 | $this->addElement('checkbox', 'is_public', ts('Public Event')); |
77b95c29 | 160 | $this->addElement('checkbox', 'is_share', ts('Add footer region with Twitter, Facebook and LinkedIn share buttons and scripts?')); |
0781df9b | 161 | $this->addElement('checkbox', 'is_map', ts('Include Map to Event Location')); |
6a488035 | 162 | |
67cc69d7 | 163 | $this->add('datepicker', 'start_date', ts('Start'), [], !$this->_isTemplate, ['time' => TRUE]); |
8b827219 | 164 | $this->add('datepicker', 'end_date', ts('End'), [], FALSE, ['time' => TRUE]); |
6a488035 | 165 | |
d70ada2a | 166 | $this->add('number', 'max_participants', ts('Max Number of Participants'), |
be2fb01f | 167 | ['onchange' => "if (this.value != '') {cj('#id-waitlist').show(); showHideByValue('has_waitlist','0','id-waitlist-text','table-row','radio',false); showHideByValue('has_waitlist','0','id-event_full','table-row','radio',true); return;} else {cj('#id-event_full, #id-waitlist, #id-waitlist-text').hide(); return;}"] |
6a488035 TO |
168 | ); |
169 | $this->addRule('max_participants', ts('Max participants should be a positive number'), 'positiveInteger'); | |
170 | ||
171 | $participantStatuses = CRM_Event_PseudoConstant::participantStatus(); | |
172 | $waitlist = 0; | |
173 | if (in_array('On waitlist', $participantStatuses) and in_array('Pending from waitlist', $participantStatuses)) { | |
be2fb01f | 174 | $this->addElement('checkbox', 'has_waitlist', ts('Offer a Waitlist?'), NULL, ['onclick' => "showHideByValue('has_waitlist','0','id-event_full','table-row','radio',true); showHideByValue('has_waitlist','0','id-waitlist-text','table-row','radio',false);"]); |
6a488035 TO |
175 | $this->add('textarea', 'waitlist_text', ts('Waitlist Message'), $attributes['waitlist_text']); |
176 | $waitlist = 1; | |
177 | } | |
178 | $this->assign('waitlist', $waitlist); | |
179 | ||
180 | $this->add('textarea', 'event_full_text', ts('Message if Event Is Full'), $attributes['event_full_text']); | |
181 | ||
182 | $this->addElement('checkbox', 'is_active', ts('Is this Event Active?')); | |
183 | ||
be2fb01f | 184 | $this->addFormRule(['CRM_Event_Form_ManageEvent_EventInfo', 'formRule']); |
6a488035 TO |
185 | |
186 | parent::buildQuickForm(); | |
187 | } | |
188 | ||
189 | /** | |
66f9e52b | 190 | * Global validation rules for the form. |
6a488035 | 191 | * |
c490a46a | 192 | * @param array $values |
6a488035 | 193 | * |
a6c01b45 CW |
194 | * @return array |
195 | * list of errors to be posted back to the form | |
6a488035 | 196 | */ |
00be9182 | 197 | public static function formRule($values) { |
be2fb01f | 198 | $errors = []; |
6a488035 | 199 | |
67cc69d7 J |
200 | if (!empty($values['end_date']) && ($values['end_date'] < $values['start_date'])) { |
201 | $errors['end_date'] = ts('End date should be after Start date.'); | |
6a488035 TO |
202 | } |
203 | ||
204 | //CRM-4286 | |
205 | if (strstr($values['title'], '/')) { | |
206 | $errors['title'] = ts("Please do not use '/' in Event Title."); | |
207 | } | |
208 | ||
209 | return $errors; | |
210 | } | |
211 | ||
212 | /** | |
66f9e52b | 213 | * Process the form submission. |
6a488035 TO |
214 | */ |
215 | public function postProcess() { | |
8c605c27 | 216 | $params = array_merge($this->controller->exportValues($this->_name), $this->_submitValues); |
6a488035 TO |
217 | |
218 | //format params | |
b1141842 | 219 | $params['start_date'] = $params['start_date'] ?? NULL; |
220 | $params['end_date'] = $params['end_date'] ?? NULL; | |
6a488035 TO |
221 | $params['has_waitlist'] = CRM_Utils_Array::value('has_waitlist', $params, FALSE); |
222 | $params['is_map'] = CRM_Utils_Array::value('is_map', $params, FALSE); | |
223 | $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); | |
224 | $params['is_public'] = CRM_Utils_Array::value('is_public', $params, FALSE); | |
225 | $params['is_share'] = CRM_Utils_Array::value('is_share', $params, FALSE); | |
226 | $params['default_role_id'] = CRM_Utils_Array::value('default_role_id', $params, FALSE); | |
227 | $params['id'] = $this->_id; | |
228 | ||
6a488035 | 229 | //merge params with defaults from templates |
a7488080 | 230 | if (!empty($params['template_id'])) { |
6a488035 TO |
231 | $params = array_merge(CRM_Event_BAO_Event::getTemplateDefaultValues($params['template_id']), $params); |
232 | } | |
233 | ||
8c605c27 MD |
234 | $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, |
235 | $this->_id, | |
236 | 'Event' | |
237 | ); | |
238 | ||
6a488035 | 239 | // now that we have the event’s id, do some more template-based stuff |
a7488080 | 240 | if (!empty($params['template_id'])) { |
2e45b2f8 | 241 | $event = CRM_Event_BAO_Event::copy($params['template_id'], $params); |
ae70f47e MWMC |
242 | } |
243 | else { | |
244 | $event = CRM_Event_BAO_Event::create($params); | |
6a488035 | 245 | } |
03e04002 | 246 | |
6a488035 TO |
247 | $this->set('id', $event->id); |
248 | ||
c654c119 | 249 | $this->postProcessHook(); |
250 | ||
6a488035 TO |
251 | if ($this->_action & CRM_Core_Action::ADD) { |
252 | $url = 'civicrm/event/manage/location'; | |
253 | $urlParams = "action=update&reset=1&id={$event->id}"; | |
254 | // special case for 'Save and Done' consistency. | |
255 | if ($this->controller->getButtonName('submit') == '_qf_EventInfo_upload_done') { | |
256 | $url = 'civicrm/event/manage'; | |
257 | $urlParams = 'reset=1'; | |
258 | CRM_Core_Session::setStatus(ts("'%1' information has been saved.", | |
be2fb01f | 259 | [1 => $this->getTitle()] |
353ffa53 | 260 | ), ts('Saved'), 'success'); |
6a488035 TO |
261 | } |
262 | ||
263 | CRM_Utils_System::redirect(CRM_Utils_System::url($url, $urlParams)); | |
264 | } | |
265 | ||
266 | parent::endPostProcess(); | |
267 | } | |
6a488035 TO |
268 | |
269 | /** | |
3bdf1f3a | 270 | * Return a descriptive name for the page, used in wizard header. |
6a488035 TO |
271 | * |
272 | * @return string | |
6a488035 TO |
273 | */ |
274 | public function getTitle() { | |
275 | return ts('Event Information and Settings'); | |
276 | } | |
277 | ||
6a488035 | 278 | } |