Skip to content

Commit b40184b

Browse files
authored
Merge pull request #89 from ferishili/500-issue-77
Add help infos and tabs descriptions in simple and advanced upload pages (v 5.x)
2 parents ca6b364 + 00bd2ab commit b40184b

File tree

7 files changed

+98
-7
lines changed

7 files changed

+98
-7
lines changed

classes/local/advancedupload_field.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ class advancedupload_field {
7777
*/
7878
private $subfields = [];
7979

80+
/**
81+
* @var string Field description.
82+
*/
83+
private $description = null;
84+
8085
/**
8186
* Constructor to set field properties.
8287
*
@@ -251,4 +256,22 @@ public function set_subfield(advancedupload_field $subfield): void {
251256
public function get_subfields(): array {
252257
return $this->subfields;
253258
}
259+
260+
/**
261+
* Get the field description.
262+
*
263+
* @return ?string
264+
*/
265+
public function get_description(): ?string {
266+
return $this->description;
267+
}
268+
269+
/**
270+
* Set the field description.
271+
*
272+
* @param string $description
273+
*/
274+
public function set_description(string $description): void {
275+
$this->description = $description;
276+
}
254277
}

classes/local/upload_helper.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,13 @@ private static function convert_metadatacatalog(
188188
if (!empty($additionalattr)) {
189189
$attributes = array_merge($additionalattr, $attributes);
190190
}
191-
return new advancedupload_field($datatype, $id, $label, $params, $attributes, $default, $required);
191+
192+
$advanceduploadfield = new advancedupload_field($datatype, $id, $label, $params, $attributes, $default, $required);
193+
194+
if (!empty($field->description)) {
195+
$advanceduploadfield->set_description($field->description);
196+
}
197+
return $advanceduploadfield;
192198
}
193199

194200
/**

classes/output/renderer.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,19 @@ public function render_advanced_upload_form_tab_field(
248248
"$CFG->dirroot/local/chunkupload/classes/chunkupload_form_element.php",
249249
'local_chunkupload\chunkupload_form_element');
250250
}
251-
$mform->addElement(
251+
$element = $mform->addElement(
252252
$field->get_datatype(),
253253
$field->get_id(),
254254
$field->get_label(),
255255
$field->get_params(),
256256
$attributes
257257
);
258+
if (!empty($field->get_description())) {
259+
$mainrenderer = $this->page->get_renderer('tool_opencast');
260+
$element->_helpbutton = $mainrenderer->render_help_icon_with_custom_text(
261+
$field->get_label(), $field->get_description()
262+
);
263+
}
258264
if (!empty($field->get_default())) {
259265
$mform->setDefault($field->get_id(), $field->get_default());
260266
}
@@ -288,4 +294,18 @@ public function render_advanced_upload_form_tab_field(
288294
}
289295
}
290296
}
297+
298+
/**
299+
* Renders a description for a tab in the advanced upload form.
300+
*
301+
* Adds the provided description as a paragraph element to the Moodle form.
302+
*
303+
* @param MoodleQuickForm $mform The Moodle form object.
304+
* @param string $description The description text to display.
305+
* @return void
306+
*/
307+
public function render_tab_description(MoodleQuickForm &$mform, string $description): void {
308+
$tabdescription = html_writer::tag('p', $description, ['class' => 'pb-2']);
309+
$mform->addElement('html', $tabdescription);
310+
}
291311
}

lang/en/opencast.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
$string['uploadform_inplace_edit_visibility_hidden'] = 'Make it hidden!';
153153
$string['uploadform_ocinstancesselect'] = 'Opencast Instance';
154154
$string['uploadform_visibility'] = 'Visibility';
155+
$string['uploadform_visibility_help'] = 'Set whether students in this course can view the video or keep it hidden from them.';
155156
$string['uploadform_seriessselect'] = 'Series';
156157
$string['uploadform_submit'] = 'Upload now!';
157158
$string['uploadform_subtitle_field_enabled'] = 'Enable upload field';
@@ -170,9 +171,15 @@
170171
$string['uploadtitledisplay'] = 'Upload video:';
171172
$string['videotitle'] = 'Video title';
172173
$string['uploadform_tab_metadata'] = 'Video Metadata';
174+
$string['uploadform_tab_metadata_desc'] = 'Set metadata fields for your video. These details will be saved with the upload.';
173175
$string['uploadform_tab_presentation'] = 'Presentation Upload';
176+
$string['uploadform_tab_presentation_desc'] = 'Optionally upload a presentation file with your video.';
174177
$string['uploadform_tab_visibility'] = 'Video Visibility';
178+
$string['uploadform_tab_visibility_desc'] = 'Set the initial visibility for your video before uploading.';
175179
$string['uploadform_tab_processing'] = 'Processing Settings';
180+
$string['uploadform_tab_processing_desc'] = 'The following settings options are available to customized the upload process according to your likings.';
176181
$string['uploadform_tab_subtitle'] = 'Subtitles Upload';
182+
$string['uploadform_tab_subtitle_desc'] = 'Upload subtitle files for each language to enable captions.';
177183
$string['uploadform_presentation_upload'] = 'Presentation file';
184+
$string['uploadform_processing_options_general_help'] = 'Choose extra processing options for your upload. For example, "Straight to publishing" will publish the video immediately. Contact your administrator for details about available options';
178185
$string['uploaddeactivatedadvancedmode'] = 'Advanced mode is deactivated for this Opencast instance, please contact your system administrator.';

styles.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,16 @@ body.path-mod-opencast .mod-opencast-paella-player {
110110
.form-filetypes-descriptions li .text-dark {
111111
font-size: 12px;
112112
}
113+
114+
#mod-opencast-simple-upload-page .form-control-static {
115+
align-self: center;
116+
}
117+
118+
#mod-opencast-simple-upload-page .fitem {
119+
padding-top: calc(0.375rem + 1px);
120+
padding-bottom: calc(0.375rem + 1px);
121+
}
122+
123+
#mod-opencast-simple-upload-page .fitem .col-form-label {
124+
padding-top: 0px;
125+
}

uploadvideo_form.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ class mod_opencast_uploadvideo_form extends moodleform {
5454
* Defines forms elements
5555
*/
5656
public function definition() {
57+
global $PAGE;
5758
$cmid = $this->_customdata['cmid'];
5859
$ocmoduleinstance = $this->_customdata['moduleinstance'];
5960
$uploadoptions = json_decode($ocmoduleinstance->uploadoptionsjson);
6061
$simpleuploaddata = mod_upload_helper::get_simple_upload_form_data($ocmoduleinstance, $cmid);
6162
$ocinstanceformdata = $simpleuploaddata['ocinstanceformdata'];
6263
$defaultocinstance = (int) $uploadoptions->selectedocinstanceid;
6364
$ocinstancesoptions = $uploadoptions->options;
65+
$mainrenderer = $PAGE->get_renderer('tool_opencast');
6466

6567
$mform = $this->_form;
6668

@@ -116,7 +118,7 @@ public function definition() {
116118
foreach ($formdata->metadatacatalogs as $field) {
117119
$elementid = "{$field->name}_{$formdata->ocinstanceid}";
118120
$value = (isset($field->userdefault) ? $field->userdefault : null);
119-
$lbltext = $this->try_get_string($field->name, 'block_opencast');
121+
$lbltext = $this->try_get_string($field->name, 'tool_opencast');
120122

121123
if (!empty($ocinstancesoptions?->{$formdata->ocinstanceid}?->metadata?->{$field->name}->value)) {
122124
$value = $ocinstancesoptions->{$formdata->ocinstanceid}->metadata->{$field->name}->value;
@@ -156,13 +158,20 @@ public function definition() {
156158
}
157159

158160
if (!empty($inplaceobjhtml)) {
159-
$mform->addElement(
161+
$element = $mform->addElement(
160162
'static',
161163
$elementid,
162164
$lbltext,
163165
$inplaceobjhtml
164166
);
165167
$this->set_element_toggles($mform, $elementid, $formdata->ocinstanceid);
168+
169+
// Check if the description is set for the field, to display it as help icon.
170+
if (isset($field->description) && !empty($field->description)) {
171+
// Use the renderer to generate a help icon with custom text.
172+
$element->_helpbutton = $mainrenderer->render_help_icon_with_custom_text(
173+
$this->try_get_string($field->name, 'tool_opencast'), $field->description);
174+
}
166175
}
167176

168177
// We record the required metadata fields to verify them later on.
@@ -187,12 +196,14 @@ public function definition() {
187196
}
188197
$inplaceobj = new inplace_edit_toggle_visibility($inplvisibilitydata);
189198
$inplaceobjhtml = mod_upload_helper::render_inplace_editable_object($inplaceobj);
190-
$mform->addElement(
199+
$element = $mform->addElement(
191200
'static',
192201
$elementid,
193202
$lbltext,
194203
$inplaceobjhtml
195204
);
205+
$visibilityhelp = get_string('uploadform_visibility_help', 'mod_opencast');
206+
$element->_helpbutton = $mainrenderer->render_help_icon_with_custom_text($lbltext, $visibilityhelp);
196207
$this->set_element_toggles($mform, $elementid, $formdata->ocinstanceid);
197208
}
198209

@@ -229,12 +240,16 @@ public function definition() {
229240
}
230241
if (!empty($inplaceobj)) {
231242
$inplaceobjhtml = mod_upload_helper::render_inplace_editable_object($inplaceobj);
232-
$mform->addElement(
243+
$element = $mform->addElement(
233244
'static',
234245
$elementid,
235246
$lbltext,
236247
$inplaceobjhtml
237248
);
249+
$processingoptionsdesc = get_string('uploadform_processing_options_general_help', 'mod_opencast');
250+
$element->_helpbutton = $mainrenderer->render_help_icon_with_custom_text(
251+
$lbltext, $processingoptionsdesc
252+
);
238253
$this->set_element_toggles($mform, $elementid, $formdata->ocinstanceid);
239254
}
240255
}
@@ -252,6 +267,8 @@ public function definition() {
252267
$mform->addElement('hidden', 'cmid', $cmid);
253268
$mform->setType('cmid', PARAM_INT);
254269

270+
$mform->setAttributes(['id' => 'mod-opencast-simple-upload-page'] + $mform->getAttributes());
271+
255272
$mform->closeHeaderBefore('buttonar');
256273
$this->add_action_buttons(true, get_string('uploadform_submit', 'mod_opencast'));
257274
}

uploadvideoadvanced_form.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,13 @@ public function definition() {
7171
// Make sure the first tab is marked activated.
7272
$renderer->tab_pane_start($mform, $tabid, ($tabindex == 0), true);
7373

74-
// Here we look for the values already set in the uploadoptionsjson.
74+
// Here we add some helper texts and information regarding each tab if the string exists.
75+
$tabdescriptionstringid = "uploadform_tab_{$tabid}_desc";
76+
if (get_string_manager()->string_exists($tabdescriptionstringid, 'mod_opencast')) {
77+
$renderer->render_tab_description($mform, get_string($tabdescriptionstringid, 'mod_opencast'));
78+
}
7579

80+
// Here we look for the values already set in the uploadoptionsjson.
7681
foreach ($tabcontent as $field) {
7782
// Add default title to the metadata field when it is set.
7883
if ($field->get_id() === mod_upload_helper::METADATA_ID_PREFIX . 'title') {

0 commit comments

Comments
 (0)