mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 17:06:53 +02:00
Merge branch 'MDL-60156-master' of git://github.com/andrewnicols/moodle
This commit is contained in:
commit
25759080d6
4 changed files with 83 additions and 31 deletions
28
calendar/classes/external/month_exporter.php
vendored
28
calendar/classes/external/month_exporter.php
vendored
|
@ -162,6 +162,10 @@ class month_exporter extends exporter {
|
|||
// The right arrow defined by the theme.
|
||||
'type' => PARAM_RAW,
|
||||
],
|
||||
'defaulteventcontext' => [
|
||||
'type' => PARAM_INT,
|
||||
'default' => null,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -182,7 +186,7 @@ class month_exporter extends exporter {
|
|||
$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),
|
||||
|
@ -200,6 +204,12 @@ class month_exporter extends exporter {
|
|||
'rarrow' => $output->rarrow(),
|
||||
'includenavigation' => $this->includenavigation,
|
||||
];
|
||||
|
||||
if ($context = $this->get_default_add_context()) {
|
||||
$return['defaulteventcontext'] = $context->id;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -211,9 +221,6 @@ class month_exporter extends exporter {
|
|||
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;
|
||||
}
|
||||
|
@ -361,4 +368,17 @@ class month_exporter extends exporter {
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,37 +114,20 @@ class core_calendar_renderer extends plugin_renderer_base {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
43
calendar/templates/add_event_button.mustache
Normal file
43
calendar/templates/add_event_button.mustache
Normal file
|
@ -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}}
|
|
@ -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">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue