Skip to content

Commit

Permalink
MDL-78288 core_course: Adding filter_shown_headers option to forms
Browse files Browse the repository at this point in the history
  • Loading branch information
Amaia Anabitarte committed Jul 12, 2023
1 parent ef93325 commit 290e6f4
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 22 deletions.
18 changes: 14 additions & 4 deletions course/editsection.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@
$id = required_param('id', PARAM_INT); // course_sections.id
$sectionreturn = optional_param('sr', 0, PARAM_INT);
$deletesection = optional_param('delete', 0, PARAM_BOOL);
$showonly = optional_param('showonly', 0, PARAM_TAGLIST);

$PAGE->set_url('/course/editsection.php', array('id'=>$id, 'sr'=> $sectionreturn));
$params = ['id'=>$id, 'sr'=> $sectionreturn];
if (!empty($showonly)) {
$params['showonly'] = $showonly;
}
$PAGE->set_url('/course/editsection.php', $params);

$section = $DB->get_record('course_sections', array('id' => $id), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $section->course), '*', MUST_EXIST);
Expand Down Expand Up @@ -96,11 +101,13 @@
$courseformat = course_get_format($course);
$defaultsectionname = $courseformat->get_default_section_name($section);

$customdata = array(
$customdata = [
'cs' => $sectioninfo,
'editoroptions' => $editoroptions,
'defaultsectionname' => $defaultsectionname
);
'defaultsectionname' => $defaultsectionname,
'showonly' => $showonly,
];

$mform = $courseformat->editsection_form($PAGE->url, $customdata);

// set current value, make an editable copy of section_info object
Expand All @@ -110,6 +117,9 @@
$initialdata['availabilityconditionsjson'] = $sectioninfo->availability;
}
$mform->set_data($initialdata);
if (!empty($showonly)) {
$mform->filter_shown_headers(explode(',', $showonly));
}

if ($mform->is_cancelled()){
// Form cancelled, return to course.
Expand Down
25 changes: 14 additions & 11 deletions course/editsection_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
class editsection_form extends moodleform {

function definition() {
global $CFG;

$mform = $this->_form;
$course = $this->_customdata['course'];
Expand Down Expand Up @@ -47,26 +48,28 @@ function definition() {
$elements = $courseformat->create_edit_form_elements($mform, true);
}

if (!empty($CFG->enableavailability)) {
$mform->addElement('header', 'availabilityconditions',
get_string('restrictaccess', 'availability'));
$mform->setExpanded('availabilityconditions', false);

// Availability field. This is just a textarea; the user interface
// interaction is all implemented in JavaScript. The field is named
// availabilityconditionsjson for consistency with moodleform_mod.
$mform->addElement('textarea', 'availabilityconditionsjson',
get_string('accessrestrictions', 'availability'));
}

$mform->_registerCancelButton('cancel');
}

public function definition_after_data() {
global $CFG, $DB;
global $CFG;

$mform = $this->_form;
$course = $this->_customdata['course'];
$context = context_course::instance($course->id);

if (!empty($CFG->enableavailability)) {
$mform->addElement('header', 'availabilityconditions',
get_string('restrictaccess', 'availability'));
$mform->setExpanded('availabilityconditions', false);

// Availability field. This is just a textarea; the user interface
// interaction is all implemented in JavaScript. The field is named
// availabilityconditionsjson for consistency with moodleform_mod.
$mform->addElement('textarea', 'availabilityconditionsjson',
get_string('accessrestrictions', 'availability'));
\core_availability\frontend::include_all_javascript($course, null,
$this->_customdata['cs']);
}
Expand Down
10 changes: 10 additions & 0 deletions course/modedit.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@
$type = optional_param('type', '', PARAM_ALPHANUM); //TODO: hopefully will be removed in 2.0
$sectionreturn = optional_param('sr', null, PARAM_INT);
$beforemod = optional_param('beforemod', 0, PARAM_INT);
$showonly = optional_param('showonly', '', PARAM_ALPHANUM); // Settings group to show expanded and hide the rest.

$url = new moodle_url('/course/modedit.php');
$url->param('sr', $sectionreturn);
if (!empty($return)) {
$url->param('return', $return);
}
if (!empty($showonly)) {
$url->param('showonly', $showonly);
}

if (!empty($add)) {
$section = required_param('section', PARAM_INT);
Expand Down Expand Up @@ -113,6 +117,9 @@
$data->return = $return;
$data->sr = $sectionreturn;
$data->update = $update;
if (!empty($showonly)) {
$data->showonly = $showonly;
}

$sectionname = get_section_name($course, $cw);
$fullmodulename = get_string('modulename', $module->name);
Expand Down Expand Up @@ -153,6 +160,9 @@
$mformclassname = 'mod_'.$module->name.'_mod_form';
$mform = new $mformclassname($data, $cw->section, $cm, $course);
$mform->set_data($data);
if (!empty($showonly)) {
$mform->filter_shown_headers(explode(',', $showonly));
}

if ($mform->is_cancelled()) {
if ($return && !empty($cm->id)) {
Expand Down
3 changes: 3 additions & 0 deletions course/moodleform_mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,9 @@ function standard_hidden_coursemodule_elements(){

$mform->addElement('hidden', 'beforemod', 0);
$mform->setType('beforemod', PARAM_INT);

$mform->addElement('hidden', 'showonly', '');
$mform->setType('showonly', PARAM_ALPHANUMEXT);
}

public function standard_grading_coursemodule_elements() {
Expand Down
2 changes: 1 addition & 1 deletion lib/form/amd/build/collapsesections.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 290e6f4

Please sign in to comment.