Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'MDL-60967-master' of git://github.com/ryanwyllie/moodle
  • Loading branch information
David Monllao committed Jan 16, 2018
2 parents 174fbac + 60908b2 commit abf089f
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 9 deletions.
2 changes: 1 addition & 1 deletion calendar/amd/build/calendar_threemonth.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/repository.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

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

1 change: 1 addition & 0 deletions calendar/amd/src/calendar_threemonth.js
Expand Up @@ -71,6 +71,7 @@ function(
var placeHolder = $('<span>');
placeHolder.attr('data-template', 'core_calendar/threemonth_month');
placeHolder.attr('data-includenavigation', false);
placeHolder.attr('data-mini', true);
var placeHolderContainer = $('<div>');
placeHolderContainer.hide();
placeHolderContainer.append(placeHolder);
Expand Down
4 changes: 3 additions & 1 deletion calendar/amd/src/repository.js
Expand Up @@ -95,9 +95,10 @@ define(['jquery', 'core/ajax'], function($, Ajax) {
* @param {Number} courseid The course id.
* @param {Number} categoryid The category id.
* @param {Bool} includenavigation Whether to include navigation.
* @param {Bool} mini Whether the month is in mini view.
* @return {promise} Resolved with the month view data.
*/
var getCalendarMonthData = function(year, month, courseid, categoryid, includenavigation) {
var getCalendarMonthData = function(year, month, courseid, categoryid, includenavigation, mini) {
var request = {
methodname: 'core_calendar_get_calendar_monthly_view',
args: {
Expand All @@ -106,6 +107,7 @@ define(['jquery', 'core/ajax'], function($, Ajax) {
courseid: courseid,
categoryid: categoryid,
includenavigation: includenavigation,
mini: mini
}
};

Expand Down
3 changes: 2 additions & 1 deletion calendar/amd/src/view_manager.js
Expand Up @@ -121,7 +121,8 @@ define([

M.util.js_pending([root.get('id'), year, month, courseid].join('-'));
var includenavigation = root.data('includenavigation');
return CalendarRepository.getCalendarMonthData(year, month, courseid, categoryid, includenavigation)
var mini = root.data('mini');
return CalendarRepository.getCalendarMonthData(year, month, courseid, categoryid, includenavigation, mini)
.then(function(context) {
return Templates.render(root.attr('data-template'), context);
})
Expand Down
23 changes: 22 additions & 1 deletion calendar/classes/external/month_exporter.php
Expand Up @@ -64,6 +64,11 @@ class month_exporter extends exporter {
*/
protected $initialeventsloaded = true;

/**
* @var bool $showcoursefilter Whether to render the course filter selector as well.
*/
protected $showcoursefilter = false;

/**
* Constructor for month_exporter.
*
Expand Down Expand Up @@ -120,6 +125,7 @@ protected static function define_other_properties() {
],
'filter_selector' => [
'type' => PARAM_RAW,
'optional' => true,
],
'weeks' => [
'type' => week_exporter::read_properties_definition(),
Expand Down Expand Up @@ -206,7 +212,6 @@ protected function get_other_values(renderer_base $output) {

$return = [
'courseid' => $this->calendar->courseid,
'filter_selector' => $this->get_course_filter_selector($output),
'weeks' => $this->get_weeks($output),
'daynames' => $this->get_day_names($output),
'view' => 'month',
Expand All @@ -224,6 +229,10 @@ protected function get_other_values(renderer_base $output) {
'initialeventsloaded' => $this->initialeventsloaded,
];

if ($this->showcoursefilter) {
$return['filter_selector'] = $this->get_course_filter_selector($output);
}

if ($context = $this->get_default_add_context()) {
$return['defaulteventcontext'] = $context->id;
}
Expand Down Expand Up @@ -405,6 +414,18 @@ public function set_initialeventsloaded(bool $loaded) {
return $this;
}

/**
* Set whether the course filter selector should be shown.
*
* @param bool $show
* @return $this
*/
public function set_showcoursefilter(bool $show) {
$this->showcoursefilter = $show;

return $this;
}

/**
* Get the default context for use when adding a new event.
*
Expand Down
14 changes: 12 additions & 2 deletions calendar/externallib.php
Expand Up @@ -945,9 +945,10 @@ public static function submit_create_update_form_returns() {
* @param int $courseid The course to be included
* @param int $categoryid The category to be included
* @param bool $includenavigation Whether to include navigation
* @param bool $mini Whether to return the mini month view or not
* @return array
*/
public static function get_calendar_monthly_view($year, $month, $courseid, $categoryid, $includenavigation) {
public static function get_calendar_monthly_view($year, $month, $courseid, $categoryid, $includenavigation, $mini) {
global $CFG, $DB, $USER, $PAGE;
require_once($CFG->dirroot."/calendar/lib.php");

Expand All @@ -958,6 +959,7 @@ public static function get_calendar_monthly_view($year, $month, $courseid, $cate
'courseid' => $courseid,
'categoryid' => $categoryid,
'includenavigation' => $includenavigation,
'mini' => $mini,
]);

$context = \context_user::instance($USER->id);
Expand All @@ -970,7 +972,8 @@ public static function get_calendar_monthly_view($year, $month, $courseid, $cate
$calendar = \calendar_information::create($time, $params['courseid'], $params['categoryid']);
self::validate_context($calendar->context);

list($data, $template) = calendar_get_view($calendar, 'month', $params['includenavigation']);
$view = $params['mini'] ? 'mini' : 'month';
list($data, $template) = calendar_get_view($calendar, $view, $params['includenavigation']);

return $data;
}
Expand All @@ -994,6 +997,13 @@ public static function get_calendar_monthly_view_parameters() {
true,
NULL_ALLOWED
),
'mini' => new external_value(
PARAM_BOOL,
'Whether to return the mini month view or not',
VALUE_DEFAULT,
false,
NULL_ALLOWED
),
]
);
}
Expand Down
1 change: 1 addition & 0 deletions calendar/lib.php
Expand Up @@ -3490,6 +3490,7 @@ function ($event) {
$month = new \core_calendar\external\month_exporter($calendar, $type, $related);
$month->set_includenavigation($includenavigation);
$month->set_initialeventsloaded(!$skipevents);
$month->set_showcoursefilter($view == "month");
$data = $month->export($renderer);
} else if ($view == "day") {
$day = new \core_calendar\external\calendar_day_exporter($calendar, $related);
Expand Down

0 comments on commit abf089f

Please sign in to comment.