3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
14 * @copyright CiviCRM LLC https://civicrm.org/licensing
18 * This class generates form components for processing Event.
20 class CRM_Event_Form_ManageEvent_EventInfo
extends CRM_Event_Form_ManageEvent
{
26 protected $_eventType = NULL;
29 * Set variables up before form is built.
31 public function preProcess() {
33 $this->setSelectedChild('settings');
35 $entityID = $this->_id ?
: $this->_templateId
;
37 $this->assign('entityID', $entityID);
38 $eventType = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
47 $showLocation = FALSE;
48 // when custom data is included in this page
49 if (!empty($_POST['hidden_custom'])) {
50 $this->set('type', 'Event');
51 $this->set('subType', CRM_Utils_Array
::value('event_type_id', $_POST));
52 $this->assign('customDataSubType', CRM_Utils_Array
::value('event_type_id', $_POST));
53 $this->set('entityId', $entityID);
55 CRM_Custom_Form_CustomData
::preProcess($this, NULL, $this->_eventType
, 1, 'Event', $entityID);
56 CRM_Custom_Form_CustomData
::buildQuickForm($this);
57 CRM_Custom_Form_CustomData
::setDefaultValues($this);
62 * Set default values for the form.
64 * For edit/view mode he default values are retrieved from the database.
66 public function setDefaultValues() {
67 $defaults = parent
::setDefaultValues();
69 // in update mode, we need to set custom data subtype to tpl
70 if (!empty($defaults['event_type_id'])) {
71 $this->assign('customDataSubType', $defaults['event_type_id']);
74 $this->_showHide
= new CRM_Core_ShowHideBlocks();
75 // Show waitlist features or event_full_text if max participants set
76 if (!empty($defaults['max_participants'])) {
77 $this->_showHide
->addShow('id-waitlist');
78 if (!empty($defaults['has_waitlist'])) {
79 $this->_showHide
->addShow('id-waitlist-text');
80 $this->_showHide
->addHide('id-event_full');
83 $this->_showHide
->addHide('id-waitlist-text');
84 $this->_showHide
->addShow('id-event_full');
88 $this->_showHide
->addHide('id-event_full');
89 $this->_showHide
->addHide('id-waitlist');
90 $this->_showHide
->addHide('id-waitlist-text');
93 $this->_showHide
->addToTemplate();
94 $this->assign('elemType', 'table-row');
96 $this->assign('description', CRM_Utils_Array
::value('description', $defaults));
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.'));
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.'));
102 $defaults['template_id'] = $this->_templateId
;
107 * Build the form object.
109 public function buildQuickForm() {
110 //need to assign custom data type and subtype to the template
111 $this->assign('customDataType', 'Event');
112 if ($this->_eventType
) {
113 $this->assign('customDataSubType', $this->_eventType
);
116 $this->_first
= TRUE;
117 $this->applyFilter('__ALL__', 'trim');
118 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
120 if ($this->_isTemplate
) {
121 $this->add('text', 'template_title', ts('Template Title'), $attributes['template_title'], TRUE);
124 if ($this->_action
& CRM_Core_Action
::ADD
) {
125 $eventTemplates = CRM_Event_PseudoConstant
::eventTemplates();
126 if (CRM_Utils_System
::isNull($eventTemplates) && !$this->_isTemplate
) {
127 $url = CRM_Utils_System
::url('civicrm/admin/eventTemplate', ['reset' => 1]);
128 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');
130 if (!CRM_Utils_System
::isNull($eventTemplates)) {
131 $this->add('select', 'template_id', ts('From Template'), ['' => ts('- select -')] +
$eventTemplates, FALSE, ['class' => 'crm-select2 huge']);
133 // Make sure this form redirects properly
134 $this->preventAjaxSubmit();
137 // add event title, make required if this is not a template
138 $this->add('text', 'title', ts('Event Title'), $attributes['event_title'], !$this->_isTemplate
);
140 $this->addSelect('event_type_id',
141 ['onChange' => "CRM.buildCustomData( 'Event', this.value );"],
145 //CRM-7362 --add campaigns.
148 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_id
, 'campaign_id');
150 CRM_Campaign_BAO_Campaign
::addCampaign($this, $campaignId);
152 $this->addSelect('default_role_id', [], TRUE);
154 $this->addSelect('participant_listing_id', ['placeholder' => ts('Disabled'), 'option_url' => NULL]);
156 $this->add('textarea', 'summary', ts('Event Summary'), $attributes['summary']);
157 $this->add('wysiwyg', 'description', ts('Complete Description'), $attributes['event_description'] +
['preset' => 'civievent']);
158 $this->addElement('checkbox', 'is_public', ts('Public Event'));
159 $this->addElement('checkbox', 'is_share', ts('Allow sharing through social media?'));
160 $this->addElement('checkbox', 'is_map', ts('Include Map to Event Location'));
162 $this->add('datepicker', 'start_date', ts('Start'), [], !$this->_isTemplate
, ['time' => TRUE]);
163 $this->add('datepicker', 'end_date', ts('End'), [], FALSE, ['time' => TRUE]);
165 $this->add('number', 'max_participants', ts('Max Number of Participants'),
166 ['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;}"]
168 $this->addRule('max_participants', ts('Max participants should be a positive number'), 'positiveInteger');
170 $participantStatuses = CRM_Event_PseudoConstant
::participantStatus();
172 if (in_array('On waitlist', $participantStatuses) and in_array('Pending from waitlist', $participantStatuses)) {
173 $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);"]);
174 $this->add('textarea', 'waitlist_text', ts('Waitlist Message'), $attributes['waitlist_text']);
177 $this->assign('waitlist', $waitlist);
179 $this->add('textarea', 'event_full_text', ts('Message if Event Is Full'), $attributes['event_full_text']);
181 $this->addElement('checkbox', 'is_active', ts('Is this Event Active?'));
183 $this->addFormRule(['CRM_Event_Form_ManageEvent_EventInfo', 'formRule']);
185 parent
::buildQuickForm();
189 * Global validation rules for the form.
191 * @param array $values
194 * list of errors to be posted back to the form
196 public static function formRule($values) {
199 if (!empty($values['end_date']) && ($values['end_date'] < $values['start_date'])) {
200 $errors['end_date'] = ts('End date should be after Start date.');
204 if (strstr($values['title'], '/')) {
205 $errors['title'] = ts("Please do not use '/' in Event Title.");
212 * Process the form submission.
214 public function postProcess() {
215 $params = array_merge($this->controller
->exportValues($this->_name
), $this->_submitValues
);
218 $params['start_date'] = CRM_Utils_Array
::value('start_date', $params);
219 $params['end_date'] = CRM_Utils_Array
::value('end_date', $params);
220 $params['has_waitlist'] = CRM_Utils_Array
::value('has_waitlist', $params, FALSE);
221 $params['is_map'] = CRM_Utils_Array
::value('is_map', $params, FALSE);
222 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
223 $params['is_public'] = CRM_Utils_Array
::value('is_public', $params, FALSE);
224 $params['is_share'] = CRM_Utils_Array
::value('is_share', $params, FALSE);
225 $params['default_role_id'] = CRM_Utils_Array
::value('default_role_id', $params, FALSE);
226 $params['id'] = $this->_id
;
228 //merge params with defaults from templates
229 if (!empty($params['template_id'])) {
230 $params = array_merge(CRM_Event_BAO_Event
::getTemplateDefaultValues($params['template_id']), $params);
231 foreach ($params as $key => $value) {
232 $customFieldInfo = CRM_Core_BAO_CustomField
::getKeyID($key, TRUE);
233 if (!empty($customFieldInfo[1])) {
234 $params[str_replace($customFieldInfo[1], '-' . $customFieldInfo[1], $key)] = $value;
235 unset($params[$key]);
240 $params['custom'] = CRM_Core_BAO_CustomField
::postProcess($params,
245 // now that we have the event’s id, do some more template-based stuff
246 if (!empty($params['template_id'])) {
247 $event = CRM_Event_BAO_Event
::copy($params['template_id'], $params);
250 $event = CRM_Event_BAO_Event
::create($params);
253 $this->set('id', $event->id
);
255 $this->postProcessHook();
257 if ($this->_action
& CRM_Core_Action
::ADD
) {
258 $url = 'civicrm/event/manage/location';
259 $urlParams = "action=update&reset=1&id={$event->id}";
260 // special case for 'Save and Done' consistency.
261 if ($this->controller
->getButtonName('submit') == '_qf_EventInfo_upload_done') {
262 $url = 'civicrm/event/manage';
263 $urlParams = 'reset=1';
264 CRM_Core_Session
::setStatus(ts("'%1' information has been saved.",
265 [1 => $this->getTitle()]
266 ), ts('Saved'), 'success');
269 CRM_Utils_System
::redirect(CRM_Utils_System
::url($url, $urlParams));
272 parent
::endPostProcess();
276 * Return a descriptive name for the page, used in wizard header.
280 public function getTitle() {
281 return ts('Event Information and Settings');