Skip to content

Commit

Permalink
Merge branch 'MDL-60156-master' of git://github.com/andrewnicols/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Sep 26, 2017
2 parents 536572c + 3fb45f5 commit 2575908
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 31 deletions.
28 changes: 24 additions & 4 deletions calendar/classes/external/month_exporter.php
Expand Up @@ -162,6 +162,10 @@ protected static function define_other_properties() {
// The right arrow defined by the theme.
'type' => PARAM_RAW,
],
'defaulteventcontext' => [
'type' => PARAM_INT,
'default' => null,
],
];
}

Expand All @@ -182,7 +186,7 @@ protected function get_other_values(renderer_base $output) {
$previousperiodlink = new moodle_url($this->url);
$previousperiodlink->param('time', $previousperiod[0]);

return [
$return = [
'courseid' => $this->calendar->courseid,
'filter_selector' => $this->get_course_filter_selector($output),
'weeks' => $this->get_weeks($output),
Expand All @@ -200,6 +204,12 @@ protected function get_other_values(renderer_base $output) {
'rarrow' => $output->rarrow(),
'includenavigation' => $this->includenavigation,
];

if ($context = $this->get_default_add_context()) {
$return['defaulteventcontext'] = $context->id;
}

return $return;
}

/**
Expand All @@ -211,9 +221,6 @@ protected function get_other_values(renderer_base $output) {
protected function get_course_filter_selector(renderer_base $output) {
$content = '';
$content .= $output->course_filter_selector($this->url, get_string('detailedmonthviewfor', 'calendar'));
if (calendar_user_can_add_event($this->calendar->course)) {
$content .= $output->add_event_button($this->calendar->courseid, 0, 0, 0, $this->calendar->time);
}

return $content;
}
Expand Down Expand Up @@ -361,4 +368,17 @@ public function set_includenavigation($include) {

return $this;
}

/**
* Get the default context for use when adding a new event.
*
* @return null|\context
*/
protected function get_default_add_context() {
if (calendar_user_can_add_event($this->calendar->course)) {
return \context_course::instance($this->calendar->course->id);
}

return null;
}
}
35 changes: 9 additions & 26 deletions calendar/renderer.php
Expand Up @@ -114,37 +114,20 @@ public function add_pretend_calendar_block(block_contents $bc, $pos=BLOCK_POS_RI
}

/**
* Creates a button to add a new event
* Creates a button to add a new event.
*
* @param int $courseid
* @param int $day
* @param int $month
* @param int $year
* @param int $time the unixtime, used for multiple calendar support. The values $day,
* $month and $year are kept for backwards compatibility.
* @param int $unused1
* @param int $unused2
* @param int $unused3
* @param int $unused4
* @return string
*/
public function add_event_button($courseid, $day = null, $month = null, $year = null, $time = null) {
// If a day, month and year were passed then convert it to a timestamp. If these were passed
// then we can assume the day, month and year are passed as Gregorian, as no where in core
// should we be passing these values rather than the time. This is done for BC.
if (!empty($day) && !empty($month) && !empty($year)) {
if (checkdate($month, $day, $year)) {
$time = make_timestamp($year, $month, $day);
} else {
$time = time();
}
} else if (empty($time)) {
$time = time();
}

$coursecontext = \context_course::instance($courseid);
$attributes = [
'class' => 'btn btn-secondary pull-xs-right pull-right',
'data-context-id' => $coursecontext->id,
'data-action' => 'new-event-button'
public function add_event_button($courseid, $unused1 = null, $unused2 = null, $unused3 = null, $unused4 = null) {
$data = [
'contextid' => (\context_course::instance($courseid))->id,
];
return html_writer::tag('button', get_string('newevent', 'calendar'), $attributes);
return $this->render_from_template('core_calendar/add_event_button', $data);
}

/**
Expand Down
43 changes: 43 additions & 0 deletions calendar/templates/add_event_button.mustache
@@ -0,0 +1,43 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template calendar/add_event_button
Button to launch the "Add new event" dialogue.
The purpose of this template is to render the button used to generate the new event dialogue.
Classes required for JS:
* none
Data attributes required for JS:
* none
Example context (json):
{
"defaulteventcontext": "2"
}
}}
{{#defaulteventcontext}}
<button{{!
}} class="btn btn-secondary pull-xs-right pull-right"{{!
}} data-context-id="{{defaulteventcontext}}"{{!
}} data-action="new-event-button"{{!
}}>
{{#str}}newevent, core_calendar{{/str}}
</button>
{{/defaulteventcontext}}
8 changes: 7 additions & 1 deletion calendar/templates/month_detailed.mustache
Expand Up @@ -31,8 +31,14 @@
{
}
}}
<div class="calendarwrapper" data-courseid="{{courseid}}" data-month="{{date.mon}}" data-year="{{date.year}}">
<div{{!
}} class="calendarwrapper"{{!
}} data-courseid="{{courseid}}"{{!
}} data-month="{{date.mon}}"{{!
}} data-year="{{date.year}}"{{!
}}>
{{> core_calendar/header }}
{{> core_calendar/add_event_button}}
{{> core_calendar/month_navigation }}
{{> core/overlay_loading}}
<table id="month-detailed-{{uniqid}}" class="calendarmonth calendartable card-deck m-b-0">
Expand Down

0 comments on commit 2575908

Please sign in to comment.