From 39e40fda71a1aa40e9f9a4a70703b0a0913f136e Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 5 Sep 2017 15:17:50 +0800 Subject: [PATCH] MDL-59392 calendar: Add the calendar info to the exporter --- calendar/classes/external/day_exporter.php | 18 ++++++++++++++++++ calendar/classes/external/month_exporter.php | 4 ++-- calendar/classes/external/week_exporter.php | 10 +++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/calendar/classes/external/day_exporter.php b/calendar/classes/external/day_exporter.php index eec64847461..90b5c73e3ae 100644 --- a/calendar/classes/external/day_exporter.php +++ b/calendar/classes/external/day_exporter.php @@ -39,6 +39,24 @@ use moodle_url; */ class day_exporter extends exporter { + /** + * @var \calendar_information $calendar The calendar being displayed. + */ + protected $calendar; + + /** + * Constructor. + * + * @param \calendar_information $calendar The calendar information for the period being displayed + * @param mixed $data Either an stdClass or an array of values. + * @param array $related Related objects. + */ + public function __construct(\calendar_information $calendar, $data, $related) { + $this->calendar = $calendar; + + parent::__construct($data, $related); + } + /** * Return the list of properties. * diff --git a/calendar/classes/external/month_exporter.php b/calendar/classes/external/month_exporter.php index 9b99498e910..870687e9637 100644 --- a/calendar/classes/external/month_exporter.php +++ b/calendar/classes/external/month_exporter.php @@ -213,13 +213,13 @@ class month_exporter extends exporter { $prepadding = ($firstdayno + $daysinweek - 1) % $daysinweek; $daysinfirstweek = $daysinweek - $prepadding; $days = array_slice($alldays, 0, $daysinfirstweek); - $week = new week_exporter($days, $prepadding, ($daysinweek - count($days) - $prepadding), $this->related); + $week = new week_exporter($this->calendar, $days, $prepadding, ($daysinweek - count($days) - $prepadding), $this->related); $weeks[] = $week->export($output); // Now chunk up the remaining day. and turn them into weeks. $daychunks = array_chunk(array_slice($alldays, $daysinfirstweek), $daysinweek); foreach ($daychunks as $days) { - $week = new week_exporter($days, 0, ($daysinweek - count($days)), $this->related); + $week = new week_exporter($this->calendar, $days, 0, ($daysinweek - count($days)), $this->related); $weeks[] = $week->export($output); } diff --git a/calendar/classes/external/week_exporter.php b/calendar/classes/external/week_exporter.php index b8bb4da63fc..f0b6c4d7d4e 100644 --- a/calendar/classes/external/week_exporter.php +++ b/calendar/classes/external/week_exporter.php @@ -53,18 +53,26 @@ class week_exporter extends exporter { */ protected $postpadding = 0; + + /** + * @var \calendar_information $calendar The calendar being displayed. + */ + protected $calendar; + /** * Constructor. * + * @param \calendar_information $calendar The calendar information for the period being displayed * @param mixed $days An array of day_exporter objects. * @param int $prepadding The number of pre-padding days at the start of the week. * @param int $postpadding The number of post-padding days at the start of the week. * @param array $related Related objects. */ - public function __construct($days, $prepadding, $postpadding, $related) { + public function __construct(\calendar_information $calendar, $days, $prepadding, $postpadding, $related) { $this->days = $days; $this->prepadding = $prepadding; $this->postpadding = $postpadding; + $this->calendar = $calendar; parent::__construct([], $related); }