mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 04:30:15 +01:00
Merge branch 'MDL-81610_main' of https://github.com/marxjohnson/moodle
This commit is contained in:
commit
0767670829
6
course/format/classes/external/get_state.php
vendored
6
course/format/classes/external/get_state.php
vendored
@ -60,7 +60,7 @@ class get_state extends external_api {
|
||||
* @return string Course state in JSON
|
||||
*/
|
||||
public static function execute(int $courseid): string {
|
||||
global $PAGE, $CFG;
|
||||
global $PAGE, $CFG, $USER;
|
||||
|
||||
require_once($CFG->dirroot.'/course/lib.php');
|
||||
|
||||
@ -73,6 +73,8 @@ class get_state extends external_api {
|
||||
|
||||
$courseformat = course_get_format($courseid);
|
||||
$modinfo = $courseformat->get_modinfo();
|
||||
$completioninfo = new \completion_info(get_course($courseid));
|
||||
$istrackeduser = $completioninfo->is_tracked_user($USER->id);
|
||||
|
||||
// Get the proper renderer.
|
||||
$renderer = $courseformat->get_renderer($PAGE);
|
||||
@ -106,7 +108,7 @@ class get_state extends external_api {
|
||||
if ($cm->is_visible_on_course_page()) {
|
||||
// Only return this course module data if it's visible by current user on the course page.
|
||||
$section = $sections[$cm->sectionnum];
|
||||
$cmstate = new $cmclass($courseformat, $section, $cm);
|
||||
$cmstate = new $cmclass($courseformat, $section, $cm, istrackeduser: $istrackeduser);
|
||||
$result->cm[] = $cmstate->export_for_template($renderer);
|
||||
}
|
||||
}
|
||||
|
@ -33,37 +33,26 @@ require_once($CFG->libdir . '/completionlib.php');
|
||||
/**
|
||||
* Contains the ajax update course module structure.
|
||||
*
|
||||
* @package core_course
|
||||
* @package core_courseformat
|
||||
* @copyright 2021 Ferran Recio <ferran@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class cm implements renderable {
|
||||
|
||||
/** @var course_format the course format class */
|
||||
protected $format;
|
||||
|
||||
/** @var section_info the course section class */
|
||||
protected $section;
|
||||
|
||||
/** @var bool if cmitem HTML content must be exported as well */
|
||||
protected $exportcontent;
|
||||
|
||||
/** @var cm_info the course module to display */
|
||||
protected $cm;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param course_format $format the course format
|
||||
* @param section_info $section the section data
|
||||
* @param cm_info $cm the course module data
|
||||
* @param bool $exportcontent = false if pre-rendered cmitem must be exported.
|
||||
*/
|
||||
public function __construct(course_format $format, section_info $section, cm_info $cm, bool $exportcontent = false) {
|
||||
$this->format = $format;
|
||||
$this->section = $section;
|
||||
$this->cm = $cm;
|
||||
$this->exportcontent = $exportcontent;
|
||||
public function __construct(
|
||||
/** @var course_format $format The course format. */
|
||||
protected course_format $format,
|
||||
/** @var section_info $section The section data. */
|
||||
protected section_info $section,
|
||||
/** @var cm_info $cm The course module data. */
|
||||
protected cm_info $cm,
|
||||
/** @var bool $exportcontent False if pre-rendered cmitem HTML content must be exported. */
|
||||
protected bool $exportcontent = false,
|
||||
/** @var ?bool $istrackeduser If is_tracked_user is pre-computed for this CM's course, it can be provided here. */
|
||||
protected ?bool $istrackeduser = null,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
@ -115,7 +104,7 @@ class cm implements renderable {
|
||||
|
||||
// Completion status.
|
||||
$completioninfo = new completion_info($course);
|
||||
$data->istrackeduser = $completioninfo->is_tracked_user($USER->id);
|
||||
$data->istrackeduser = $this->istrackeduser ?? $completioninfo->is_tracked_user($USER->id);
|
||||
if ($data->istrackeduser && $completioninfo->is_enabled($cm)) {
|
||||
$completiondata = $completioninfo->get_data($cm);
|
||||
$data->completionstate = $completiondata->completionstate;
|
||||
|
Loading…
x
Reference in New Issue
Block a user