Skip to content

Commit

Permalink
Fix 'Problems with creating multiple courses from template via CSV in…
Browse files Browse the repository at this point in the history
… Grid Format' - #189.
  • Loading branch information
gjb2048 committed Sep 28, 2023
1 parent f35f715 commit 9840a7b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Version 401.2.1 - TBR
1. Fix 'Webp image causes an error and makes course unaccessible' - #190.
2. Fix "Hidden sections are shown as not available" doesn't seem to work. - #192.
3. Add 'Flex containers' justify-content property options' - #191.
4. Fix 'Problems with creating multiple courses from template via CSV in Grid Format' - #189.

Version 401.2.0 - 16/08/2023
----------------------------
Expand Down
17 changes: 16 additions & 1 deletion backup/moodle2/restore_format_grid_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,25 @@ public function process_gridsection($data) {

$data = (object) $data;

$target = $this->step->get_task()->get_target();
if (($target == backup::TARGET_NEW_COURSE) ||
($target == backup::TARGET_CURRENT_ADDING) ||
($target == backup::TARGET_CURRENT_DELETING) ||
($target == backup::TARGET_EXISTING_DELETING)) {
/* This ensures that when a course is created from an uploaded CSV file that the number of sections is correct.
Thus when an existing course or course file is used but the course restore code is not called.
Because the backup file / course being restored from has the correct 'sections', i.e. that will be in the
'course_sections' table. */
$courseid = $this->task->get_courseid();
static $gnumsections = 0;
$gnumsections++;
// We don't know how many more sections there is and also don't know if this is the last.
$courseformat = course_get_format($courseid);
$courseformat->restore_gnumsections($gnumsections);
}
/* Allow this to process even if not in the grid format so that our event observer on 'course_restored'
can perform a clean up of restored grid image files after all the data is in place in the database
for this to happen properly. */
$target = $this->step->get_task()->get_target();
if (($target == backup::TARGET_NEW_COURSE) ||
($target == backup::TARGET_CURRENT_DELETING) ||
($target == backup::TARGET_EXISTING_DELETING) ||
Expand Down
13 changes: 7 additions & 6 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,18 @@ class format_grid extends core_courseformat\base {
* @return format_grid
*/
protected function __construct($format, $courseid) {
parent::__construct($format, $courseid);
if ($courseid === 0) {
global $COURSE;
$courseid = $COURSE->id; // Save lots of global $COURSE as we will never be the site course.
}
parent::__construct($format, $courseid);

$currentsettings = $this->get_settings();
if (!empty($currentsettings['popup'])) {
if ($currentsettings['popup'] == 2) {
$this->coursedisplay = COURSE_DISPLAY_SINGLEPAGE;
if ($courseid != 1) {
$currentsettings = $this->get_settings();
if (!empty($currentsettings['popup'])) {
if ($currentsettings['popup'] == 2) {
$this->coursedisplay = COURSE_DISPLAY_SINGLEPAGE;
}
}
}
}
Expand Down Expand Up @@ -309,7 +310,7 @@ public function course_format_options($foreditform = false) {
$courseid = $this->get_courseid();
if ($courseid == 1) { // New course.
$defaultnumsections = $courseconfig->numsections;
} else { // Existing course that may not have 'numsections' - see get_last_section().
} else { // Existing course that may not have '(g)numsections' - see get_last_section().
global $DB;
$defaultnumsections = $DB->get_field_sql('SELECT max(section) from {course_sections}
WHERE course = ?', [$courseid]);
Expand Down

0 comments on commit 9840a7b

Please sign in to comment.