Skip to content

Commit

Permalink
idea
Browse files Browse the repository at this point in the history
  • Loading branch information
gjb2048 committed Sep 28, 2023
1 parent 19f2c6f commit d47ea88
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 52 deletions.
7 changes: 4 additions & 3 deletions format.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,21 @@
course_set_marker($course->id, $marker);
}

if ($courseformatoptions['gnumsectionsnewcourse'] == 1) {
//if ($courseformatoptions['gnumsectionsnewcourse'] == 1) {
/*if (!array_key_exists())
// A new course that may have sections but does not know how many.
global $DB;
$numsections = $DB->get_field_sql('SELECT max(section) from {course_sections}
WHERE course = ?', [$course->id]);
if (empty($numsections)) {
/* Sections not created, so we need to use the default course setting,
which could be zero but this will still work. */
$numsections = get_config('moodlecourse', 'numsections');
/* $numsections = get_config('moodlecourse', 'numsections');
}
$format->set_gnumsections($numsections);
$courseformatoptions['gnumsections'] = $numsections;
$courseformatoptions['gnumsectionsnewcourse'] = 0;
}
}*/

// Make sure all sections are created.
course_create_sections_if_missing($course, range(0, $courseformatoptions['gnumsections']));
Expand Down
103 changes: 54 additions & 49 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,77 +308,80 @@ public function course_format_options($foreditform = false) {
if ($courseformatoptions === false) {
$courseconfig = get_config('moodlecourse');
$courseid = $this->get_courseid();
if ($courseid == 1) { // New course.
$defaultnumsections = $courseconfig->numsections;
$defaultgnumsectionsnewcourse = 1;
} else { // Existing course that may not have '(g)numsections' - see get_last_section().
//if ($courseid == 1) { // New course.
// $defaultnumsections = $courseconfig->numsections;
// $defaultgnumsectionsnewcourse = 1;
//} else { // Existing course that may not have '(g)numsections' - see get_last_section().
$courseformatoptions = [];
if ($courseid != 1) { // Not new course.
global $DB;
$defaultnumsections = $DB->get_field_sql('SELECT max(section) from {course_sections}
WHERE course = ?', [$courseid]);
$defaultgnumsectionsnewcourse = 0;
}
$courseformatoptions = [
'gnumsections' => [
$courseformatoptions['gnumsections'] = [
'default' => $defaultnumsections,
'type' => PARAM_INT,
],
'gnumsectionsnewcourse' => [
'default' => $defaultgnumsectionsnewcourse,
'type' => PARAM_INT,
],
'hiddensections' => [
'default' => $courseconfig->hiddensections,
'type' => PARAM_INT,
],
'popup' => [
];
}
//'gnumsectionsnewcourse' => [
// 'default' => $defaultgnumsectionsnewcourse,
// 'type' => PARAM_INT,
//],
$courseformatoptions['hiddensections'] = [
'default' => $courseconfig->hiddensections,
'type' => PARAM_INT,
];
$courseformatoptions['popup'] = [
'default' => 0,
'type' => PARAM_INT,
],
'gridjustification' => [
];
$courseformatoptions['gridjustification'] = [
'default' => '-',
'type' => PARAM_ALPHAEXT,
],
'imagecontainerwidth' => [
];
$courseformatoptions['imagecontainerwidth'] = [
'default' => 0,
'type' => PARAM_INT,
],
'imagecontainerratio' => [
];
$courseformatoptions['imagecontainerratio'] = [
'default' => '-',
'type' => PARAM_ALPHANUMEXT,
],
'imageresizemethod' => [
];
$courseformatoptions['imageresizemethod'] = [
'default' => 0,
'type' => PARAM_INT,
],
'showcompletion' => [
];
$courseformatoptions['showcompletion'] = [
'default' => 0,
'type' => PARAM_INT,
],
'singlepagesummaryimage' => [
];
$courseformatoptions['singlepagesummaryimage'] = [
'default' => 0,
'type' => PARAM_INT,
],
];
];
//];
}
if ($foreditform && !isset($courseformatoptions['gnumsections']['label'])) {
if ($foreditform && !isset($courseformatoptions['hiddensections']['label'])) {
if (is_null($courseconfig)) {
$courseconfig = get_config('moodlecourse');
}
$sectionmenu = [];
for ($i = 0; $i <= $courseconfig->maxsections; $i++) {
$sectionmenu[$i] = "$i";
}
$courseformatoptionsedit = [
'gnumsections' => [
$courseformatoptionsedit = [];
if ($courseid != 1) { // Not new course.
$courseformatoptionsedit['gnumsections'] = [
'label' => new lang_string('numbersections', 'format_grid'),
'element_type' => 'select',
'element_attributes' => [$sectionmenu],
],
'gnumsectionsnewcourse' => [
'label' => 0,
'element_type' => 'hidden',
],
'hiddensections' => [
];
}

//'gnumsectionsnewcourse' => [
//'label' => 0,
//'element_type' => 'hidden',
//],
$courseformatoptionsedit['hiddensections'] = [
'label' => new lang_string('hiddensections'),
'help' => 'hiddensections',
'help_component' => 'moodle',
Expand All @@ -389,7 +392,6 @@ public function course_format_options($foreditform = false) {
1 => new lang_string('hiddensectionsinvisible'),
],
],
],
];

// TODO - Use capabilities?
Expand Down Expand Up @@ -547,13 +549,16 @@ public function create_edit_form_elements(&$mform, $forsection = false) {
defaults page. This is so that the number of sections is not reduced leaving unintended orphaned
activities / resources. */
if (!$forsection) {
$maxsections = get_config('moodlecourse', 'maxsections');
$numsections = $mform->getElementValue('gnumsections');
$numsections = $numsections[0];
if ($numsections > $maxsections) {
$element = $mform->getElement('gnumsections');
for ($i = $maxsections + 1; $i <= $numsections; $i++) {
$element->addOption("$i", $i);
$courseid = $this->get_courseid();
if ($courseid != 1) { // Not new course.
$maxsections = get_config('moodlecourse', 'maxsections');
$numsections = $mform->getElementValue('gnumsections');
$numsections = $numsections[0];
if ($numsections > $maxsections) {
$element = $mform->getElement('gnumsections');
for ($i = $maxsections + 1; $i <= $numsections; $i++) {
$element->addOption("$i", $i);
}
}
}
}
Expand Down

0 comments on commit d47ea88

Please sign in to comment.