MDL-59392 calendar: Add the calendar info to the exporter

This commit is contained in:
Andrew Nicols
2017-09-11 10:00:49 +08:00
parent fb9be27127
commit 39e40fda71
3 changed files with 29 additions and 3 deletions
+18
View File
@@ -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.
*
+2 -2
View File
@@ -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);
}
+9 -1
View File
@@ -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);
}