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
7 changes: 3 additions & 4 deletions backup/moodle2/backup_subcourse_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot.'/mod/subcourse/backup/moodle2/backup_subcourse_stepslib.php');
require_once($CFG->dirroot . '/mod/subcourse/backup/moodle2/backup_subcourse_stepslib.php');

/**
* Provides settings and steps to perform a complete backup of the activity.
Expand All @@ -34,7 +34,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backup_subcourse_activity_task extends backup_activity_task {

/**
* Define (add) particular settings this activity can have
*/
Expand All @@ -60,11 +59,11 @@ public static function encode_content_links($content) {
$base = preg_quote($CFG->wwwroot, "/");

// Link to the list of subcourses.
$search = "/(".$base."\/mod\/subcourse\/index.php\?id\=)([0-9]+)/";
$search = "/(" . $base . "\/mod\/subcourse\/index.php\?id\=)([0-9]+)/";
$content = preg_replace($search, '$@SUBCOURSEINDEX*$2@$', $content);

// Link to subcourse by moduleid.
$search = "/(".$base."\/mod\/subcourse\/view.php\?id\=)([0-9]+)/";
$search = "/(" . $base . "\/mod\/subcourse\/view.php\?id\=)([0-9]+)/";
$content = preg_replace($search, '$@SUBCOURSEVIEWBYID*$2@$', $content);

return $content;
Expand Down
17 changes: 13 additions & 4 deletions backup/moodle2/backup_subcourse_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,25 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backup_subcourse_activity_structure_step extends backup_activity_structure_step {

/**
* Defines the complete subcourse structure for backup
*/
protected function define_structure() {

$subcourse = new backup_nested_element('subcourse', ['id'], [
'name', 'intro', 'introformat', 'timecreated', 'timemodified', 'timefetched',
'refcourse', 'instantredirect', 'completioncourse', 'blankwindow', 'fetchpercentage',
'coursepageprintgrade', 'coursepageprintprogress'
'name',
'intro',
'introformat',
'timecreated',
'timemodified',
'timefetched',
'refcourse',
'instantredirect',
'completioncourse',
'blankwindow',
'fetchpercentage',
'coursepageprintgrade',
'coursepageprintprogress',
]);

$subcourse->set_source_table('subcourse', ['id' => backup::VAR_ACTIVITYID]);
Expand Down
13 changes: 9 additions & 4 deletions backup/moodle2/restore_subcourse_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restore_subcourse_activity_task extends restore_activity_task {

/**
* Define (add) particular settings this activity can have
*/
Expand Down Expand Up @@ -73,7 +72,6 @@ public static function define_decode_rules() {
$rules[] = new restore_decode_rule('SUBCOURSEINDEX', '/mod/subcourse/index.php?id=$1', 'course');

return $rules;

}

/**
Expand Down Expand Up @@ -107,8 +105,15 @@ public static function define_restore_log_rules_for_course() {
$rules = [];

// Fix old wrong uses (missing extension).
$rules[] = new restore_log_rule('subcourse', 'view all', 'index?id={course}', null,
null, null, 'index.php?id={course}');
$rules[] = new restore_log_rule(
'subcourse',
'view all',
'index?id={course}',
null,
null,
null,
'index.php?id={course}'
);
$rules[] = new restore_log_rule('subcourse', 'view all', 'index.php?id={course}', null);

return $rules;
Expand Down
1 change: 0 additions & 1 deletion backup/moodle2/restore_subcourse_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restore_subcourse_activity_structure_step extends restore_activity_structure_step {

/**
* Attaches the handlers of the backup XML tree parts.
*
Expand Down
2 changes: 1 addition & 1 deletion classes/completion/custom_completion.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class custom_completion extends \core_completion\activity_custom_completion {
*/
public function get_state(string $rule): int {
global $CFG, $DB;
require_once($CFG->dirroot.'/completion/completion_completion.php');
require_once($CFG->dirroot . '/completion/completion_completion.php');

$this->validate_rule($rule);

Expand Down
78 changes: 78 additions & 0 deletions classes/courseformat/overview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.

namespace mod_subcourse\courseformat;

use core\output\action_link;
use core\output\local\properties\button;
use core\output\local\properties\text_align;
use core\url;
use core_courseformat\local\overview\overviewitem;

/**
* Subcourse overview integration (for Moodle 5.1+)
*
* @package mod_subcourse
* @copyright 2026 Luca Bösch <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class overview extends \core_courseformat\activityoverviewbase {
/**
* Constructor.
*
* @param \cm_info $cm the course module instance.
* @param \core\output\renderer_helper $rendererhelper the renderer helper.
*/
public function __construct(
\cm_info $cm,
/** @var \core\output\renderer_helper $rendererhelper the renderer helper */
protected readonly \core\output\renderer_helper $rendererhelper,
) {
parent::__construct($cm);
}

#[\Override]
public function get_actions_overview(): ?overviewitem {
$url = new url(
'/mod/subcourse/view.php',
['id' => $this->cm->id],
);

if (
class_exists(button::class) &&
(new \ReflectionClass(button::class))->hasConstant('BODY_OUTLINE')
) {
$bodyoutline = button::BODY_OUTLINE;
$buttonclass = $bodyoutline->classes();
} else {
$buttonclass = "btn btn-outline-secondary";
}

$text = get_string('view');
$content = new action_link(
url: $url,
text: $text,
attributes: ['class' => $buttonclass],
);

return new overviewitem(
name: get_string('actions'),
value: $text,
content: $content,
textalign: text_align::CENTER,
);
}
}
1 change: 0 additions & 1 deletion classes/event/course_module_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_module_viewed extends \core\event\course_module_viewed {

/**
* Initialize the event - set the objecttable.
*/
Expand Down
3 changes: 1 addition & 2 deletions classes/event/subcourse_grades_fetched.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class subcourse_grades_fetched extends \core\event\base {

/**
* Initialize the event.
*/
Expand All @@ -57,7 +56,7 @@ public static function get_name() {
* @return string
*/
public function get_description() {
return "The user with id '{$this->userid}' fetched grades from the course with id '{$this->other['refcourse']}' ".
return "The user with id '{$this->userid}' fetched grades from the course with id '{$this->other['refcourse']}' " .
"into the 'subcourse' activity with the course module id '{$this->contextinstanceid}'.";
}

Expand Down
4 changes: 2 additions & 2 deletions classes/external/view_subcourse.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/**
* Provides {@see \mod_subcourse\external\view_subcourse} class.
*
* @package mod_subcourse
* @copyright 2020 David Mudrák <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
Expand All @@ -43,7 +44,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class view_subcourse extends external_api {

/**
* Describes the parameters for view_subcourse.
*
Expand Down Expand Up @@ -72,7 +72,7 @@ public static function execute($subcourseid) {
$warnings = [];

$subcourse = $DB->get_record('subcourse', ['id' => $params['subcourseid']], '*', MUST_EXIST);
list($course, $cm) = get_course_and_cm_from_instance($subcourse, 'subcourse');
[$course, $cm] = get_course_and_cm_from_instance($subcourse, 'subcourse');
$context = \context_module::instance($cm->id);

self::validate_context($context);
Expand Down
27 changes: 21 additions & 6 deletions classes/observers.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class observers {

/**
* User graded
*
Expand All @@ -53,8 +52,16 @@ public static function user_graded(\core\event\user_graded $event) {
$subcourses = $DB->get_records('subcourse', ['refcourse' => $courseid], '', 'id, course, refcourse, fetchpercentage');

foreach ($subcourses as $subcourse) {
subcourse_grades_update($subcourse->course, $subcourse->id, $subcourse->refcourse,
null, false, false, $userid, $subcourse->fetchpercentage);
subcourse_grades_update(
$subcourse->course,
$subcourse->id,
$subcourse->refcourse,
null,
false,
false,
$userid,
$subcourse->fetchpercentage
);
}
}

Expand All @@ -76,8 +83,16 @@ public static function role_assigned(\core\event\role_assigned $event) {
$subcourses = $DB->get_records('subcourse', ['course' => $courseid], '', 'id, course, refcourse, fetchpercentage');

foreach ($subcourses as $subcourse) {
subcourse_grades_update($subcourse->course, $subcourse->id, $subcourse->refcourse,
null, false, false, $userid, $subcourse->fetchpercentage);
subcourse_grades_update(
$subcourse->course,
$subcourse->id,
$subcourse->refcourse,
null,
false,
false,
$userid,
$subcourse->fetchpercentage
);
}
}

Expand All @@ -93,7 +108,7 @@ public static function role_assigned(\core\event\role_assigned $event) {
*/
public static function course_completed(\core\event\course_completed $event) {
global $CFG, $DB;
require_once($CFG->dirroot.'/lib/completionlib.php');
require_once($CFG->dirroot . '/lib/completionlib.php');

$courseid = $event->courseid;
$userid = $event->relateduserid;
Expand Down
12 changes: 8 additions & 4 deletions classes/output/mobile.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/**
* Provides {@see \mod_subcourse\output\mobile} class.
*
* @package mod_subcourse
* @copyright 2020 David Mudrák <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
Expand All @@ -36,7 +37,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mobile {

/**
* Return the data for the CoreCourseModuleDelegate delegate.
*
Expand Down Expand Up @@ -64,7 +64,6 @@ public static function main_view($args) {
if (has_capability('mod/subcourse:fetchgrades', $context)) {
$warning = get_string('refcoursenull', 'subcourse');
}

} else {
$refcourse = $DB->get_record('course', ['id' => $subcourse->refcourse], 'id, fullname', IGNORE_MISSING);
}
Expand All @@ -79,8 +78,13 @@ public static function main_view($args) {

// Pre-format some of the texts for the mobile app.
$subcourse->name = \core_external\util::format_string($subcourse->name, $context);
[$subcourse->intro, $subcourse->introformat] = \core_external\util::format_text($subcourse->intro, $subcourse->introformat,
$context, 'mod_subcourse', 'intro');
[$subcourse->intro, $subcourse->introformat] = \core_external\util::format_text(
$subcourse->intro,
$subcourse->introformat,
$context,
'mod_subcourse',
'intro'
);

$data = [
'cmid' => $cm->id,
Expand Down
1 change: 0 additions & 1 deletion classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {

use \core_privacy\local\legacy_polyfill;

// phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
Expand Down
11 changes: 5 additions & 6 deletions classes/task/check_completed_refcourses.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot.'/mod/subcourse/locallib.php');
require_once($CFG->dirroot . '/mod/subcourse/locallib.php');

/**
* Makes sure that all subcourse instances are marked as completed when they should be.
Expand All @@ -44,7 +44,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class check_completed_refcourses extends \core\task\scheduled_task {

/**
* Returns a descriptive name for this task shown to admins
*
Expand All @@ -61,8 +60,8 @@ public function get_name() {
*/
public function execute() {
global $CFG, $DB;
require_once($CFG->dirroot.'/lib/completionlib.php');
require_once($CFG->dirroot.'/completion/completion_completion.php');
require_once($CFG->dirroot . '/lib/completionlib.php');
require_once($CFG->dirroot . '/completion/completion_completion.php');

if (!completion_info::is_enabled_for_site()) {
mtrace("Completion tracking not enabled on this site");
Expand Down Expand Up @@ -94,7 +93,7 @@ public function execute() {
$course->id => (object)[
'course' => $course,
'participants' => get_enrolled_users($coursecontext, 'mod/subcourse:begraded', 0, "u.id"),
]
],
];
}

Expand All @@ -116,7 +115,7 @@ public function execute() {
}
}

mtrace(" ... checked ".count($cache[$subcourse->course]->participants)." users");
mtrace(" ... checked " . count($cache[$subcourse->course]->participants) . " users");
}

$rs->close();
Expand Down
Loading
Loading