Skip to content

Commit

Permalink
MDL-71817 block_calendar_month: load month view in the block
Browse files Browse the repository at this point in the history
  • Loading branch information
lameze committed Jul 22, 2021
1 parent 8453fe0 commit d2f612a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
7 changes: 5 additions & 2 deletions blocks/calendar_month/block_calendar_month.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ public function get_content() {
}

$this->content = new stdClass;
$this->content->text = '';
$this->content->footer = '';

$renderer = $this->page->get_renderer('core_calendar');
$this->content->text = $renderer->start_layout();

$courseid = $this->page->course->id;
$categoryid = ($this->page->context->contextlevel === CONTEXT_COURSECAT && !empty($this->page->category)) ?
$this->page->category->id : null;
$calendar = \calendar_information::create(time(), $courseid, $categoryid);
list($data, $template) = calendar_get_view($calendar, 'mini', isloggedin(), isloggedin());
list($data, $template) = calendar_get_view($calendar, 'monthblock', isloggedin());

$renderer = $this->page->get_renderer('core_calendar');
$this->content->text .= $renderer->render_from_template($template, $data);
Expand All @@ -67,6 +69,7 @@ public function get_content() {
];
list($footerdata, $footertemplate) = calendar_get_footer_options($calendar, $options);
$this->content->footer .= $renderer->render_from_template($footertemplate, $footerdata);
$this->content->text .= $renderer->complete_layout();

return $this->content;
}
Expand Down
2 changes: 1 addition & 1 deletion calendar/amd/build/view_manager.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion calendar/amd/build/view_manager.min.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions calendar/amd/src/view_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export const refreshMonthContent = (root, year, month, courseId, categoryId, tar
return CalendarRepository.getCalendarMonthData(year, month, courseId, categoryId, includenavigation, mini, day)
.then(context => {
context.viewingmonth = true;
context.showviewselector = !mini;
return Templates.render(template, context);
})
.then((html, js) => {
Expand Down Expand Up @@ -241,6 +242,7 @@ export const refreshDayContent = (root, year, month, day, courseId, categoryId,
return CalendarRepository.getCalendarDayData(year, month, day, courseId, categoryId, includenavigation)
.then((context) => {
context.viewingday = true;
context.showviewselector = true;
return Templates.render(template, context);
})
.then((html, js) => {
Expand Down Expand Up @@ -348,6 +350,7 @@ export const reloadCurrentUpcoming = (root, courseId = 0, categoryId = 0, target
return CalendarRepository.getCalendarUpcomingData(courseId, categoryId)
.then((context) => {
context.viewingupcoming = true;
context.showviewselector = true;
return Templates.render(template, context);
})
.then((html, js) => {
Expand Down
7 changes: 5 additions & 2 deletions calendar/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3493,17 +3493,19 @@ function ($event) {
];

$data = [];
if ($view == "month" || $view == "mini" || $view == "minithree") {
if ($view == "month" || $view == "monthblock" || $view == "mini" || $view == "minithree" ) {
$month = new \core_calendar\external\month_exporter($calendar, $type, $related);
$month->set_includenavigation($includenavigation);
$month->set_initialeventsloaded(!$skipevents);
$month->set_showcoursefilter($view == "month");
$month->set_showcoursefilter(($view == "month" || $view == "monthblock"));
$data = $month->export($renderer);
$data->viewingmonth = true;
$data->showviewselector = ($view == "month");
} else if ($view == "day") {
$day = new \core_calendar\external\calendar_day_exporter($calendar, $related);
$data = $day->export($renderer);
$data->viewingday = true;
$data->showviewselector = true;
$template = 'core_calendar/calendar_day';
} else if ($view == "upcoming" || $view == "upcoming_mini") {
$upcoming = new \core_calendar\external\calendar_upcoming_exporter($calendar, $related);
Expand All @@ -3512,6 +3514,7 @@ function ($event) {
if ($view == "upcoming") {
$template = 'core_calendar/calendar_upcoming';
$data->viewingupcoming = true;
$data->showviewselector = true;
} else if ($view == "upcoming_mini") {
$template = 'core_calendar/calendar_upcoming_mini';
}
Expand Down
4 changes: 3 additions & 1 deletion calendar/templates/header.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
}
}}
<div class="header d-flex flex-wrap p-1">
{{> core_calendar/view_selector}}
{{#showviewselector}}
{{> core_calendar/view_selector}}
{{/showviewselector}}
{{#filter_selector}}
{{{filter_selector}}}
{{/filter_selector}}
Expand Down

0 comments on commit d2f612a

Please sign in to comment.