Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions backup/moodle2/backup_format_softcourse_plugin.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
// This file is part of the softcourse course format
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* format_softcourse course format.
* Provides the information to backup grid course format
*
* @package format_softcourse
* @copyright 2026 Pimenko <contact@pimenko.com>.
* @category backup
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backup_format_softcourse_plugin extends backup_format_plugin {
/**
* Returns the format information to attach to section element
*/
protected function define_course_plugin_structure() {

// Define the virtual plugin element with the condition to fulfill.
$plugin = $this->get_plugin_element(
null,
'/course/format',
'softcourse',
);

// Create one standard named plugin element (the visible container).
$pluginwrapper = new backup_nested_element($this->get_recommended_name());

$plugin->add_child($pluginwrapper);

// Introduction.
$pluginwrapper->annotate_files('format_softcourse', 'introduction', null);

// Section image.
$pluginwrapper->annotate_files('format_softcourse', 'sectionimage', null);

return $plugin;
}
}
54 changes: 36 additions & 18 deletions backup/moodle2/restore_format_softcourse_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Specialised restore for format_softcourse
*
* @package format_softcourse
* @category backup
* @copyright 2021 Pimenko <contact@pimneko.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
* Specialised restore for format_softcourse
* Specialised restore for format_softcourse.
*
* Processes 'numsections' from the old backup files and hides sections that used to be "orphaned"
*
Expand All @@ -34,7 +25,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restore_format_softcourse_plugin extends restore_format_plugin {

/** @var int */
protected $originalnumsections = 0;

Expand All @@ -61,11 +51,14 @@ public function define_course_plugin_structure() {
// Since this method is executed before the restore we can do some pre-checks here.
// In case of merging backup into existing course find the current number of sections.
$target = $this->step->get_task()->get_target();
if (($target == backup::TARGET_CURRENT_ADDING || $target == backup::TARGET_EXISTING_ADDING) &&
$this->need_restore_numsections()) {
if (
($target == backup::TARGET_CURRENT_ADDING || $target == backup::TARGET_EXISTING_ADDING) &&
$this->need_restore_numsections()
) {
$maxsection = $DB->get_field_sql(
'SELECT max(section) FROM {course_sections} WHERE course = ?',
[$this->step->get_task()->get_courseid()]);
[$this->step->get_task()->get_courseid()]
);
$this->originalnumsections = (int)$maxsection;
}

Expand All @@ -77,7 +70,6 @@ public function define_course_plugin_structure() {
* Dummy process method
*/
public function process_dummy_course() {

}

/**
Expand All @@ -86,7 +78,31 @@ public function process_dummy_course() {
* This method is only executed if course configuration was overridden
*/
public function after_restore_course() {
global $DB;
global $DB, $CFG;

$this->add_related_files('format_softcourse', 'introduction', null);
$this->add_related_files('format_softcourse', 'sectionimage', null);

$courseid = $this->step->get_task()->get_courseid();
$newcontext = \context_course::instance($courseid);

$record = $DB->get_record('course_format_options', [
'courseid' => $courseid,
'format' => 'softcourse',
'name' => 'introduction',
]);

if ($record && !empty($record->value)) {
$newvalue = preg_replace(
'/\$@PLUGINFILEBYCONTEXT\*\d+@\$/',
$CFG->wwwroot . '/pluginfile.php/' . $newcontext->id,
$record->value
);
if ($newvalue !== $record->value) {
$record->value = $newvalue;
$DB->update_record('course_format_options', $record);
}
}

if (!$this->need_restore_numsections()) {
// Backup file was made in Moodle 3.3 or later, we don't need to process 'numsecitons'.
Expand All @@ -110,8 +126,10 @@ public function after_restore_course() {
if ($this->step->get_task()->get_setting_value($key . '_included')) {
$sectionnum = (int)$section->title;
if ($sectionnum > $numsections && $sectionnum > $this->originalnumsections) {
$DB->execute("UPDATE {course_sections} SET visible = 0 WHERE course = ? AND section = ?",
[$this->step->get_task()->get_courseid(), $sectionnum]);
$DB->execute(
"UPDATE {course_sections} SET visible = 0 WHERE course = ? AND section = ?",
[$this->step->get_task()->get_courseid(), $sectionnum]
);
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions classes/output/courseformat/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class content extends content_base {

/**
* @var bool Topic format has add section after each topic.
*
* The responsible for the buttons is core_courseformat\output\local\content\section.
*/
protected $hasaddsection = true;

}
Loading