-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathPresentationForm.php
More file actions
247 lines (208 loc) · 9.02 KB
/
Copy pathPresentationForm.php
File metadata and controls
247 lines (208 loc) · 9.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
/**
* Class PresentationForm
*/
final class PresentationForm extends BootstrapForm
{
/**
* @var IPresentationManager
*/
private $presentation_manager;
/**
* @var ISummit
*/
private $summit;
/**
* @var IPresentation
*/
private $presentation;
/**
* PresentationForm constructor.
* @param Controller $controller
* @param string $name
* @param FieldList $actions
* @param ISummit $summit
* @param IPresentationManager $presentation_manager
* @param IPresentation $presentation
*/
public function __construct($controller, $name, $actions, ISummit $summit, IPresentationManager $presentation_manager, IPresentation $presentation) {
$this->presentation_manager = $presentation_manager;
$this->summit = $summit;
$this->presentation = $presentation;
$this->setTemplate('PresentationForm');
JQueryValidateDependencies::renderRequirements(true,false);
Requirements::javascript('summit/javascript/presentation-form.js');
Requirements::javascript('summit/javascript/presentation-form-save-actions.js');
Requirements::css('node_modules/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css');
parent::__construct(
$controller,
$name,
$this->getPresentationFields(),
$actions,
$this->getPresentationValidator()
);
}
protected function getPresentationFields() {
$category_groups = [];
if ($this->summit->isCallForSpeakersOpen()) {
$category_groups = $this->summit->getOpenSelectionPlanForStage('Submission')->getPublicCategoryGroups();
}
$category_groups_map = array();
foreach ($category_groups as $group) {
if (!$group->Categories()->count()) continue;
if (!$group->hasCategoryVisible()) continue;
$category_groups_map[] = array('id' => $group->ID,'title' => $group->Name);
}
if(!count($category_groups_map))
throw new RuntimeException("not available categories (tracks)!");
usort($category_groups_map, function($a, $b) { return strcmp($a["title"], $b["title"]); });
$types = PresentationType::get()
->filter(['SummitID' => $this->summit->ID, 'ShouldBeAvailableOnCFP' => 1])
->exclude('Type', [IPresentationType::Keynotes, IPresentationType::LightingTalks]);
$instructions = '(';
foreach($types as $type){
$instructions .= $type->Type;
if(intval($type->MaxSpeakers > 0))
$instructions .= sprintf(" Max %s moderators", $type->MaxSpeakers);
if(intval($type->MaxModerators > 0))
$instructions .= sprintf(" %s moderator", $type->MaxModerators);
$instructions .= '; ';
}
$instructions .= ')';
$fields = FieldList::create()
->text('Title', 'Proposed Title')
->configure()
->setAttribute('autofocus','TRUE')
->end()
->literal('TypeIDHelp','<label>Select the format</label> <br>'.$instructions)
->dropdown('TypeID','')
->configure()
->setEmptyString('-- Select one --')
->setSource($types->map('ID', 'Type'))
->end()
->literal('CategoryContainer','<div id="category_options"></div>')
->dropdown('Level','Select the technical level of your session')
->configure()
->setEmptyString('-- Select one --')
->setSource(Presentation::create()->dbObject('Level')->enumValues())
->end()
->tinyMCEEditor('Abstract','Abstract (1000 chars)')
->configure()
->setRows(20)
->setColumns(8)
->end()
->literal('SocialSummaryHelp','<hr/><p>Used for social sharing and YouTube description.</p>')
->textArea('SocialSummary', 'Social Summary (100 chars)')
->configure()
->setRows(10)
->setColumns(8)
->end()
->tinyMCEEditor('AttendeesExpectedLearnt','Why is this session useful? (1000 chars)')
->configure()
->setRows(20)
->setColumns(8)
->end()
->optionset('AttendingMedia',
'Are you available to discuss this topic with attending media?',
array(
1 => 'Yes',
0 => 'No'
)
)
->configure()
->setTemplate('BootstrapAwesomeOptionsetField')
->setInline(true)
->end()
->literal('PresentationMaterialsTitle','<h3>Please provide any relevant links to additional information, such as code repositories, case studies, papers, blog posts etc. (Up to 5 links)</h3>')
->text('PresentationLink[1]','#1')
->text('PresentationLink[2]','#2')
->text('PresentationLink[3]','#3')
->text('PresentationLink[4]','#4')
->text('PresentationLink[5]','#5')
->hidden('ID','ID')
->hidden('SummitID','',$this->summit->ID)
->hidden('CategoryIDbis','')
->hidden('Continue','',1)
->configure()
->addExtraClass('continue_field')
->end()
->literal('EndHr','<hr>');
$CategoryGroupField = new CategoryGroupField('GroupID','Select the <a href="'.$this->summit->Link.'categories" target="_blank">Summit Category</a> of your session');
$CategoryGroupField->setSource($category_groups_map);
if(count($category_groups_map) < 2 && count($category_groups_map) > 0 ) {
$CategoryGroupField->setValue($category_groups_map[0]['id']);
$CategoryGroupField->addHolderClass('hidden');
}
$fields->insertAfter($CategoryGroupField,'TypeID');
return $fields;
}
protected function getPresentationValidator()
{
return RequiredFields::create('Title','Level');
}
public function loadDataFrom($data, $mergeStrategy = 0, $fieldList = null)
{
parent::loadDataFrom($data, $mergeStrategy, $fieldList);
if (!$data instanceof Presentation) {
return;
}
$presentation = $data;
$this->fields->fieldByName('Continue')->setValue(1);
if ($presentation->Category()->ID) {
$group = $presentation->Category()->getCategoryGroups()->first();
$this->fields->fieldByName('GroupID')->setValue($group->ID);
$this->fields->fieldByName('CategoryIDbis')->setValue($presentation->Category()->ID);
}
foreach ($presentation->Materials()->filter('ClassName', 'PresentationLink') as $key => $link)
{
if ($key > 4) break;
$this->fields->fieldByName('PresentationLink['.($key+1).']')->setValue($link->Link);
}
return $this;
}
public function saveInto(DataObjectInterface $dataObject, $fieldList = null)
{
parent::saveInto($dataObject, $fieldList);
if (!$dataObject instanceof Presentation) {
return;
}
$presentation = $dataObject;
$old_materials = $presentation->Materials()->filter('ClassName', 'PresentationLink');
foreach($old_materials as $o) $o->Delete();
for($i = 1 ; $i <= 5 ; $i++ ){
$field = $this->fields->fieldByName("PresentationLink[{$i}]");
if(is_null($field)) continue;
$val = $field->Value();
if(empty($val)) continue;
$presentation = PresentationLink::create(['Name' => trim($val), 'Link' => trim($val)]);
$presentation->Materials()->add($presentation);
}
$extra_questions = ($presentation->Category()->Exists()) ? $presentation->Category()->ExtraQuestions() : array();
foreach ($extra_questions as $question) {
$field = $this->fields->fieldByName($question->Name);
if(is_null($field)) continue;
$answer_value = $field->Value();
if(empty($answer_value)) continue;
if (!$answer = $presentation->findAnswerByQuestion($question)) {
$answer = new TrackAnswer();
}
if(is_array($answer_value) ){
$answer_value = str_replace('{comma}', ',', $answer_value);
$answer->Value = implode(',', $answer_value);
}
else{
$answer->Value = $answer_value;
}
$answer->QuestionID = $question->getIdentifier();
$answer->write();
$presentation->ExtraAnswers()->add($answer);
}
}
public function forTemplate() {
parent::forTemplate();
$return = $this->renderWith(['PresentationForm']);
// Now that we're rendered, clear message
$this->clearMessage();
return $return;
}
}