mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-58098 block_myoverview: change renderables to load courses once
Part of MDL-55611 epic.
This commit is contained in:
parent
bea71d5732
commit
eb481a3e52
@ -36,6 +36,18 @@ use templatable;
|
||||
*/
|
||||
class course_summary implements renderable, templatable {
|
||||
|
||||
/** @var array $courses List of courses the user is enrolled in. */
|
||||
protected $courses = [];
|
||||
|
||||
/**
|
||||
* The course_summary constructor.
|
||||
*
|
||||
* @param array $courses list of courses.
|
||||
*/
|
||||
public function __construct($courses) {
|
||||
$this->courses = $courses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export this data so it can be used as the context for a mustache template.
|
||||
*
|
||||
@ -43,12 +55,11 @@ class course_summary implements renderable, templatable {
|
||||
* @return stdClass
|
||||
*/
|
||||
public function export_for_template(renderer_base $output) {
|
||||
$courses = enrol_get_my_courses('*');
|
||||
|
||||
$data = [];
|
||||
foreach ($courses as $courseid => $value) {
|
||||
foreach ($this->courses as $courseid => $value) {
|
||||
$context = \context_course::instance($courseid);
|
||||
$exporter = new course_summary_exporter($courses[$courseid], array('context' => $context));
|
||||
$exporter = new course_summary_exporter($this->courses[$courseid], array('context' => $context));
|
||||
$data[] = $exporter->export($output);
|
||||
}
|
||||
return $data;
|
||||
|
@ -37,6 +37,18 @@ class courses_view implements renderable, templatable {
|
||||
/** Quantity of courses per page. */
|
||||
const COURSES_PER_PAGE = 6;
|
||||
|
||||
/** @var array $courses List of courses the user is enrolled in. */
|
||||
protected $courses = [];
|
||||
|
||||
/**
|
||||
* The courses_view constructor.
|
||||
*
|
||||
* @param array $courses list of courses.
|
||||
*/
|
||||
public function __construct($courses) {
|
||||
$this->courses = $courses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export this data so it can be used as the context for a mustache template.
|
||||
*
|
||||
@ -44,12 +56,11 @@ class courses_view implements renderable, templatable {
|
||||
* @return stdClass
|
||||
*/
|
||||
public function export_for_template(renderer_base $output) {
|
||||
$courses = enrol_get_my_courses('startdate, enddate');
|
||||
$today = time();
|
||||
|
||||
// How many courses we have per status?
|
||||
$coursesbystatus = ['past' => 0, 'inprogress' => 0, 'future' => 0];
|
||||
foreach ($courses as $course) {
|
||||
foreach ($this->courses as $course) {
|
||||
$startdate = $course->startdate;
|
||||
$enddate = $course->enddate;
|
||||
|
||||
|
@ -42,8 +42,11 @@ class main implements renderable, templatable {
|
||||
* @return stdClass
|
||||
*/
|
||||
public function export_for_template(renderer_base $output) {
|
||||
$coursesummary = new course_summary();
|
||||
$coursesview = new courses_view();
|
||||
|
||||
$courses = enrol_get_my_courses('id, shortname, startdate, enddate, summary');
|
||||
|
||||
$coursesummary = new course_summary($courses);
|
||||
$coursesview = new courses_view($courses);
|
||||
|
||||
return [
|
||||
'courses' => $coursesummary->export_for_template($output),
|
||||
|
Loading…
x
Reference in New Issue
Block a user