Merge branch 'MDL-59733-master' of https://github.com/xow/moodle
authorJun Pataleta <jun@moodle.com>
Mon, 21 Aug 2017 02:40:27 +0000 (10:40 +0800)
committerJun Pataleta <jun@moodle.com>
Mon, 21 Aug 2017 02:40:27 +0000 (10:40 +0800)
95 files changed:
admin/tool/recyclebin/tests/events_test.php
analytics/classes/manager.php
backup/util/helper/backup_anonymizer_helper.class.php
backup/util/plan/backup_plan.class.php
blocks/myoverview/classes/output/courses_view.php
blocks/myoverview/templates/course-event-list.mustache
blocks/myoverview/templates/course-summary.mustache
blocks/myoverview/templates/courses-view-course-item.mustache
calendar/amd/build/calendar.min.js
calendar/amd/build/events.min.js
calendar/amd/build/repository.min.js
calendar/amd/build/view_manager.min.js [new file with mode: 0644]
calendar/amd/src/calendar.js
calendar/amd/src/event_form.js
calendar/amd/src/events.js
calendar/amd/src/repository.js
calendar/amd/src/view_manager.js [new file with mode: 0644]
calendar/classes/external/calendar_event_exporter.php [new file with mode: 0644]
calendar/classes/external/day_exporter.php [new file with mode: 0644]
calendar/classes/external/day_name_exporter.php [new file with mode: 0644]
calendar/classes/external/event_exporter.php
calendar/classes/external/event_exporter_base.php [new file with mode: 0644]
calendar/classes/external/footer_options_exporter.php [new file with mode: 0644]
calendar/classes/external/month_exporter.php [new file with mode: 0644]
calendar/classes/external/week_exporter.php [new file with mode: 0644]
calendar/classes/local/api.php
calendar/classes/type_base.php
calendar/externallib.php
calendar/lib.php
calendar/renderer.php
calendar/templates/footer_options.mustache [new file with mode: 0644]
calendar/templates/month_detailed.mustache [new file with mode: 0644]
calendar/templates/month_header.mustache [new file with mode: 0644]
calendar/templates/month_navigation.mustache [new file with mode: 0644]
calendar/tests/externallib_test.php
calendar/view.php
course/classes/management/helper.php
course/edit.php
course/format/topics/tests/behat/edit_delete_sections.feature
course/format/weeks/tests/behat/edit_delete_sections.feature
course/tests/behat/behat_course.php
course/tests/courselib_test.php
enrol/bulkchange.php [deleted file]
enrol/flatfile/lib.php
enrol/locallib.php
enrol/lti/lib.php
enrol/manual/lib.php
enrol/manual/manage.php
enrol/meta/tests/behat/enrol_meta.feature
enrol/paypal/lib.php
enrol/renderer.php
enrol/self/lib.php
enrol/tests/behat/add_to_group.feature
enrol/tests/behat/filter_enrolled_users.feature [deleted file]
enrol/upgrade.txt
enrol/users.php [deleted file]
grade/tests/behat/grade_average.feature
install/lang/el/moodle.php
install/lang/es_mx_kids/langconfig.php
install/lang/fa/error.php
lang/en/moodle.php
lib/amd/build/form-autocomplete.min.js
lib/amd/build/modal_factory.min.js
lib/amd/src/form-autocomplete.js
lib/amd/src/modal_factory.js
lib/authlib.php
lib/classes/analytics/target/no_teaching.php
lib/classes/event/course_backup_created.php [new file with mode: 0644]
lib/classes/event/user_enrolment_created.php
lib/classes/event/user_enrolment_deleted.php
lib/db/services.php
lib/enrollib.php
lib/form/submit.php
lib/form/yui/build/moodle-form-dateselector/moodle-form-dateselector-debug.js
lib/form/yui/build/moodle-form-dateselector/moodle-form-dateselector-min.js
lib/form/yui/build/moodle-form-dateselector/moodle-form-dateselector.js
lib/form/yui/src/dateselector/js/dateselector.js
lib/oauthlib.php
lib/templates/single_button.mustache [new file with mode: 0644]
lib/weblib.php
mod/book/view.php
mod/forum/discuss.php
report/log/lib.php
theme/boost/scss/moodle/calendar.scss
theme/bootstrapbase/less/moodle/bs4-compat.less
theme/bootstrapbase/less/moodle/calendar.less
theme/bootstrapbase/style/moodle.css
theme/bootstrapbase/templates/block_myoverview/course-event-list.mustache
theme/bootstrapbase/templates/block_myoverview/course-summary.mustache
theme/bootstrapbase/templates/block_myoverview/courses-view-course-item.mustache
user/amd/build/status_field.min.js
user/amd/src/status_field.js
user/templates/status_details.mustache
user/tests/behat/edit_user_enrolment.feature
version.php

index 80ab6aa..d10fa93 100644 (file)
@@ -60,6 +60,8 @@ class tool_recyclebin_events_testcase extends advanced_testcase {
         delete_course($course, false);
         $events = $sink->get_events();
         $event = reset($events);
+        // Need the second event here, the first is backup created.
+        $event = next($events);
 
         // Get the item from the recycle bin.
         $rb = new \tool_recyclebin\category_bin($course->category);
index 581f917..80f80cd 100644 (file)
@@ -84,15 +84,9 @@ class manager {
 
         $params = array();
 
-        $fields = 'am.id, am.enabled, am.trained, am.target, ' . $DB->sql_compare_text('am.indicators') .
-            ', am.timesplitting, am.version, am.timecreated, am.timemodified, am.usermodified';
-        $sql = "SELECT DISTINCT $fields FROM {analytics_models} am";
-        if ($predictioncontext) {
-            $sql .= " JOIN {analytics_predictions} ap ON ap.modelid = am.id AND ap.contextid = :contextid";
-            $params['contextid'] = $predictioncontext->id;
-        }
+        $sql = "SELECT am.* FROM {analytics_models} am";
 
-        if ($enabled || $trained) {
+        if ($enabled || $trained || $predictioncontext) {
             $conditions = [];
             if ($enabled) {
                 $conditions[] = 'am.enabled = :enabled';
@@ -102,6 +96,10 @@ class manager {
                 $conditions[] = 'am.trained = :trained';
                 $params['trained'] = 1;
             }
+            if ($predictioncontext) {
+                $conditions[] = "EXISTS (SELECT 'x' FROM {analytics_predictions} ap WHERE ap.modelid = am.id AND ap.contextid = :contextid)";
+                $params['contextid'] = $predictioncontext->id;
+            }
             $sql .= ' WHERE ' . implode(' AND ', $conditions);
         }
         $sql .= ' ORDER BY am.enabled DESC, am.timemodified DESC';
index f3b5925..9ccd887 100644 (file)
@@ -56,8 +56,10 @@ class backup_anonymizer_helper {
         if (preg_match('/^anon\d*$/', $user->username)) {
             $match = preg_match('/^anonfirstname\d*$/', $user->firstname);
             $match = $match && preg_match('/^anonlastname\d*$/', $user->lastname);
-            $match = $match && preg_match('/^anon\d*@doesntexist\.com$/', $user->email);
-            if ($match) {
+            // Check .com for backwards compatibility.
+            $emailmatch = preg_match('/^anon\d*@doesntexist\.com$/', $user->email) ||
+                preg_match('/^anon\d*@doesntexist\.invalid$/', $user->email);
+            if ($match && $emailmatch) {
                 return true;
             }
         }
@@ -93,7 +95,7 @@ class backup_anonymizer_helper {
     public static function process_user_email($value) {
         static $counter = 0;
         $counter++;
-        return 'anon' . $counter . '@doesntexist.com'; // Just a counter
+        return 'anon' . $counter . '@doesntexist.invalid'; // Just a counter.
     }
 
     public static function process_user_icq($value) {
index 2fcb469..954ecb0 100644 (file)
@@ -119,6 +119,21 @@ class backup_plan extends base_plan implements loggable {
         $this->controller->set_status(backup::STATUS_EXECUTING);
         parent::execute();
         $this->controller->set_status(backup::STATUS_FINISHED_OK);
+
+        if ($this->controller->get_type() === backup::TYPE_1COURSE) {
+            // Trigger a course_backup_created event.
+            $otherarray = array('format' => $this->controller->get_format(),
+                                'mode' => $this->controller->get_mode(),
+                                'interactive' => $this->controller->get_interactive(),
+                                'type' => $this->controller->get_type(),
+            );
+            $event = \core\event\course_backup_created::create(array(
+                'objectid' => $this->get_courseid(),
+                'context' => context_course::instance($this->get_courseid()),
+                'other' => $otherarray
+            ));
+            $event->trigger();
+        }
     }
 }
 
index 2949c09..2f8cb9a 100644 (file)
@@ -83,6 +83,9 @@ class courses_view implements renderable, templatable {
             // Convert summary to plain text.
             $exportedcourse->summary = content_to_text($exportedcourse->summary, $exportedcourse->summaryformat);
 
+            // Include course visibility.
+            $exportedcourse->visible = (bool)$course->visible;
+
             $courseprogress = null;
 
             $classified = course_classify_for_timeline($course);
index 74922d6..d9e729a 100644 (file)
@@ -22,6 +22,9 @@
 
     Example context (json):
     {
+        "urls": {
+            "noevents": "#"
+        }
     }
 }}
 <div data-region="event-list-container"
@@ -93,7 +96,7 @@
              alt="{{#str}} noevents, block_myoverview {{/str}}"
              role="presentation">
         <p class="text-muted m-t-1">{{#str}} noevents, block_myoverview {{/str}}</p>
-        <a href="{{viewurl}}" class="btn btn-secondary text-primary"
+        <a href="{{viewurl}}" class="btn btn-secondary {{#visible}}text-primary{{/visible}}"
            aria-label="{{#str}} viewcoursename, block_myoverview, {{fullnamedisplay}} {{/str}}">
             {{#str}} viewcourse, block_myoverview {{/str}}
         </a>
index 21368a7..acc214b 100644 (file)
 <div class="course-info-container" id="course-info-container-{{id}}">
     <div class="hidden-sm-up hidden-tablet hidden-phone">
         {{> block_myoverview/progress-chart}}
-        <h4 class="h5"><a href="{{viewurl}}">{{{fullnamedisplay}}}</a></h4>
+        <h4 class="h5"><a href="{{viewurl}}" class="{{^visible}}dimmed{{/visible}}">{{{fullnamedisplay}}}</a></h4>
     </div>
     <div class="hidden-sm-down hidden-tablet hidden-desktop">
         {{> block_myoverview/progress-chart}}
-        <h4 class="h5"><a href="{{viewurl}}">{{{fullnamedisplay}}}</a></h4>
+        <h4 class="h5"><a href="{{viewurl}}" class="{{^visible}}dimmed{{/visible}}">{{{fullnamedisplay}}}</a></h4>
     </div>
     <div class="hidden-xs-down hidden-md-up visible-tablet">
         <div class="media">
@@ -43,7 +43,7 @@
                 </div>
             </div>
             <div class="media-body">
-                <h4 class="h5"><a href="{{viewurl}}">{{{fullnamedisplay}}}</a></h4>
+                <h4 class="h5"><a href="{{viewurl}}" class="{{^visible}}dimmed{{/visible}}">{{{fullnamedisplay}}}</a></h4>
             </div>
         </div>
     </div>
index b2f39a8..fd8a4fb 100644 (file)
@@ -31,7 +31,7 @@
         <div class="card-block course-info-container" id="course-info-container-{{id}}">
             <div class="hidden-sm-up hidden-phone">
                 {{> block_myoverview/progress-chart}}
-                <h4 class="h5"><a href="{{viewurl}}">{{{fullnamedisplay}}}</a></h4>
+                <h4 class="h5"><a href="{{viewurl}}" class="{{^visible}}dimmed{{/visible}}">{{{fullnamedisplay}}}</a></h4>
             </div>
             <div class="hidden-xs-down visible-phone">
                 <div class="media">
@@ -41,7 +41,7 @@
                         </div>
                     </div>
                     <div class="media-body">
-                        <h4 class="h5"><a href="{{viewurl}}">{{{fullnamedisplay}}}</a></h4>
+                        <h4 class="h5"><a href="{{viewurl}}" class="{{^visible}}dimmed{{/visible}}">{{{fullnamedisplay}}}</a></h4>
                     </div>
                 </div>
             </div>
index f21a625..24a5810 100644 (file)
Binary files a/calendar/amd/build/calendar.min.js and b/calendar/amd/build/calendar.min.js differ
index 0c310d9..ca56cb1 100644 (file)
Binary files a/calendar/amd/build/events.min.js and b/calendar/amd/build/events.min.js differ
index 27c0538..8cc9d4b 100644 (file)
Binary files a/calendar/amd/build/repository.min.js and b/calendar/amd/build/repository.min.js differ
diff --git a/calendar/amd/build/view_manager.min.js b/calendar/amd/build/view_manager.min.js
new file mode 100644 (file)
index 0000000..384490f
Binary files /dev/null and b/calendar/amd/build/view_manager.min.js differ
index a08f1c3..570c8c6 100644 (file)
@@ -37,7 +37,8 @@ define([
             'core_calendar/modal_event_form',
             'core_calendar/summary_modal',
             'core_calendar/repository',
-            'core_calendar/events'
+            'core_calendar/events',
+            'core_calendar/view_manager'
         ],
         function(
             $,
@@ -51,7 +52,8 @@ define([
             ModalEventForm,
             SummaryModal,
             CalendarRepository,
-            CalendarEvents
+            CalendarEvents,
+            CalendarViewManager
         ) {
 
     var SELECTORS = {
@@ -173,7 +175,7 @@ define([
                     contextid: contextId
                 }
             },
-            newEventButton
+            [root, SELECTORS.NEW_EVENT_BUTTON]
         );
     };
 
@@ -222,7 +224,7 @@ define([
         var root = $(SELECTORS.ROOT);
 
         // Bind click events to event links.
-        $(SELECTORS.EVENT_LINK).click(function(e) {
+        root.on('click', SELECTORS.EVENT_LINK, function(e) {
             e.preventDefault();
             var eventId = $(this).attr('data-event-id');
             renderEventSummaryModal(eventId);
@@ -234,6 +236,7 @@ define([
 
     return {
         init: function() {
+            CalendarViewManager.init();
             registerEventListeners();
         }
     };
index e62ee63..0a4e33e 100644 (file)
@@ -249,7 +249,7 @@ define(['jquery', 'core/templates'], function($, Templates) {
     };
 
     /**
-     * Initialise all of the form enhancementds.
+     * Initialise all of the form enhancements.
      *
      * @method init
      * @param {string} formId The value of the form's id attribute
index 47aac12..465e337 100644 (file)
@@ -28,6 +28,7 @@ define([], function() {
         deleted: 'calendar-events:deleted',
         updated: 'calendar-events:updated',
         editEvent: 'calendar-events:edit_event',
-        editActionEvent: 'calendar-events:edit_action_event'
+        editActionEvent: 'calendar-events:edit_action_event',
+        monthChanged: 'calendar-events:month_changed'
     };
 });
index 0f96079..5c95483 100644 (file)
@@ -83,9 +83,30 @@ define(['jquery', 'core/ajax'], function($, Ajax) {
         return Ajax.call([request])[0];
     };
 
+    /**
+     * Get calendar data for the month view.
+     *
+     * @method getCalendarMonthData
+     * @param {Number} time Timestamp.
+     * @param {Number} courseid The course id.
+     * @return {promise} Resolved with the month view data.
+     */
+    var getCalendarMonthData = function(time, courseid) {
+        var request = {
+            methodname: 'core_calendar_get_calendar_monthly_view',
+            args: {
+                time: time,
+                courseid: courseid
+            }
+        };
+
+        return Ajax.call([request])[0];
+    };
+
     return {
         getEventById: getEventById,
         deleteEvent: deleteEvent,
-        submitCreateUpdateForm: submitCreateUpdateForm
+        submitCreateUpdateForm: submitCreateUpdateForm,
+        getCalendarMonthData: getCalendarMonthData
     };
 });
diff --git a/calendar/amd/src/view_manager.js b/calendar/amd/src/view_manager.js
new file mode 100644 (file)
index 0000000..6eb6269
--- /dev/null
@@ -0,0 +1,77 @@
+// 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/>.
+
+/**
+ * A javascript module to handler calendar view changes.
+ *
+ * @module     core_calendar/view_manager
+ * @package    core_calendar
+ * @copyright  2017 Andrew Nicols <andrew@nicols.co.uk>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+define(['jquery', 'core/templates', 'core/notification', 'core_calendar/repository', 'core_calendar/events'],
+    function($, Templates, Notification, CalendarRepository, CalendarEvents) {
+
+        var SELECTORS = {
+            ROOT: "[data-region='calendar']",
+            CALENDAR_NAV_LINK: "span.calendarwrapper .arrow_link",
+            CALENDAR_MONTH_WRAPPER: ".calendarwrapper",
+        };
+
+        /**
+         * Register event listeners for the module.
+         *
+         * @param {object} root The root element.
+         */
+        var registerEventListeners = function(root) {
+            root = $(root);
+
+            root.on('click', SELECTORS.CALENDAR_NAV_LINK, function(e) {
+                var courseId = $(root).find(SELECTORS.CALENDAR_MONTH_WRAPPER).data('courseid');
+                var link = $(e.currentTarget);
+                changeMonth(link.attr('href'), link.data('time'), courseId);
+
+                e.preventDefault();
+            });
+        };
+
+        /**
+         * Handle changes to the current calendar view.
+         *
+         * @param {String} url The calendar url to be shown
+         * @param {Number} time The calendar time to be shown
+         * @param {Number} courseid The id of the course whose events are shown
+         */
+        var changeMonth = function(url, time, courseid) {
+            CalendarRepository.getCalendarMonthData(time, courseid)
+            .then(function(context) {
+                window.history.pushState({}, '', url);
+                return Templates.render('core_calendar/month_detailed', context);
+            })
+            .then(function(html, js) {
+                return Templates.replaceNodeContents(SELECTORS.CALENDAR_MONTH_WRAPPER, html, js);
+            })
+            .done(function() {
+                $('body').trigger(CalendarEvents.monthChanged, [time, courseid]);
+            })
+            .fail(Notification.exception);
+        };
+
+        return {
+            init: function() {
+                registerEventListeners(SELECTORS.ROOT);
+            }
+        };
+    });
diff --git a/calendar/classes/external/calendar_event_exporter.php b/calendar/classes/external/calendar_event_exporter.php
new file mode 100644 (file)
index 0000000..3186390
--- /dev/null
@@ -0,0 +1,87 @@
+<?php
+// 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/>.
+
+/**
+ * Contains event class for displaying a calendar event.
+ *
+ * @package   core_calendar
+ * @copyright 2017 Ryan Wyllie <ryan@moodle.com>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace core_calendar\external;
+
+defined('MOODLE_INTERNAL') || die();
+
+use \core_course\external\course_summary_exporter;
+use \renderer_base;
+
+/**
+ * Class for displaying a calendar event.
+ *
+ * @package   core_calendar
+ * @copyright 2017 Ryan Wyllie <ryan@moodle.com>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class calendar_event_exporter extends event_exporter_base {
+
+    /**
+     * Return the list of additional properties.
+     *
+     * @return array
+     */
+    protected static function define_other_properties() {
+        return [
+            'url' => ['type' => PARAM_URL],
+            'icon' => [
+                'type' => event_icon_exporter::read_properties_definition(),
+            ],
+            'course' => [
+                'type' => course_summary_exporter::read_properties_definition(),
+                'optional' => true,
+            ]
+        ];
+    }
+
+    /**
+     * Get the additional values to inject while exporting.
+     *
+     * @param renderer_base $output The renderer.
+     * @return array Keys are the property names, values are their values.
+     */
+    protected function get_other_values(renderer_base $output) {
+        $values = parent::get_other_values($output);
+
+        $eventid = $this->event->get_id();
+
+        $url = new \moodle_url($this->related['daylink'], [], "event_{$eventid}");
+        $values['url'] = $url->out(false);
+
+        return $values;
+    }
+
+    /**
+     * Returns a list of objects that are related.
+     *
+     * @return array
+     */
+    protected static function define_related() {
+        $related = parent::define_related();
+        $related['daylink'] = \moodle_url::class;
+
+        return $related;
+    }
+}
diff --git a/calendar/classes/external/day_exporter.php b/calendar/classes/external/day_exporter.php
new file mode 100644 (file)
index 0000000..5cac152
--- /dev/null
@@ -0,0 +1,149 @@
+<?php
+// 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/>.
+
+/**
+ * Contains event class for displaying the day view.
+ *
+ * @package   core_calendar
+ * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace core_calendar\external;
+
+defined('MOODLE_INTERNAL') || die();
+
+use core\external\exporter;
+use renderer_base;
+use moodle_url;
+
+/**
+ * Class for displaying the day view.
+ *
+ * @package   core_calendar
+ * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class day_exporter extends exporter {
+
+    /**
+     * Return the list of properties.
+     *
+     * @return array
+     */
+    protected static function define_properties() {
+        // These are the default properties as returned by getuserdate()
+        // but without the formatted month and week names.
+        return [
+            'seconds' => [
+                'type' => PARAM_INT,
+            ],
+            'minutes' => [
+                'type' => PARAM_INT,
+            ],
+            'hours' => [
+                'type' => PARAM_INT,
+            ],
+            'mday' => [
+                'type' => PARAM_INT,
+            ],
+            'wday' => [
+                'type' => PARAM_INT,
+            ],
+            'year' => [
+                'type' => PARAM_INT,
+            ],
+            'yday' => [
+                'type' => PARAM_INT,
+            ],
+        ];
+    }
+
+    /**
+     * Return the list of additional properties.
+     *
+     * @return array
+     */
+    protected static function define_other_properties() {
+        return [
+            'timestamp' => [
+                'type' => PARAM_INT,
+            ],
+            'istoday' => [
+                'type' => PARAM_BOOL,
+                'default' => false,
+            ],
+            'isweekend' => [
+                'type' => PARAM_BOOL,
+                'default' => false,
+            ],
+            'viewdaylink' => [
+                'type' => PARAM_URL,
+                'optional' => true,
+            ],
+            'events' => [
+                'type' => calendar_event_exporter::read_properties_definition(),
+                'multiple' => true,
+            ]
+        ];
+    }
+
+    /**
+     * Get the additional values to inject while exporting.
+     *
+     * @param renderer_base $output The renderer.
+     * @return array Keys are the property names, values are their values.
+     */
+    protected function get_other_values(renderer_base $output) {
+        $return = [
+            'timestamp' => $this->data[0],
+        ];
+
+        $url = new moodle_url('/calendar/view.php', [
+                'view' => 'day',
+                'time' => $this->data[0],
+            ]);
+        $return['viewdaylink'] = $url->out(false);
+
+        $cache = $this->related['cache'];
+        $return['events'] = array_map(function($event) use ($cache, $output, $url) {
+            $context = $cache->get_context($event);
+            $course = $cache->get_course($event);
+            $exporter = new calendar_event_exporter($event, [
+                'context' => $context,
+                'course' => $course,
+                'daylink' => $url,
+            ]);
+
+            return $exporter->export($output);
+        }, $this->related['events']);
+
+        return $return;
+    }
+
+    /**
+     * Returns a list of objects that are related.
+     *
+     * @return array
+     */
+    protected static function define_related() {
+        return [
+            'events' => '\core_calendar\local\event\entities\event_interface[]',
+            'cache' => '\core_calendar\external\events_related_objects_cache',
+            'type' => '\core_calendar\type_base',
+        ];
+    }
+}
diff --git a/calendar/classes/external/day_name_exporter.php b/calendar/classes/external/day_name_exporter.php
new file mode 100644 (file)
index 0000000..41c657f
--- /dev/null
@@ -0,0 +1,87 @@
+<?php
+// 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/>.
+
+/**
+ * Contains event class for displaying the day name.
+ *
+ * @package   core_calendar
+ * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace core_calendar\external;
+
+defined('MOODLE_INTERNAL') || die();
+
+use core\external\exporter;
+
+/**
+ * Class for displaying the day view.
+ *
+ * @package   core_calendar
+ * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class day_name_exporter extends exporter {
+
+    /**
+     * @var int $dayno The day number.
+     */
+    protected $dayno;
+
+    /**
+     * @var string $shortname The formatted short name of the day.
+     */
+    protected $shortname;
+
+    /**
+     * @var string $fullname The formatted full name of the day.
+     */
+    protected $fullname;
+
+    /**
+     * Constructor.
+     *
+     * @param int $dayno The day number.
+     * @param array $names The list of names.
+     */
+    public function __construct($dayno, $names) {
+        $data = $names + ['dayno' => $dayno];
+
+        parent::__construct($data, []);
+    }
+
+    /**
+     * Return the list of properties.
+     *
+     * @return array
+     */
+    protected static function define_properties() {
+        return [
+            'dayno' => [
+                'type' => PARAM_INT,
+            ],
+            'shortname' => [
+                // Note: The calendar type class has already formatted the names.
+                'type' => PARAM_RAW,
+            ],
+            'fullname' => [
+                // Note: The calendar type class has already formatted the names.
+                'type' => PARAM_RAW,
+            ],
+        ];
+    }
+}
index ce78114..7e4bb7c 100644 (file)
@@ -28,8 +28,6 @@ defined('MOODLE_INTERNAL') || die();
 
 require_once($CFG->dirroot . "/calendar/lib.php");
 
-use \core\external\exporter;
-use \core_calendar\local\event\entities\event_interface;
 use \core_calendar\local\event\entities\action_event_interface;
 use \core_calendar\local\event\container;
 use \core_course\external\course_summary_exporter;
@@ -42,112 +40,7 @@ use \renderer_base;
  * @copyright 2017 Ryan Wyllie <ryan@moodle.com>
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class event_exporter extends exporter {
-
-    /**
-     * @var event_interface $event
-     */
-    protected $event;
-
-    /**
-     * Constructor.
-     *
-     * @param event_interface $event
-     * @param array $related The related data.
-     */
-    public function __construct(event_interface $event, $related = []) {
-        $this->event = $event;
-
-        $starttimestamp = $event->get_times()->get_start_time()->getTimestamp();
-        $endtimestamp = $event->get_times()->get_end_time()->getTimestamp();
-        $groupid = $event->get_group() ? $event->get_group()->get('id') : null;
-        $userid = $event->get_user() ? $event->get_user()->get('id') : null;
-
-        $data = new \stdClass();
-        $data->id = $event->get_id();
-        $data->name = $event->get_name();
-        $data->description = $event->get_description()->get_value();
-        $data->descriptionformat = $event->get_description()->get_format();
-        $data->groupid = $groupid;
-        $data->userid = $userid;
-        $data->eventtype = $event->get_type();
-        $data->timestart = $starttimestamp;
-        $data->timeduration = $endtimestamp - $starttimestamp;
-        $data->timesort = $event->get_times()->get_sort_time()->getTimestamp();
-        $data->visible = $event->is_visible() ? 1 : 0;
-        $data->timemodified = $event->get_times()->get_modified_time()->getTimestamp();
-
-        if ($repeats = $event->get_repeats()) {
-            $data->repeatid = $repeats->get_id();
-        }
-
-        if ($cm = $event->get_course_module()) {
-            $data->modulename = $cm->get('modname');
-            $data->instance = $cm->get('id');
-        }
-
-        parent::__construct($data, $related);
-    }
-
-    /**
-     * Return the list of properties.
-     *
-     * @return array
-     */
-    protected static function define_properties() {
-        return [
-            'id' => ['type' => PARAM_INT],
-            'name' => ['type' => PARAM_TEXT],
-            'description' => [
-                'type' => PARAM_RAW,
-                'optional' => true,
-                'default' => null,
-                'null' => NULL_ALLOWED
-            ],
-            'descriptionformat' => [
-                'type' => PARAM_INT,
-                'optional' => true,
-                'default' => null,
-                'null' => NULL_ALLOWED
-            ],
-            'groupid' => [
-                'type' => PARAM_INT,
-                'optional' => true,
-                'default' => null,
-                'null' => NULL_ALLOWED
-            ],
-            'userid' => [
-                'type' => PARAM_INT,
-                'optional' => true,
-                'default' => null,
-                'null' => NULL_ALLOWED
-            ],
-            'repeatid' => [
-                'type' => PARAM_INT,
-                'optional' => true,
-                'default' => null,
-                'null' => NULL_ALLOWED
-            ],
-            'modulename' => [
-                'type' => PARAM_TEXT,
-                'optional' => true,
-                'default' => null,
-                'null' => NULL_ALLOWED
-            ],
-            'instance' => [
-                'type' => PARAM_INT,
-                'optional' => true,
-                'default' => null,
-                'null' => NULL_ALLOWED
-            ],
-            'eventtype' => ['type' => PARAM_TEXT],
-            'timestart' => ['type' => PARAM_INT],
-            'timeduration' => ['type' => PARAM_INT],
-            'timesort' => ['type' => PARAM_INT],
-            'visible' => ['type' => PARAM_INT],
-            'timemodified' => ['type' => PARAM_INT],
-        ];
-    }
+class event_exporter extends event_exporter_base {
 
     /**
      * Return the list of additional properties.
@@ -155,34 +48,26 @@ class event_exporter extends exporter {
      * @return array
      */
     protected static function define_other_properties() {
-        return [
-            'url' => ['type' => PARAM_URL],
-            'editurl' => [
-                'type' => PARAM_URL,
-                'optional' => true
-            ],
-            'icon' => [
-                'type' => event_icon_exporter::read_properties_definition(),
-            ],
-            'action' => [
-                'type' => event_action_exporter::read_properties_definition(),
-                'optional' => true,
-            ],
-            'course' => [
-                'type' => course_summary_exporter::read_properties_definition(),
-                'optional' => true,
-            ],
-            'canedit' => ['type' => PARAM_BOOL],
-            'displayeventsource' => ['type' => PARAM_BOOL],
-            'subscription' => [
-                'type' => PARAM_RAW,
-                'optional' => true,
-                'default' => null,
-                'null' => NULL_ALLOWED
-            ],
-            'isactionevent' => ['type' => PARAM_BOOL],
-            'candelete' => ['type' => PARAM_BOOL]
+
+        $values = parent::define_other_properties();
+
+        $values['canedit'] = ['type' => PARAM_BOOL];
+        $values['displayeventsource'] = ['type' => PARAM_BOOL];
+        $values['subscription'] = [
+            'type' => PARAM_RAW,
+            'optional' => true,
+            'default' => null,
+            'null' => NULL_ALLOWED
         ];
+        $values['isactionevent'] = ['type' => PARAM_BOOL];
+        $values['candelete'] = ['type' => PARAM_BOOL];
+        $values['url'] = ['type' => PARAM_URL];
+        $values['action'] = [
+            'type' => event_action_exporter::read_properties_definition(),
+            'optional' => true,
+        ];
+
+        return $values;
     }
 
     /**
@@ -192,12 +77,14 @@ class event_exporter extends exporter {
      * @return array Keys are the property names, values are their values.
      */
     protected function get_other_values(renderer_base $output) {
-        $values = [];
+        $values = parent::get_other_values($output);
+
         $event = $this->event;
         $legacyevent = container::get_event_mapper()->from_event_to_legacy_event($event);
 
         $context = $this->related['context'];
         $values['isactionevent'] = false;
+
         if ($moduleproxy = $event->get_course_module()) {
             $modulename = $moduleproxy->get('modname');
             $moduleid = $moduleproxy->get('id');
@@ -215,11 +102,8 @@ class event_exporter extends exporter {
             require_once($CFG->dirroot.'/course/lib.php');
             $url = \course_get_url($this->related['course'] ?: SITEID);
         }
-        $timesort = $event->get_times()->get_sort_time()->getTimestamp();
-        $iconexporter = new event_icon_exporter($event, ['context' => $context]);
 
         $values['url'] = $url->out(false);
-        $values['icon'] = $iconexporter->export($output);
 
         if ($event instanceof action_event_interface) {
             $actionrelated = [
@@ -253,18 +137,7 @@ class event_exporter extends exporter {
                 $values['subscription'] = json_encode($subscriptiondata);
             }
         }
-        return $values;
-    }
 
-    /**
-     * Returns a list of objects that are related.
-     *
-     * @return array
-     */
-    protected static function define_related() {
-        return [
-            'context' => 'context',
-            'course' => 'stdClass?',
-        ];
+        return $values;
     }
 }
diff --git a/calendar/classes/external/event_exporter_base.php b/calendar/classes/external/event_exporter_base.php
new file mode 100644 (file)
index 0000000..bc176d3
--- /dev/null
@@ -0,0 +1,225 @@
+<?php
+// 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/>.
+
+/**
+ * Contains event class for displaying a calendar event.
+ *
+ * @package   core_calendar
+ * @copyright 2017 Ryan Wyllie <ryan@moodle.com>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace core_calendar\external;
+
+defined('MOODLE_INTERNAL') || die();
+
+use \core\external\exporter;
+use \core_calendar\local\event\entities\event_interface;
+use \core_calendar\local\event\entities\action_event_interface;
+use \core_course\external\course_summary_exporter;
+use \renderer_base;
+
+/**
+ * Class for displaying a calendar event.
+ *
+ * @package   core_calendar
+ * @copyright 2017 Ryan Wyllie <ryan@moodle.com>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class event_exporter_base extends exporter {
+
+    /**
+     * @var event_interface $event
+     */
+    protected $event;
+
+    /**
+     * Constructor.
+     *
+     * @param event_interface $event
+     * @param array $related The related data.
+     */
+    public function __construct(event_interface $event, $related = []) {
+        $this->event = $event;
+
+        $starttimestamp = $event->get_times()->get_start_time()->getTimestamp();
+        $endtimestamp = $event->get_times()->get_end_time()->getTimestamp();
+        $groupid = $event->get_group() ? $event->get_group()->get('id') : null;
+        $userid = $event->get_user() ? $event->get_user()->get('id') : null;
+
+        $data = new \stdClass();
+        $data->id = $event->get_id();
+        $data->name = $event->get_name();
+        $data->description = $event->get_description()->get_value();
+        $data->descriptionformat = $event->get_description()->get_format();
+        $data->groupid = $groupid;
+        $data->userid = $userid;
+        $data->eventtype = $event->get_type();
+        $data->timestart = $starttimestamp;
+        $data->timeduration = $endtimestamp - $starttimestamp;
+        $data->timesort = $event->get_times()->get_sort_time()->getTimestamp();
+        $data->visible = $event->is_visible() ? 1 : 0;
+        $data->timemodified = $event->get_times()->get_modified_time()->getTimestamp();
+
+        if ($repeats = $event->get_repeats()) {
+            $data->repeatid = $repeats->get_id();
+        }
+
+        if ($cm = $event->get_course_module()) {
+            $data->modulename = $cm->get('modname');
+            $data->instance = $cm->get('id');
+        }
+
+        parent::__construct($data, $related);
+    }
+
+    /**
+     * Return the list of properties.
+     *
+     * @return array
+     */
+    protected static function define_properties() {
+        return [
+            'id' => ['type' => PARAM_INT],
+            'name' => ['type' => PARAM_TEXT],
+            'description' => [
+                'type' => PARAM_RAW,
+                'optional' => true,
+                'default' => null,
+                'null' => NULL_ALLOWED
+            ],
+            'descriptionformat' => [
+                'type' => PARAM_INT,
+                'optional' => true,
+                'default' => null,
+                'null' => NULL_ALLOWED
+            ],
+            'groupid' => [
+                'type' => PARAM_INT,
+                'optional' => true,
+                'default' => null,
+                'null' => NULL_ALLOWED
+            ],
+            'userid' => [
+                'type' => PARAM_INT,
+                'optional' => true,
+                'default' => null,
+                'null' => NULL_ALLOWED
+            ],
+            'repeatid' => [
+                'type' => PARAM_INT,
+                'optional' => true,
+                'default' => null,
+                'null' => NULL_ALLOWED
+            ],
+            'modulename' => [
+                'type' => PARAM_TEXT,
+                'optional' => true,
+                'default' => null,
+                'null' => NULL_ALLOWED
+            ],
+            'instance' => [
+                'type' => PARAM_INT,
+                'optional' => true,
+                'default' => null,
+                'null' => NULL_ALLOWED
+            ],
+            'eventtype' => ['type' => PARAM_TEXT],
+            'timestart' => ['type' => PARAM_INT],
+            'timeduration' => ['type' => PARAM_INT],
+            'timesort' => ['type' => PARAM_INT],
+            'visible' => ['type' => PARAM_INT],
+            'timemodified' => ['type' => PARAM_INT],
+        ];
+    }
+
+    /**
+     * Return the list of additional properties.
+     *
+     * @return array
+     */
+    protected static function define_other_properties() {
+        return [
+            'url' => ['type' => PARAM_URL],
+            'icon' => [
+                'type' => event_icon_exporter::read_properties_definition(),
+            ],
+            'action' => [
+                'type' => event_action_exporter::read_properties_definition(),
+                'optional' => true,
+            ],
+            'course' => [
+                'type' => course_summary_exporter::read_properties_definition(),
+                'optional' => true,
+            ]
+        ];
+    }
+
+    /**
+     * Get the additional values to inject while exporting.
+     *
+     * @param renderer_base $output The renderer.
+     * @return array Keys are the property names, values are their values.
+     */
+    protected function get_other_values(renderer_base $output) {
+        $values = [];
+        $event = $this->event;
+        $context = $this->related['context'];
+        if ($moduleproxy = $event->get_course_module()) {
+            $modulename = $moduleproxy->get('modname');
+            $moduleid = $moduleproxy->get('id');
+            $url = new \moodle_url(sprintf('/mod/%s/view.php', $modulename), ['id' => $moduleid]);
+        } else {
+            // TODO MDL-58866 We do not have any way to find urls for events outside of course modules.
+            global $CFG;
+            require_once($CFG->dirroot.'/course/lib.php');
+            $url = \course_get_url($this->related['course'] ?: SITEID);
+        }
+        $timesort = $event->get_times()->get_sort_time()->getTimestamp();
+        $iconexporter = new event_icon_exporter($event, ['context' => $context]);
+
+        $values['url'] = $url->out(false);
+        $values['icon'] = $iconexporter->export($output);
+
+        if ($event instanceof action_event_interface) {
+            $actionrelated = [
+                'context' => $context,
+                'event' => $event
+            ];
+            $actionexporter = new event_action_exporter($event->get_action(), $actionrelated);
+            $values['action'] = $actionexporter->export($output);
+        }
+
+        if ($course = $this->related['course']) {
+            $coursesummaryexporter = new course_summary_exporter($course, ['context' => $context]);
+            $values['course'] = $coursesummaryexporter->export($output);
+        }
+
+        return $values;
+    }
+
+    /**
+     * Returns a list of objects that are related.
+     *
+     * @return array
+     */
+    protected static function define_related() {
+        return [
+            'context' => 'context',
+            'course' => 'stdClass?',
+        ];
+    }
+}
diff --git a/calendar/classes/external/footer_options_exporter.php b/calendar/classes/external/footer_options_exporter.php
new file mode 100644 (file)
index 0000000..23bb42f
--- /dev/null
@@ -0,0 +1,144 @@
+<?php
+// 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/>.
+
+/**
+ * Class for exporting calendar footer view options data.
+ *
+ * @package    core_calendar
+ * @copyright  2017 Simey Lameze <simey@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+namespace core_calendar\external;
+
+defined('MOODLE_INTERNAL') || die();
+
+use core\external\exporter;
+use renderer_base;
+use stdClass;
+use moodle_url;
+
+/**
+ * Class for exporting calendar footer view options data.
+ *
+ * @copyright  2017 Simey Lameze
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class footer_options_exporter extends exporter {
+
+    /**
+     * @var \calendar_information $calendar The calendar to be rendered.
+     */
+    protected $calendar;
+
+    /**
+     * @var int $userid The user id.
+     */
+    protected $userid;
+
+    /**
+     * @var string $token The user sha1 token.
+     */
+    protected $token;
+
+    /**
+     * Constructor for month_exporter.
+     *
+     * @param \calendar_information $calendar The calendar being represented
+     * @param int $userid The user id
+     * @param string $token The user sha1 token.
+     */
+    public function __construct(\calendar_information $calendar, $userid, $token) {
+        $this->calendar = $calendar;
+        $this->userid = $userid;
+        $this->token = $token;
+    }
+
+    /**
+     * Get the export calendar button.
+     *
+     * @return \single_button The export calendar button html.
+     */
+    protected function get_export_calendar_button() {
+        $exportcalendarurl = new moodle_url('/calendar/export.php', ['course' => $this->calendar->course->id]);
+        return new \single_button($exportcalendarurl, get_string('exportcalendar', 'calendar'));
+    }
+
+    /**
+     * Get the iCal url.
+     *
+     * @return string The iCal url.
+     */
+    protected function get_ical_url() {
+        return new moodle_url('/calendar/export_execute.php', ['preset_what' => 'all',
+                'preset_time' => 'recentupcoming', 'userid' => $this->userid, 'authtoken' => $this->token]);
+
+    }
+
+    /**
+     * Get manage subscription button.
+     *
+     * @return string The manage subscription button html.
+     */
+    protected function get_manage_subscriptions_button() {
+        if (calendar_user_can_add_event($this->calendar->course)) {
+            $managesubscriptionurl = new moodle_url('/calendar/managesubscriptions.php',
+                    ['course' => $this->calendar->course->id]);
+            return new \single_button($managesubscriptionurl,
+                    get_string('managesubscriptions', 'calendar'));
+        }
+    }
+
+    /**
+     * Get the additional values to inject while exporting.
+     *
+     * @param renderer_base $output The renderer.
+     * @return array Keys are the property names, values are their values.
+     */
+    protected function get_other_values(renderer_base $output) {
+        global $CFG;
+
+        $values = new stdClass();
+
+        if (!empty($CFG->enablecalendarexport)) {
+            $exportbutton = $this->get_export_calendar_button();
+            $managesubscriptionbutton = $this->get_manage_subscriptions_button();
+            $values->exportcalendarbutton = $exportbutton->export_for_template($output);
+            $values->managesubscriptionbutton = $managesubscriptionbutton->export_for_template($output);
+            $values->icalurl = $this->get_ical_url()->out(false);
+        }
+
+        return (array) $values;
+    }
+
+    /**
+     * Return the list of additional properties.
+     *
+     * @return array
+     */
+    public static function define_other_properties() {
+        return array(
+            'exportcalendarbutton' => [
+                'type' => PARAM_RAW,
+            ],
+            'managesubscriptionbutton' => [
+                'type' => PARAM_RAW,
+            ],
+            'icalurl' => [
+                'type' => PARAM_URL,
+            ],
+        );
+    }
+}
diff --git a/calendar/classes/external/month_exporter.php b/calendar/classes/external/month_exporter.php
new file mode 100644 (file)
index 0000000..cf1d1bd
--- /dev/null
@@ -0,0 +1,283 @@
+<?php
+// 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/>.
+
+/**
+ * Contains event class for displaying the month view.
+ *
+ * @package   core_calendar
+ * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace core_calendar\external;
+
+defined('MOODLE_INTERNAL') || die();
+
+use core\external\exporter;
+use renderer_base;
+use moodle_url;
+
+/**
+ * Class for displaying the month view.
+ *
+ * @package   core_calendar
+ * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class month_exporter extends exporter {
+
+    /**
+     * @var \calendar_information $calendar The calendar to be rendered.
+     */
+    protected $calendar;
+
+    /**
+     * @var int $firstdayofweek The first day of the week.
+     */
+    protected $firstdayofweek;
+
+    /**
+     * @var moodle_url $url The URL for the events page.
+     */
+    protected $url;
+
+    /**
+     * Constructor for month_exporter.
+     *
+     * @param \calendar_information $calendar The calendar being represented
+     * @param \core_calendar\type_base $type The calendar type (e.g. Gregorian)
+     * @param array $related The related information
+     */
+    public function __construct(\calendar_information $calendar, \core_calendar\type_base $type, $related) {
+        $this->calendar = $calendar;
+        $this->firstdayofweek = $type->get_starting_weekday();
+
+        $this->url = new moodle_url('/calendar/view.php', [
+                'view' => 'month',
+                'time' => $calendar->time,
+            ]);
+
+        if ($this->calendar->courseid) {
+            $this->url->param('course', $this->calendar->courseid);
+        }
+
+        $related['type'] = $type;
+
+        parent::__construct([], $related);
+    }
+
+    /**
+     * Return the list of additional properties.
+     *
+     * @return array
+     */
+    protected static function define_other_properties() {
+        return [
+            'courseid' => [
+                'type' => PARAM_INT,
+            ],
+            'filter_selector' => [
+                'type' => PARAM_RAW,
+            ],
+            'navigation' => [
+                'type' => PARAM_RAW,
+            ],
+            'weeks' => [
+                'type' => week_exporter::read_properties_definition(),
+                'multiple' => true,
+            ],
+            'daynames' => [
+                'type' => day_name_exporter::read_properties_definition(),
+                'multiple' => true,
+            ],
+            'view' => [
+                'type' => PARAM_ALPHA,
+            ],
+            'previousperiod' => [
+                'type' => PARAM_INT,
+            ],
+            'nextperiod' => [
+                'type' => PARAM_INT,
+            ],
+        ];
+    }
+
+    /**
+     * Get the additional values to inject while exporting.
+     *
+     * @param renderer_base $output The renderer.
+     * @return array Keys are the property names, values are their values.
+     */
+    protected function get_other_values(renderer_base $output) {
+        return [
+            'courseid' => $this->calendar->courseid,
+            'view' => 'month',
+            'previousperiod' => $this->get_previous_month_timestamp(),
+            'nextperiod' => $this->get_next_month_timestamp(),
+            'filter_selector' => $this->get_course_filter_selector($output),
+            'navigation' => $this->get_navigation($output),
+            'weeks' => $this->get_weeks($output),
+            'daynames' => $this->get_day_names($output),
+        ];
+    }
+
+    /**
+     * Get the course filter selector.
+     *
+     * @param renderer_base $output
+     * @return string The html code for the course filter selector.
+     */
+    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;
+    }
+
+    /**
+     * Get the calendar navigation controls.
+     *
+     * @param renderer_base $output
+     * @return string The html code to the calendar top navigation.
+     */
+    protected function get_navigation(renderer_base $output) {
+        return calendar_top_controls('month', [
+            'id' => $this->calendar->courseid,
+            'time' => $this->calendar->time,
+        ]);
+    }
+
+    /**
+     * Get the list of day names for display, re-ordered from the first day
+     * of the week.
+     *
+     * @param   renderer_base $output
+     * @return  day_name_exporter[]
+     */
+    protected function get_day_names(renderer_base $output) {
+        $weekdays = $this->related['type']->get_weekdays();
+        $daysinweek = count($weekdays);
+
+        $daynames = [];
+        for ($i = 0; $i < $daysinweek; $i++) {
+            // Bump the currentdayno and ensure it loops.
+            $dayno = ($i + $this->firstdayofweek + $daysinweek) % $daysinweek;
+            $dayname = new day_name_exporter($dayno, $weekdays[$dayno]);
+            $daynames[] = $dayname->export($output);
+        }
+
+        return $daynames;
+    }
+
+    /**
+     * Get the list of week days, ordered into weeks and padded according
+     * to the value of the first day of the week.
+     *
+     * @param renderer_base $output
+     * @return array The list of weeks.
+     */
+    protected function get_weeks(renderer_base $output) {
+        $weeks = [];
+        $alldays = $this->get_days();
+
+        $daysinweek = count($this->related['type']->get_weekdays());
+
+        // Calculate which day number is the first, and last day of the week.
+        $firstdayofweek = $this->firstdayofweek;
+        $lastdayofweek = ($firstdayofweek + $daysinweek - 1) % $daysinweek;
+
+        // The first week is special as it may have padding at the beginning.
+        $day = reset($alldays);
+        $firstdayno = $day['wday'];
+
+        $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);
+        $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);
+            $weeks[] = $week->export($output);
+        }
+
+        return $weeks;
+    }
+
+    /**
+     * Get the list of days with the matching date array.
+     *
+     * @return array
+     */
+    protected function get_days() {
+        $date = $this->related['type']->timestamp_to_date_array($this->calendar->time);
+        $monthdays = $this->related['type']->get_num_days_in_month($date['year'], $date['mon']);
+
+        $days = [];
+        for ($dayno = 1; $dayno <= $monthdays; $dayno++) {
+            // Get the gregorian representation of the day.
+            $timestamp = $this->related['type']->convert_to_timestamp($date['year'], $date['mon'], $dayno);
+
+            $days[] = $this->related['type']->timestamp_to_date_array($timestamp);
+        }
+
+        return $days;
+    }
+
+    /**
+     * Returns a list of objects that are related.
+     *
+     * @return array
+     */
+    protected static function define_related() {
+        return [
+            'events' => '\core_calendar\local\event\entities\event_interface[]',
+            'cache' => '\core_calendar\external\events_related_objects_cache',
+            'type' => '\core_calendar\type_base',
+        ];
+    }
+
+    /**
+     * Get the previous month timestamp.
+     *
+     * @return int The previous month timestamp.
+     */
+    protected function get_previous_month_timestamp() {
+        $date = $this->related['type']->timestamp_to_date_array($this->calendar->time);
+        $month = calendar_sub_month($date['mon'], $date['year']);
+        $monthtime = $this->related['type']->convert_to_gregorian($month[1], $month[0], 1);
+
+        return make_timestamp($monthtime['year'], $monthtime['month'], $monthtime['day'], $monthtime['hour'], $monthtime['minute']);
+    }
+
+    /**
+     * Get the next month timestamp.
+     *
+     * @return int The next month timestamp.
+     */
+    protected function get_next_month_timestamp() {
+        $date = $this->related['type']->timestamp_to_date_array($this->calendar->time);
+        $month = calendar_sub_month($date['mon'], $date['year']);
+        $monthtime = $this->related['type']->convert_to_gregorian($month[1], $month[0], 1);
+
+        return make_timestamp($monthtime['year'], $monthtime['month'], $monthtime['day'], $monthtime['hour'], $monthtime['minute']);
+    }
+}
diff --git a/calendar/classes/external/week_exporter.php b/calendar/classes/external/week_exporter.php
new file mode 100644 (file)
index 0000000..afc92b2
--- /dev/null
@@ -0,0 +1,159 @@
+<?php
+// 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/>.
+
+/**
+ * Contains event class for displaying the week view.
+ *
+ * @package   core_calendar
+ * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace core_calendar\external;
+
+defined('MOODLE_INTERNAL') || die();
+
+use core\external\exporter;
+use renderer_base;
+
+/**
+ * Class for displaying the week view.
+ *
+ * @package   core_calendar
+ * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class week_exporter extends exporter {
+
+    /**
+     * @var array $days An array of day_exporter objects.
+     */
+    protected $days = [];
+
+    /**
+     * @var int $prepadding The number of pre-padding days at the start of the week.
+     */
+    protected $prepadding = 0;
+
+    /**
+     * @var int $postpadding The number of post-padding days at the start of the week.
+     */
+    protected $postpadding = 0;
+
+    /**
+     * Constructor.
+     *
+     * @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) {
+        $this->days = $days;
+        $this->prepadding = $prepadding;
+        $this->postpadding = $postpadding;
+
+        parent::__construct([], $related);
+    }
+
+    /**
+     * Return the list of additional properties.
+     *
+     * @return array
+     */
+    protected static function define_other_properties() {
+        return [
+            'prepadding' => [
+                'type' => PARAM_INT,
+                'multiple' => true,
+            ],
+            'postpadding' => [
+                'type' => PARAM_INT,
+                'multiple' => true,
+            ],
+            'days' => [
+                'type' => day_exporter::read_properties_definition(),
+                'multiple' => true,
+            ],
+        ];
+    }
+
+    /**
+     * Get the additional values to inject while exporting.
+     *
+     * @param renderer_base $output The renderer.
+     * @return array Keys are the property names, values are their values.
+     */
+    protected function get_other_values(renderer_base $output) {
+        $return = [
+            'prepadding' => [],
+            'postpadding' => [],
+            'days' => [],
+        ];
+
+        for ($i = 0; $i < $this->prepadding; $i++) {
+            $return['prepadding'][] = $i;
+        }
+        for ($i = 0; $i < $this->postpadding; $i++) {
+            $return['postpadding'][] = $i;
+        }
+
+        $return['days'] = [];
+        foreach ($this->days as $daydata) {
+            $events = [];
+            foreach ($this->related['events'] as $event) {
+                $times = $event->get_times();
+                $starttime = $times->get_start_time()->getTimestamp();
+                $startdate = $this->related['type']->timestamp_to_date_array($starttime);
+                $endtime = $times->get_end_time()->getTimestamp();
+                $enddate = $this->related['type']->timestamp_to_date_array($endtime);
+
+                if ((($startdate['year'] * 366) + $startdate['yday']) > ($daydata['year'] * 366) + $daydata['yday']) {
+                    // Starts after today.
+                    continue;
+                }
+                if ((($enddate['year'] * 366) + $enddate['yday']) < ($daydata['year'] * 366) + $daydata['yday']) {
+                    // Ends before today.
+                    continue;
+                }
+                $events[] = $event;
+            }
+
+            $day = new day_exporter($daydata, [
+                'events' => $events,
+                'cache' => $this->related['cache'],
+                'type' => $this->related['type'],
+            ]);
+
+            $return['days'][] = $day->export($output);
+        }
+
+        return $return;
+    }
+
+    /**
+     * Returns a list of objects that are related.
+     *
+     * @return array
+     */
+    protected static function define_related() {
+        return [
+            'events' => '\core_calendar\local\event\entities\event_interface[]',
+            'cache' => '\core_calendar\external\events_related_objects_cache',
+            'type' => '\core_calendar\type_base',
+        ];
+    }
+}
index 4eb25fd..e7bddfd 100644 (file)
@@ -70,7 +70,8 @@ class api {
         array $groupsfilter = null,
         array $coursesfilter = null,
         $withduration = true,
-        $ignorehidden = true
+        $ignorehidden = true,
+        callable $filter = null
     ) {
         global $USER;
 
@@ -100,7 +101,8 @@ class api {
             $groupsfilter,
             $coursesfilter,
             $withduration,
-            $ignorehidden
+            $ignorehidden,
+            $filter
         );
     }
 
index a7d52fe..a211be1 100644 (file)
@@ -217,4 +217,26 @@ abstract class type_base {
      * @return string locale
      */
     public abstract function locale_win_charset();
+
+    /**
+     * Provided with a day, month, year, hour and minute in the specific
+     * calendar type convert it into the equivalent Unix Time Stamp.
+     *
+     * @param int $year
+     * @param int $month
+     * @param int $day
+     * @param int $hour
+     * @param int $minute
+     * @return int timestamp
+     */
+    public function convert_to_timestamp($year, $month, $day, $hour = 0, $minute = 0) {
+        $gregorianinfo = $this->convert_to_gregorian($year, $month, $day, $hour, $minute);
+        return make_timestamp(
+            $gregorianinfo['year'],
+            $gregorianinfo['month'],
+            $gregorianinfo['day'],
+            $gregorianinfo['hour'],
+            $gregorianinfo['minute'],
+            0);
+    }
 }
index 2356f9e..b8ba417 100644 (file)
@@ -705,6 +705,7 @@ class core_calendar_external extends external_api {
             )
         );
     }
+
     /**
      * Get calendar event by id.
      *
@@ -745,7 +746,7 @@ class core_calendar_external extends external_api {
      *
      * @return external_description
      */
-    public static function  get_calendar_event_by_id_returns() {
+    public static function get_calendar_event_by_id_returns() {
         $eventstructure = event_exporter::get_read_structure();
 
         return new external_single_structure(array(
@@ -844,4 +845,65 @@ class core_calendar_external extends external_api {
             )
         );
     }
+
+    /**
+     * Get data for the monthly calendar view.
+     *
+     * @param   int     $time The time to be shown
+     * @param   int     $courseid The course to be included
+     * @return  array
+     */
+    public static function get_calendar_monthly_view($time, $courseid) {
+        global $CFG, $DB, $USER, $PAGE;
+        require_once($CFG->dirroot."/calendar/lib.php");
+
+        // Parameter validation.
+        $params = self::validate_parameters(self::get_calendar_monthly_view_parameters(), [
+            'time' => $time,
+            'courseid' => $courseid,
+        ]);
+
+        if ($courseid != SITEID && !empty($courseid)) {
+            // Course ID must be valid and existing.
+            $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
+            $courses = [$course->id => $course];
+        } else {
+            $course = get_site();
+            $courses = calendar_get_default_courses();
+        }
+
+        // TODO: Copy what we do in calendar/view.php.
+        $context = \context_user::instance($USER->id);
+        self::validate_context($context);
+
+        $calendar = new calendar_information(0, 0, 0, $time);
+        $calendar->prepare_for_view($course, $courses);
+
+        list($data, $template) = calendar_get_view($calendar, 'month');
+
+        return $data;
+    }
+
+    /**
+     * Returns description of method parameters.
+     *
+     * @return external_function_parameters
+     */
+    public static function get_calendar_monthly_view_parameters() {
+        return new external_function_parameters(
+            [
+                'time' => new external_value(PARAM_INT, 'Time to be viewed', VALUE_REQUIRED, '', NULL_NOT_ALLOWED),
+                'courseid' => new external_value(PARAM_INT, 'Course being viewed', VALUE_DEFAULT, SITEID, NULL_ALLOWED),
+            ]
+        );
+    }
+
+    /**
+     * Returns description of method result value.
+     *
+     * @return external_description
+     */
+    public static function get_calendar_monthly_view_returns() {
+        return \core_calendar\external\month_exporter::get_read_structure();
+    }
 }
index 9b7b76f..bb61015 100644 (file)
@@ -2148,20 +2148,7 @@ function calendar_get_link_href($linkbase, $d, $m, $y, $time = 0) {
         $linkbase = new \moodle_url($linkbase);
     }
 
-    // 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.
-    if (!empty($d) && !empty($m) && !empty($y)) {
-        if (checkdate($m, $d, $y)) {
-            $time = make_timestamp($y, $m, $d);
-        } else {
-            $time = time();
-        }
-    } else if (empty($time)) {
-        $time = time();
-    }
-
-    $linkbase->param('time', $time);
+    $linkbase->param('time', calendar_get_timestamp($d, $m, $y, $time));
 
     return $linkbase;
 }
@@ -2186,7 +2173,11 @@ function calendar_get_link_previous($text, $linkbase, $d, $m, $y, $accesshide =
         return $text;
     }
 
-    return link_arrow_left($text, (string)$href, $accesshide, 'previous');
+    $attrs = [
+        'data-time' => calendar_get_timestamp($d, $m, $y, $time),
+    ];
+
+    return link_arrow_left($text, $href->out(false), $accesshide, 'previous', $attrs);
 }
 
 /**
@@ -2209,7 +2200,11 @@ function calendar_get_link_next($text, $linkbase, $d, $m, $y, $accesshide = fals
         return $text;
     }
 
-    return link_arrow_right($text, (string)$href, $accesshide, 'next');
+    $attrs = [
+        'data-time' => calendar_get_timestamp($d, $m, $y, $time),
+    ];
+
+    return link_arrow_right($text, $href->out(false), $accesshide, 'next', $attrs);
 }
 
 /**
@@ -3427,6 +3422,98 @@ function calendar_get_legacy_events($tstart, $tend, $users, $groups, $courses, $
     }, []);
 }
 
+
+/**
+ * Get the calendar view output.
+ *
+ * @param   \calendar_information $calendar The calendar being represented
+ * @param   string      $view The type of calendar to have displayed
+ * @return  array[array, string]
+ */
+function calendar_get_view(\calendar_information $calendar, $view) {
+    global $PAGE, $CFG;
+
+    $renderer = $PAGE->get_renderer('core_calendar');
+    $type = \core_calendar\type_factory::get_calendar_instance();
+
+    // Calculate the bounds of the month.
+    $date = $type->timestamp_to_date_array($calendar->time);
+    $tstart = $type->convert_to_timestamp($date['year'], $date['mon'], 1);
+
+    if ($view === 'day') {
+        $tend = $tstart + DAYSECS - 1;
+        $selectortitle = get_string('dayviewfor', 'calendar');
+    } else if ($view === 'upcoming') {
+        if (isset($CFG->calendar_lookahead)) {
+            $defaultlookahead = intval($CFG->calendar_lookahead);
+        } else {
+            $defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD;
+        }
+        $tend = $tstart + get_user_preferences('calendar_lookahead', $defaultlookahead);
+        $selectortitle = get_string('upcomingeventsfor', 'calendar');
+    } else {
+        $monthdays = $type->get_num_days_in_month($date['year'], $date['mon']);
+        $tend = $tstart + ($monthdays * DAYSECS) - 1;
+        $selectortitle = get_string('detailedmonthviewfor', 'calendar');
+    }
+
+    list($userparam, $groupparam, $courseparam) = array_map(function($param) {
+        // If parameter is true, return null.
+        if ($param === true) {
+            return null;
+        }
+
+        // If parameter is false, return an empty array.
+        if ($param === false) {
+            return [];
+        }
+
+        // If the parameter is a scalar value, enclose it in an array.
+        if (!is_array($param)) {
+            return [$param];
+        }
+
+        // No normalisation required.
+        return $param;
+    }, [$calendar->users, $calendar->groups, $calendar->courses]);
+
+    $events = \core_calendar\local\api::get_events(
+        $tstart,
+        $tend,
+        null,
+        null,
+        null,
+        null,
+        40,
+        null,
+        $userparam,
+        $groupparam,
+        $courseparam,
+        true,
+        true,
+        function ($event) {
+            if ($proxy = $event->get_course_module()) {
+                $cminfo = $proxy->get_proxied_instance();
+                return $cminfo->uservisible;
+
+            }
+
+            return true;
+        }
+    );
+
+    $related = [
+        'events' => $events,
+        'cache' => new \core_calendar\external\events_related_objects_cache($events),
+    ];
+
+    $month = new \core_calendar\external\month_exporter($calendar, $type, $related);
+    $data = $month->export($renderer);
+    $template = 'core_calendar/month_detailed';
+
+    return [$data, $template];
+}
+
 /**
  * Request and render event form fragment.
  *
@@ -3499,3 +3586,50 @@ function calendar_output_fragment_event_form($args) {
     $html .= $mform->render();
     return $html;
 }
+
+/**
+ * Calculate the timestamp from the supplied Gregorian Year, Month, and Day.
+ *
+ * @param   int     $d The day
+ * @param   int     $m The month
+ * @param   int     $y The year
+ * @param   int     $time The timestamp to use instead of a separate y/m/d.
+ * @return  int     The timestamp
+ */
+function calendar_get_timestamp($d, $m, $y, $time = 0) {
+    // 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.
+    if (!empty($d) && !empty($m) && !empty($y)) {
+        if (checkdate($m, $d, $y)) {
+            $time = make_timestamp($y, $m, $d);
+        } else {
+            $time = time();
+        }
+    } else if (empty($time)) {
+        $time = time();
+    }
+
+    return $time;
+}
+
+/**
+ * Get the calendar footer options.
+ *
+ * @param calendar_information $calendar The calendar information object.
+ * @return array The data for template and template name.
+ */
+function calendar_get_footer_options($calendar) {
+    global $CFG, $USER, $DB, $PAGE;
+
+    // Generate hash for iCal link.
+    $rawhash = $USER->id . $DB->get_field('user', 'password', ['id' => $USER->id]) . $CFG->calendar_exportsalt;
+    $authtoken = sha1($rawhash);
+
+    $renderer = $PAGE->get_renderer('core_calendar');
+    $footer = new \core_calendar\external\footer_options_exporter($calendar, $USER->id, $authtoken);
+    $data = $footer->export($renderer);
+    $template = 'core_calendar/footer_options';
+
+    return [$data, $template];
+}
index f1bebaa..6e7cab8 100644 (file)
@@ -128,7 +128,7 @@ class core_calendar_renderer extends plugin_renderer_base {
      *     $month and $year are kept for backwards compatibility.
      * @return string
      */
-    protected function add_event_button($courseid, $day = null, $month = null, $year = null, $time = null) {
+    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.
@@ -312,234 +312,6 @@ class core_calendar_renderer extends plugin_renderer_base {
         return html_writer::tag('div', $eventhtml, array('class' => 'event', 'id' => 'event_' . $event->id));
     }
 
-    /**
-     * Displays a month in detail
-     *
-     * @param calendar_information $calendar
-     * @param moodle_url $returnurl the url to return to
-     * @return string
-     */
-    public function show_month_detailed(calendar_information $calendar, moodle_url $returnurl  = null) {
-        global $CFG;
-
-        if (empty($returnurl)) {
-            $returnurl = $this->page->url;
-        }
-
-        // Get the calendar type we are using.
-        $calendartype = \core_calendar\type_factory::get_calendar_instance();
-
-        // Store the display settings.
-        $display = new stdClass;
-        $display->thismonth = false;
-
-        // Get the specified date in the calendar type being used.
-        $date = $calendartype->timestamp_to_date_array($calendar->time);
-        $thisdate = $calendartype->timestamp_to_date_array(time());
-        if ($date['mon'] == $thisdate['mon'] && $date['year'] == $thisdate['year']) {
-            $display->thismonth = true;
-            $date = $thisdate;
-            $calendar->time = time();
-        }
-
-        // Get Gregorian date for the start of the month.
-        $gregoriandate = $calendartype->convert_to_gregorian($date['year'], $date['mon'], 1);
-        // Store the gregorian date values to be used later.
-        list($gy, $gm, $gd, $gh, $gmin) = array($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'],
-            $gregoriandate['hour'], $gregoriandate['minute']);
-
-        // Get the starting week day for this month.
-        $startwday = dayofweek(1, $date['mon'], $date['year']);
-        // Get the days in a week.
-        $daynames = calendar_get_days();
-        // Store the number of days in a week.
-        $numberofdaysinweek = $calendartype->get_num_weekdays();
-
-        $display->minwday = calendar_get_starting_weekday();
-        $display->maxwday = $display->minwday + ($numberofdaysinweek - 1);
-        $display->maxdays = calendar_days_in_month($date['mon'], $date['year']);
-
-        // These are used for DB queries, so we want unixtime, so we need to use Gregorian dates.
-        $display->tstart = make_timestamp($gy, $gm, $gd, $gh, $gmin, 0);
-        $display->tend = $display->tstart + ($display->maxdays * DAYSECS) - 1;
-
-        // Align the starting weekday to fall in our display range
-        // This is simple, not foolproof.
-        if ($startwday < $display->minwday) {
-            $startwday += $numberofdaysinweek;
-        }
-
-        // Get events from database
-        $events = calendar_get_legacy_events($display->tstart, $display->tend, $calendar->users, $calendar->groups,
-            $calendar->courses);
-        if (!empty($events)) {
-            foreach($events as $eventid => $event) {
-                $event = new calendar_event($event);
-                if (!empty($event->modulename)) {
-                    $instances = get_fast_modinfo($event->courseid)->get_instances_of($event->modulename);
-                    if (empty($instances[$event->instance]->uservisible)) {
-                        unset($events[$eventid]);
-                    }
-                }
-            }
-        }
-
-        // Extract information: events vs. time
-        calendar_events_by_day($events, $date['mon'], $date['year'], $eventsbyday, $durationbyday,
-            $typesbyday, $calendar->courses);
-
-        $output  = html_writer::start_tag('div', array('class'=>'header'));
-        $output .= $this->course_filter_selector($returnurl, get_string('detailedmonthviewfor', 'calendar'));
-        if (calendar_user_can_add_event($calendar->course)) {
-            $output .= $this->add_event_button($calendar->course->id, 0, 0, 0, $calendar->time);
-        }
-        $output .= html_writer::end_tag('div', array('class'=>'header'));
-        // Controls
-        $output .= html_writer::tag('div', calendar_top_controls('month', array('id' => $calendar->courseid,
-            'time' => $calendar->time)), array('class' => 'controls'));
-
-        $table = new html_table();
-        $table->attributes = array('class'=>'calendarmonth calendartable');
-        $table->summary = get_string('calendarheading', 'calendar', userdate($calendar->time, get_string('strftimemonthyear')));
-        $table->data = array();
-
-        // Get the day names as the header.
-        $header = array();
-        for($i = $display->minwday; $i <= $display->maxwday; ++$i) {
-            $header[] = $daynames[$i % $numberofdaysinweek]['shortname'];
-        }
-        $table->head = $header;
-
-        // For the table display. $week is the row; $dayweek is the column.
-        $week = 1;
-        $dayweek = $startwday;
-
-        $row = new html_table_row(array());
-
-        // Paddding (the first week may have blank days in the beginning)
-        for($i = $display->minwday; $i < $startwday; ++$i) {
-            $cell = new html_table_cell('&nbsp;');
-            $cell->attributes = array('class'=>'nottoday dayblank');
-            $row->cells[] = $cell;
-        }
-
-        // Now display all the calendar
-        $weekend = CALENDAR_DEFAULT_WEEKEND;
-        if (isset($CFG->calendar_weekend)) {
-            $weekend = intval($CFG->calendar_weekend);
-        }
-
-        $daytime = strtotime('-1 day', $display->tstart);
-        for ($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) {
-            $daytime = strtotime('+1 day', $daytime);
-            if($dayweek > $display->maxwday) {
-                // We need to change week (table row)
-                $table->data[] = $row;
-                $row = new html_table_row(array());
-                $dayweek = $display->minwday;
-                ++$week;
-            }
-
-            // Reset vars
-            $cell = new html_table_cell();
-            $dayhref = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php',
-                array('view' => 'day', 'course' => $calendar->courseid)), 0, 0, 0, $daytime);
-
-            $cellclasses = array();
-
-            if ($weekend & (1 << ($dayweek % $numberofdaysinweek))) {
-                // Weekend. This is true no matter what the exact range is.
-                $cellclasses[] = 'weekend';
-            }
-
-            // Special visual fx if an event is defined
-            if (isset($eventsbyday[$day])) {
-                if(count($eventsbyday[$day]) == 1) {
-                    $title = get_string('oneevent', 'calendar');
-                } else {
-                    $title = get_string('manyevents', 'calendar', count($eventsbyday[$day]));
-                }
-                $cell->text = html_writer::tag('div', html_writer::link($dayhref, $day, array('title'=>$title)), array('class'=>'day'));
-            } else {
-                $cell->text = html_writer::tag('div', $day, array('class'=>'day'));
-            }
-
-            // Special visual fx if an event spans many days
-            $durationclass = false;
-            if (isset($typesbyday[$day]['durationglobal'])) {
-                $durationclass = 'duration_global';
-            } else if (isset($typesbyday[$day]['durationcourse'])) {
-                $durationclass = 'duration_course';
-            } else if (isset($typesbyday[$day]['durationgroup'])) {
-                $durationclass = 'duration_group';
-            } else if (isset($typesbyday[$day]['durationuser'])) {
-                $durationclass = 'duration_user';
-            }
-            if ($durationclass) {
-                $cellclasses[] = 'duration';
-                $cellclasses[] = $durationclass;
-            }
-
-            // Special visual fx for today
-            if ($display->thismonth && $day == $date['mday']) {
-                $cellclasses[] = 'day today';
-            } else {
-                $cellclasses[] = 'day nottoday';
-            }
-            $cell->attributes = array('class'=>join(' ',$cellclasses));
-
-            if (isset($eventsbyday[$day])) {
-                $cell->text .= html_writer::start_tag('ul', array('class'=>'events-new'));
-                foreach($eventsbyday[$day] as $eventindex) {
-                    // If event has a class set then add it to the event <li> tag
-                    $attributes = array();
-                    if (!empty($events[$eventindex]->class)) {
-                        $attributes['class'] = $events[$eventindex]->class;
-                    }
-                    $dayhref->set_anchor('event_'.$events[$eventindex]->id);
-
-                    $eventcontext = $events[$eventindex]->context;
-                    $eventformatopts = array('context' => $eventcontext);
-                    // Get event name.
-                    $eventname = format_string($events[$eventindex]->name, true, $eventformatopts);
-                    // Include course's shortname into the event name, if applicable.
-                    $courseid = $events[$eventindex]->courseid;
-                    if (!empty($courseid) && $courseid !== SITEID) {
-                        $course = get_course($courseid);
-                        $eventnameparams = (object)[
-                            'name' => $eventname,
-                            'course' => format_string($course->shortname, true, $eventformatopts)
-                        ];
-                        $eventname = get_string('eventnameandcourse', 'calendar', $eventnameparams);
-                    }
-                    $link = html_writer::link($dayhref, $eventname, ['data-action' => 'view-event',
-                            'data-event-id' => $events[$eventindex]->id]);
-                    $cell->text .= html_writer::tag('li', $link, $attributes);
-                }
-                $cell->text .= html_writer::end_tag('ul');
-            }
-            if (isset($durationbyday[$day])) {
-                $cell->text .= html_writer::start_tag('ul', array('class'=>'events-underway'));
-                foreach($durationbyday[$day] as $eventindex) {
-                    $cell->text .= html_writer::tag('li', '['.format_string($events[$eventindex]->name,true).']', array('class'=>'events-underway'));
-                }
-                $cell->text .= html_writer::end_tag('ul');
-            }
-            $row->cells[] = $cell;
-        }
-
-        // Paddding (the last week may have blank days at the end)
-        for($i = $dayweek; $i <= $display->maxwday; ++$i) {
-            $cell = new html_table_cell('&nbsp;');
-            $cell->attributes = array('class'=>'nottoday dayblank');
-            $row->cells[] = $cell;
-        }
-        $table->data[] = $row;
-        $output .= html_writer::table($table);
-
-        return $output;
-    }
-
     /**
      * Displays upcoming events
      *
@@ -587,7 +359,7 @@ class core_calendar_renderer extends plugin_renderer_base {
      * @param string $label The label to use for the course select.
      * @return string
      */
-    protected function course_filter_selector(moodle_url $returnurl, $label=null) {
+    public function course_filter_selector(moodle_url $returnurl, $label=null) {
         global $USER, $SESSION, $CFG;
 
         if (!isloggedin() or isguestuser()) {
diff --git a/calendar/templates/footer_options.mustache b/calendar/templates/footer_options.mustache
new file mode 100644 (file)
index 0000000..05c2941
--- /dev/null
@@ -0,0 +1,37 @@
+{{!
+    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 core_calendar/footer_options
+
+    Displays export options on the calendar footer.
+
+    Example context (json):
+    {
+        "exportcalendarbutton": "<button class='btn btn-secondary'>Export calendar</button>",
+        "managesubscriptionbutton": "<button class='btn btn-secondary'>Manage subscriptions</button>",
+        "icalurl": "http://example.com/"
+    }
+}}
+<div class="bottom">
+    {{#exportcalendarbutton}}
+        {{> core/single_button }}
+    {{/exportcalendarbutton}}
+    {{#managesubscriptionbutton}}
+        {{> core/single_button }}
+    {{/managesubscriptionbutton}}
+    <a href="{{icalurl}}" title="{{#str}} quickdownloadcalendar, calendar {{/str}}" class="ical-link m-l-1">iCal</a>
+</div>
diff --git a/calendar/templates/month_detailed.mustache b/calendar/templates/month_detailed.mustache
new file mode 100644 (file)
index 0000000..106d81b
--- /dev/null
@@ -0,0 +1,99 @@
+{{!
+    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/month_detailed
+
+    Calendar month view.
+
+    The purpose of this template is to render the month view.
+
+    Classes required for JS:
+    * none
+
+    Data attributes required for JS:
+    * none
+
+    Example context (json):
+    {
+    }
+}}
+<span class="calendarwrapper" data-courseid="{{courseid}}">
+    {{> core_calendar/month_header }}
+    {{> core_calendar/month_navigation }}
+    <table class="calendarmonth calendartable card-deck m-b-0">
+        <thead>
+            <tr>
+                {{# daynames }}
+                <th class="header text-xs-center">
+                    {{shortname}}
+                </th>
+                {{/ daynames }}
+            </tr>
+        </thead>
+        <tbody>
+    {{#weeks}}
+            <tr>
+                {{#prepadding}}
+                    <td class="dayblank">&nbsp;</td>
+                {{/prepadding}}
+                {{#days}}
+                    <td class="day text-sm-center text-md-left{{!
+                            }}{{#istoday}} today{{/istoday}}{{!
+                            }}{{#isweekend}} weekend{{/isweekend}}{{!
+                            }}{{#durationevents.0}} duration{{/durationevents.0}}{{!
+                            }}{{#durationevents}} duration_{{.}}{{/durationevents}}{{!
+                        }}">
+                        <div class="hidden-sm-down text-xs-center">
+                            {{#events.0}}
+                                <a href="{{viewdaylink}}" class="day" title="{{viewdaylinktitle}}">{{mday}}</a>
+                            {{/events.0}}
+                            {{^events.0}}
+                                {{mday}}
+                            {{/events.0}}
+                            {{#events.0}}
+                                <ul>
+                                    {{#events}}
+                                        {{#underway}}
+                                            <li class="events-underway">[{{name}}]</li>
+                                        {{/underway}}
+                                        {{^underway}}
+                                            <li class="calendar_event_{{eventtype}}">
+                                                <a data-action="view-event" data-event-id="{{id}}" href="{{url}}">{{name}}</a>
+                                            </li>
+                                        {{/underway}}
+                                    {{/events}}
+                                </ul>
+                            {{/events.0}}
+                        </div>
+                        <div class="hidden-md-up hidden-desktop">
+                            {{#events.0}}
+                                <a href="{{viewdaylink}}" class="day" title="{{viewdaylinktitle}}">{{mday}}</a>
+                            {{/events.0}}
+                            {{^events.0}}
+                                {{mday}}
+                            {{/events.0}}
+                        </div>
+                    </td>
+                {{/days}}
+                {{#postpadding}}
+                    <td class="dayblank">&nbsp;</td>
+                {{/postpadding}}
+            </tr>
+    {{/weeks}}
+        </tbody>
+    </table>
+</span>
diff --git a/calendar/templates/month_header.mustache b/calendar/templates/month_header.mustache
new file mode 100644 (file)
index 0000000..56d6e49
--- /dev/null
@@ -0,0 +1,38 @@
+{{!
+    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/month_header
+
+    Calendar month header.
+
+    The purpose of this template is to render the month header.
+
+    Classes required for JS:
+    * none
+
+    Data attributes required for JS:
+    * none
+
+    Example context (json):
+    {
+    }
+}}
+{{#filter_selector}}
+<div class="header">
+    {{{filter_selector}}}
+</div>
+{{/filter_selector}}
diff --git a/calendar/templates/month_navigation.mustache b/calendar/templates/month_navigation.mustache
new file mode 100644 (file)
index 0000000..d7d3509
--- /dev/null
@@ -0,0 +1,38 @@
+{{!
+    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/month_navigation
+
+    Calendar month navigation.
+
+    The purpose of this template is to render the navigation to switch to previous and next months.
+
+    Classes required for JS:
+    * none
+
+    Data attributes required for JS:
+    * none
+
+    Example context (json):
+    {
+    }
+}}
+{{#navigation}}
+<div class="controls" data-view="{{view}}">
+    {{{navigation}}}
+</div>
+{{/navigation}}
index fc0ecc2..6f2ad09 100644 (file)
@@ -1267,4 +1267,27 @@ class core_calendar_externallib_testcase extends externallib_advanced_testcase {
         $this->assertCount(1, $groupedbycourse[$course2->id]);
         $this->assertEquals('Event 3', $groupedbycourse[$course2->id][0]['name']);
     }
+
+    /**
+     * Test for deleting module events.
+     */
+    public function test_delete_calendar_events_for_modules() {
+        $this->resetAfterTest();
+        $this->setAdminUser();
+        $course = $this->getDataGenerator()->create_course();
+        $nexttime = time() + DAYSECS;
+        $this->getDataGenerator()->create_module('assign', ['course' => $course->id, 'duedate' => $nexttime]);
+        $events = calendar_get_events(time(), $nexttime, true, true, true);
+        $this->assertCount(1, $events);
+        $params = [];
+        foreach ($events as $event) {
+            $params[] = [
+                'eventid' => $event->id,
+                'repeat' => false
+            ];
+        }
+
+        $this->expectException('moodle_exception');
+        core_calendar_external::delete_calendar_events($params);
+    }
 }
index f974ba5..ba0bc94 100644 (file)
@@ -132,49 +132,34 @@ echo $renderer->start_layout();
 echo html_writer::start_tag('div', array('class'=>'heightcontainer'));
 echo $OUTPUT->heading(get_string('calendar', 'calendar'));
 
-switch($view) {
-    case 'day':
-        echo $renderer->show_day($calendar);
-    break;
-    case 'month':
-        echo $renderer->show_month_detailed($calendar, $url);
-    break;
-    case 'upcoming':
-        $defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD;
-        if (isset($CFG->calendar_lookahead)) {
-            $defaultlookahead = intval($CFG->calendar_lookahead);
-        }
-        $lookahead = get_user_preferences('calendar_lookahead', $defaultlookahead);
-
-        $defaultmaxevents = CALENDAR_DEFAULT_UPCOMING_MAXEVENTS;
-        if (isset($CFG->calendar_maxevents)) {
-            $defaultmaxevents = intval($CFG->calendar_maxevents);
-        }
-        $maxevents = get_user_preferences('calendar_maxevents', $defaultmaxevents);
-        echo $renderer->show_upcoming_events($calendar, $lookahead, $maxevents);
-    break;
-}
-
-//Link to calendar export page.
-echo $OUTPUT->container_start('bottom');
-if (!empty($CFG->enablecalendarexport)) {
-    echo $OUTPUT->single_button(new moodle_url('export.php', array('course'=>$courseid)), get_string('exportcalendar', 'calendar'));
-    if (calendar_user_can_add_event($course)) {
-        echo $OUTPUT->single_button(new moodle_url('/calendar/managesubscriptions.php', array('course'=>$courseid)), get_string('managesubscriptions', 'calendar'));
-    }
-    if (isloggedin()) {
-        $authtoken = sha1($USER->id . $DB->get_field('user', 'password', array('id' => $USER->id)) . $CFG->calendar_exportsalt);
-        $link = new moodle_url(
-            '/calendar/export_execute.php',
-            array('preset_what'=>'all', 'preset_time' => 'recentupcoming', 'userid' => $USER->id, 'authtoken'=>$authtoken)
-        );
-        echo html_writer::tag('a', 'iCal',
-            array('href' => $link, 'title' => get_string('quickdownloadcalendar', 'calendar'), 'class' => 'ical-link m-l-1'));
+if ($view == 'day' || $view == 'upcoming') {
+    switch($view) {
+        case 'day':
+            echo $renderer->show_day($calendar);
+        break;
+        case 'upcoming':
+            $defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD;
+            if (isset($CFG->calendar_lookahead)) {
+                $defaultlookahead = intval($CFG->calendar_lookahead);
+            }
+            $lookahead = get_user_preferences('calendar_lookahead', $defaultlookahead);
+
+            $defaultmaxevents = CALENDAR_DEFAULT_UPCOMING_MAXEVENTS;
+            if (isset($CFG->calendar_maxevents)) {
+                $defaultmaxevents = intval($CFG->calendar_maxevents);
+            }
+            $maxevents = get_user_preferences('calendar_maxevents', $defaultmaxevents);
+            echo $renderer->show_upcoming_events($calendar, $lookahead, $maxevents);
+        break;
     }
+} else if ($view == 'month') {
+    list($data, $template) = calendar_get_view($calendar, $view);
+    echo $renderer->render_from_template($template, $data);
 }
-
-echo $OUTPUT->container_end();
 echo html_writer::end_tag('div');
-echo $renderer->complete_layout();
+
+list($data, $template) = calendar_get_footer_options($calendar);
+echo $renderer->render_from_template($template, $data);
+
 $PAGE->requires->js_call_amd('core_calendar/calendar', 'init');
 echo $OUTPUT->footer();
index 94b6638..fb02c22 100644 (file)
@@ -168,8 +168,8 @@ class helper {
      * @return array
      */
     public static function get_category_listitem_actions(\coursecat $category) {
-        global $PAGE;
-        $baseurl = new \moodle_url('/course/management.php', array('categoryid' => $category->id, 'sesskey' => \sesskey()));
+        $manageurl = new \moodle_url('/course/management.php', array('categoryid' => $category->id));
+        $baseurl = new \moodle_url($manageurl, array('sesskey' => \sesskey()));
         $actions = array();
         // Edit.
         if ($category->can_edit()) {
@@ -254,7 +254,7 @@ class helper {
         if ($category->can_review_roles()) {
             $actions['assignroles'] = array(
                 'url' => new \moodle_url('/admin/roles/assign.php', array('contextid' => $category->get_context()->id,
-                    'returnurl' => $PAGE->url->out_as_local_url(false))),
+                    'returnurl' => $manageurl->out_as_local_url(false))),
                 'icon' => new \pix_icon('t/assignroles', new \lang_string('assignroles', 'role')),
                 'string' => new \lang_string('assignroles', 'role')
             );
@@ -264,7 +264,7 @@ class helper {
         if ($category->can_review_permissions()) {
             $actions['permissions'] = array(
                 'url' => new \moodle_url('/admin/roles/permissions.php', array('contextid' => $category->get_context()->id,
-                    'returnurl' => $PAGE->url->out_as_local_url(false))),
+                    'returnurl' => $manageurl->out_as_local_url(false))),
                 'icon' => new \pix_icon('i/permissions', new \lang_string('permissions', 'role')),
                 'string' => new \lang_string('permissions', 'role')
             );
@@ -274,7 +274,7 @@ class helper {
         if ($category->can_review_permissions()) {
             $actions['checkroles'] = array(
                 'url' => new \moodle_url('/admin/roles/check.php', array('contextid' => $category->get_context()->id,
-                    'returnurl' => $PAGE->url->out_as_local_url(false))),
+                    'returnurl' => $manageurl->out_as_local_url(false))),
                 'icon' => new \pix_icon('i/checkpermissions', new \lang_string('checkpermissions', 'role')),
                 'string' => new \lang_string('checkpermissions', 'role')
             );
@@ -395,7 +395,7 @@ class helper {
         // Permissions.
         if ($course->can_review_enrolments()) {
             $actions['enrolledusers'] = array(
-                'url' => new \moodle_url('/enrol/users.php', array('id' => $course->id)),
+                'url' => new \moodle_url('/user/index.php', array('id' => $course->id)),
                 'string' => \get_string('enrolledusers', 'enrol')
             );
         }
index c833cca..727a1f7 100644 (file)
@@ -175,7 +175,7 @@ if ($editform->is_cancelled()) {
                 if ($plugin = enrol_get_plugin($instance->enrol)) {
                     if ($plugin->get_manual_enrol_link($instance)) {
                         // We know that the ajax enrol UI will have an option to enrol.
-                        $courseurl = new moodle_url('/enrol/users.php', array('id' => $course->id, 'newcourse' => 1));
+                        $courseurl = new moodle_url('/user/index.php', array('id' => $course->id, 'newcourse' => 1));
                         break;
                     }
                 }
index bdb48f3..e55b58d 100644 (file)
@@ -24,20 +24,18 @@ Feature: Sections can be edited and deleted in topics format
     And I am on "Course 1" course homepage with editing mode on
 
   Scenario: View the default name of the general section in topics format
-    When I click on "Edit section" "link" in the "li#section-0" "css_element"
+    When I edit the section "0"
     Then the field "Custom" matches value "0"
     And the field "New value for Section name" matches value "General"
 
   Scenario: Edit the default name of the general section in topics format
-    When I click on "Edit section" "link" in the "li#section-0" "css_element"
-    And I set the following fields to these values:
+    When I edit the section "0" and I fill the form with:
       | Custom | 1                     |
       | New value for Section name      | This is the general section |
-    And I press "Save changes"
     Then I should see "This is the general section" in the "li#section-0" "css_element"
 
   Scenario: View the default name of the second section in topics format
-    When I click on "Edit topic" "link" in the "li#section-2" "css_element"
+    When I edit the section "2"
     Then the field "Custom" matches value "0"
     And the field "New value for Section name" matches value "Topic 2"
 
index 7e1d175..a51a803 100644 (file)
@@ -24,37 +24,31 @@ Feature: Sections can be edited and deleted in weeks format
     And I am on "Course 1" course homepage with editing mode on
 
   Scenario: View the default name of the general section in weeks format
-    When I click on "Edit section" "link" in the "li#section-0" "css_element"
+    When I edit the section "0"
     Then the field "Custom" matches value "0"
     And the field "New value for Section name" matches value "General"
 
   Scenario: Edit the default name of the general section in weeks format
-    When I click on "Edit section" "link" in the "li#section-0" "css_element"
-    And I set the following fields to these values:
+    When I edit the section "0" and I fill the form with:
       | Custom | 1                      |
       | New value for Section name      | This is the general section |
-    And I press "Save changes"
     Then I should see "This is the general section" in the "li#section-0" "css_element"
 
   Scenario: View the default name of the second section in weeks format
-    When I click on "Edit week" "link" in the "li#section-2" "css_element"
+    When I edit the section "2"
     Then the field "Custom" matches value "0"
     And the field "New value for Section name" matches value "8 May - 14 May"
 
   Scenario: Edit section summary in weeks format
-    When I click on "Edit week" "link" in the "li#section-2" "css_element"
-    And I set the following fields to these values:
+    When I edit the section "2" and I fill the form with:
       | Summary | Welcome to section 2 |
-    And I press "Save changes"
     Then I should see "Welcome to section 2" in the "li#section-2" "css_element"
 
   Scenario: Edit section default name in weeks format
     Given I should see "8 May - 14 May" in the "li#section-2" "css_element"
-    When I click on "Edit week" "link" in the "li#section-2" "css_element"
-    And I set the following fields to these values:
+    When I edit the section "2" and I fill the form with:
       | Custom | 1                  |
       | New value for Section name      | This is the second week |
-    And I press "Save changes"
     Then I should see "This is the second week" in the "li#section-2" "css_element"
     And I should not see "8 May - 14 May" in the "li#section-2" "css_element"
 
index 4b20f93..52f4354 100644 (file)
@@ -399,7 +399,7 @@ class behat_course extends behat_base {
 
         // We need to know the course format as the text strings depends on them.
         $courseformat = $this->get_course_format();
-        if (get_string_manager()->string_exists('editsection', $courseformat)) {
+        if ($sectionnumber > 0 && get_string_manager()->string_exists('editsection', $courseformat)) {
             $stredit = get_string('editsection', $courseformat);
         } else {
             $stredit = get_string('editsection');
index c51f30c..fee1d43 100644 (file)
@@ -1900,6 +1900,52 @@ class core_course_courselib_testcase extends advanced_testcase {
         $this->assertEventContextNotUsed($event);
     }
 
+    /**
+     * Test that triggering a course_backup_created event works as expected.
+     */
+    public function test_course_backup_created_event() {
+        global $CFG;
+
+        // Get the necessary files to perform backup and restore.
+        require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
+        require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
+
+        $this->resetAfterTest();
+
+        // Set to admin user.
+        $this->setAdminUser();
+
+        // The user id is going to be 2 since we are the admin user.
+        $userid = 2;
+
+        // Create a course.
+        $course = $this->getDataGenerator()->create_course();
+
+        // Create backup file and save it to the backup location.
+        $bc = new backup_controller(backup::TYPE_1COURSE, $course->id, backup::FORMAT_MOODLE,
+            backup::INTERACTIVE_NO, backup::MODE_GENERAL, $userid);
+        $sink = $this->redirectEvents();
+        $bc->execute_plan();
+
+        // Capture the event.
+        $events = $sink->get_events();
+        $sink->close();
+
+        // Validate the event.
+        $event = array_pop($events);
+        $this->assertInstanceOf('\core\event\course_backup_created', $event);
+        $this->assertEquals('course', $event->objecttable);
+        $this->assertEquals($bc->get_courseid(), $event->objectid);
+        $this->assertEquals(context_course::instance($bc->get_courseid())->id, $event->contextid);
+
+        $url = new moodle_url('/course/view.php', array('id' => $event->objectid));
+        $this->assertEquals($url, $event->get_url());
+        $this->assertEventContextNotUsed($event);
+
+        // Destroy the resource controller since we are done using it.
+        $bc->destroy();
+    }
+
     /**
      * Test that triggering a course_restored event works as expected.
      */
diff --git a/enrol/bulkchange.php b/enrol/bulkchange.php
deleted file mode 100644 (file)
index 1d451ae..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-<?php
-// 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/>.
-
-/**
- * Bulk user enrolment processing.
- *
- * @package    core_enrol
- * @copyright  2011 Sam Hemelryk
- * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-require('../config.php');
-require_once("$CFG->dirroot/enrol/locallib.php");
-require_once("$CFG->dirroot/enrol/users_forms.php");
-require_once("$CFG->dirroot/enrol/renderer.php");
-require_once("$CFG->dirroot/group/lib.php");
-
-$id         = required_param('id', PARAM_INT); // course id
-$bulkuserop = required_param('bulkuserop', PARAM_ALPHANUMEXT);
-$userids    = required_param_array('bulkuser', PARAM_INT);
-$action     = optional_param('action', '', PARAM_ALPHANUMEXT);
-$filter     = optional_param('ifilter', 0, PARAM_INT);
-
-$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
-$context = context_course::instance($course->id, MUST_EXIST);
-
-if ($course->id == SITEID) {
-    redirect(new moodle_url('/'));
-}
-
-require_login($course);
-require_capability('moodle/course:enrolreview', $context);
-$PAGE->set_pagelayout('admin');
-
-$manager = new course_enrolment_manager($PAGE, $course, $filter);
-$table = new course_enrolment_users_table($manager, $PAGE);
-$returnurl = new moodle_url('/enrol/users.php', $table->get_combined_url_params());
-$actionurl = new moodle_url('/enrol/bulkchange.php', $table->get_combined_url_params()+array('bulkuserop' => $bulkuserop));
-
-$PAGE->set_url($actionurl);
-navigation_node::override_active_url(new moodle_url('/enrol/users.php', array('id' => $id)));
-
-$ops = $table->get_bulk_user_enrolment_operations();
-if (!array_key_exists($bulkuserop, $ops)) {
-    throw new moodle_exception('invalidbulkenrolop');
-}
-$operation = $ops[$bulkuserop];
-
-// Prepare the properties of the form
-$users = $manager->get_users_enrolments($userids);
-
-// Get the form for the bulk operation
-$mform = $operation->get_form($actionurl, array('users' => $users));
-// If the mform is false then attempt an immediate process. This may be an immediate action that
-// doesn't require user input OR confirmation.... who know what but maybe one day
-if ($mform === false) {
-    if ($operation->process($manager, $users, new stdClass)) {
-        redirect($returnurl);
-    } else {
-        print_error('errorwithbulkoperation', 'enrol');
-    }
-}
-// Check if the bulk operation has been cancelled
-if ($mform->is_cancelled()) {
-    redirect($returnurl);
-}
-if ($mform->is_submitted() && $mform->is_validated() && confirm_sesskey()) {
-    if ($operation->process($manager, $users, $mform->get_data())) {
-        redirect($returnurl);
-    }
-}
-
-$pagetitle = get_string('bulkuseroperation', 'enrol');
-
-$PAGE->set_title($pagetitle);
-$PAGE->set_heading($pagetitle);
-echo $OUTPUT->header();
-echo $OUTPUT->heading($operation->get_title());
-$mform->display();
-echo $OUTPUT->footer();
\ No newline at end of file
index fa4b6b8..e7bcab9 100644 (file)
@@ -130,18 +130,18 @@ class enrol_flatfile_plugin extends enrol_plugin {
         $instance = $ue->enrolmentinstance;
         $params = $manager->get_moodlepage()->url->params();
         $params['ue'] = $ue->id;
-        if ($this->allow_unenrol_user($instance, $ue) && has_capability("enrol/flatfile:unenrol", $context)) {
-            $url = new moodle_url('/enrol/unenroluser.php', $params);
-            $actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL);
-            $actions[] = new user_enrolment_action(new pix_icon('t/delete', get_string('unenrol', 'enrol')),
-                get_string('unenrol', 'enrol'), $url, $actionparams);
-        }
         if ($this->allow_manage($instance) && has_capability("enrol/flatfile:manage", $context)) {
             $url = new moodle_url('/enrol/editenrolment.php', $params);
             $actionparams = array('class' => 'editenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_EDIT);
             $actions[] = new user_enrolment_action(new pix_icon('t/edit', get_string('editenrolment', 'enrol')),
                 get_string('editenrolment', 'enrol'), $url, $actionparams);
         }
+        if ($this->allow_unenrol_user($instance, $ue) && has_capability("enrol/flatfile:unenrol", $context)) {
+            $url = new moodle_url('/enrol/unenroluser.php', $params);
+            $actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL);
+            $actions[] = new user_enrolment_action(new pix_icon('t/delete', get_string('unenrol', 'enrol')),
+                get_string('unenrol', 'enrol'), $url, $actionparams);
+        }
         return $actions;
     }
 
index f8b7ca4..bf6ab9d 100644 (file)
@@ -803,7 +803,7 @@ class course_enrolment_manager {
      */
     public function edit_enrolment($userenrolment, $data) {
         //Only allow editing if the user has the appropriate capability
-        //Already checked in /enrol/users.php but checking again in case this function is called from elsewhere
+        //Already checked in /user/index.php but checking again in case this function is called from elsewhere
         list($instance, $plugin) = $this->get_user_enrolment_components($userenrolment);
         if ($instance && $plugin && $plugin->allow_manage($instance) && has_capability("enrol/$instance->enrol:manage", $this->context)) {
             if (!isset($data->status)) {
index 3e6cb2e..6f5ac9e 100644 (file)
@@ -390,18 +390,18 @@ class enrol_lti_plugin extends enrol_plugin {
         $instance = $ue->enrolmentinstance;
         $params = $manager->get_moodlepage()->url->params();
         $params['ue'] = $ue->id;
+        if ($this->allow_manage($instance) && has_capability("enrol/lti:manage", $context)) {
+            $url = new moodle_url('/enrol/editenrolment.php', $params);
+            $actionparams = array('class' => 'editenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_EDIT);
+            $actions[] = new user_enrolment_action(new pix_icon('t/edit', get_string('editenrolment', 'enrol')),
+                get_string('editenrolment', 'enrol'), $url, $actionparams);
+        }
         if ($this->allow_unenrol_user($instance, $ue) && has_capability("enrol/lti:unenrol", $context)) {
             $url = new moodle_url('/enrol/unenroluser.php', $params);
             $actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL);
             $actions[] = new user_enrolment_action(new pix_icon('t/delete', get_string('unenrol', 'enrol')),
                 get_string('unenrol', 'enrol'), $url, $actionparams);
         }
-        if ($this->allow_manage($instance) && has_capability("enrol/lti:manage", $context)) {
-            $url = new moodle_url('/enrol/editenrolment.php', $params);
-            $actionparams = array('class' => 'editenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_EDIT);
-            $actions[] = new user_enrolment_action(new pix_icon('t/edit', get_string('editenrolment', 'enrol')),
-                get_string('editenrolment', 'enrol'), $url, $actionparam);
-        }
         return $actions;
     }
 
index 676901d..01de8e3 100644 (file)
@@ -374,18 +374,18 @@ class enrol_manual_plugin extends enrol_plugin {
         $instance = $ue->enrolmentinstance;
         $params = $manager->get_moodlepage()->url->params();
         $params['ue'] = $ue->id;
-        if ($this->allow_unenrol_user($instance, $ue) && has_capability("enrol/manual:unenrol", $context)) {
-            $url = new moodle_url('/enrol/unenroluser.php', $params);
-            $actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL);
-            $actions[] = new user_enrolment_action(new pix_icon('t/delete', get_string('unenrol', 'enrol')),
-                get_string('unenrol', 'enrol'), $url, $actionparams);
-        }
         if ($this->allow_manage($instance) && has_capability("enrol/manual:manage", $context)) {
             $url = new moodle_url('/enrol/editenrolment.php', $params);
             $actionparams = array('class' => 'editenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_EDIT);
             $actions[] = new user_enrolment_action(new pix_icon('t/edit', get_string('editenrolment', 'enrol')),
                 get_string('editenrolment', 'enrol'), $url, $actionparams);
         }
+        if ($this->allow_unenrol_user($instance, $ue) && has_capability("enrol/manual:unenrol", $context)) {
+            $url = new moodle_url('/enrol/unenroluser.php', $params);
+            $actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL);
+            $actions[] = new user_enrolment_action(new pix_icon('t/delete', get_string('unenrol', 'enrol')),
+                get_string('unenrol', 'enrol'), $url, $actionparams);
+        }
         return $actions;
     }
 
index e3161d4..9eb8758 100644 (file)
@@ -69,7 +69,7 @@ $PAGE->set_url('/enrol/manual/manage.php', array('enrolid'=>$instance->id));
 $PAGE->set_pagelayout('admin');
 $PAGE->set_title($enrol_manual->get_instance_name($instance));
 $PAGE->set_heading($course->fullname);
-navigation_node::override_active_url(new moodle_url('/enrol/users.php', array('id'=>$course->id)));
+navigation_node::override_active_url(new moodle_url('/user/index.php', array('id'=>$course->id)));
 
 // Create the user selector objects.
 $options = array('enrolid' => $enrolid, 'accesscontext' => $context);
index 52d1d19..cc65fcf 100644 (file)
@@ -41,9 +41,8 @@ Feature: Enrolments are synchronised with meta courses
     And I add "Course meta link" enrolment method with:
       | Link course  | C1C1 |
     And I navigate to "Enrolled users" node in "Course administration > Users"
-    Then I should see "Student 1"
-    And I should see "Student 4"
-    And I should not see "Groupcourse" in the "table.userenrolment" "css_element"
+    Then I should see "No groups" in the "Student 1" "table_row"
+    And I should see "No groups" in the "Student 4" "table_row"
 
   Scenario: Add meta enrolment instance with groups
     When I am on "Course 3" course homepage
@@ -105,8 +104,8 @@ Feature: Enrolments are synchronised with meta courses
     And I should see "Groupcourse 1" in the "Student 2" "table_row"
     And I should see "Groupcourse 1" in the "Student 3" "table_row"
     And I should see "Groupcourse 1" in the "Student 4" "table_row"
-    And I should see "Course 2" in the "Student 1" "table_row"
-    And I should not see "Course 2" in the "Student 3" "table_row"
+    And I click on "[data-enrolinstancename='Course meta link (Course 2)'] a[data-action=showdetails]" "css_element" in the "Student 1" "table_row"
+    And I should see "Course meta link (Course 2)" in the "Enrolment method" "table_row"
 
   Scenario: Unenrol a user from the course participants page that was enrolled via course meta link.
     Given I am on "Course 3" course homepage
index f2cab89..8041a7e 100644 (file)
@@ -289,18 +289,18 @@ class enrol_paypal_plugin extends enrol_plugin {
         $instance = $ue->enrolmentinstance;
         $params = $manager->get_moodlepage()->url->params();
         $params['ue'] = $ue->id;
-        if ($this->allow_unenrol($instance) && has_capability("enrol/paypal:unenrol", $context)) {
-            $url = new moodle_url('/enrol/unenroluser.php', $params);
-            $actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL);
-            $actions[] = new user_enrolment_action(new pix_icon('t/delete', get_string('unenrol', 'enrol')),
-                get_string('unenrol', 'enrol'), $url, $actionparams);
-        }
         if ($this->allow_manage($instance) && has_capability("enrol/paypal:manage", $context)) {
             $url = new moodle_url('/enrol/editenrolment.php', $params);
             $actionparams = array('class' => 'editenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_EDIT);
             $actions[] = new user_enrolment_action(new pix_icon('t/edit', get_string('editenrolment', 'enrol')),
                 get_string('editenrolment', 'enrol'), $url, $actionparams);
         }
+        if ($this->allow_unenrol($instance) && has_capability("enrol/paypal:unenrol", $context)) {
+            $url = new moodle_url('/enrol/unenroluser.php', $params);
+            $actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL);
+            $actions[] = new user_enrolment_action(new pix_icon('t/delete', get_string('unenrol', 'enrol')),
+                get_string('unenrol', 'enrol'), $url, $actionparams);
+        }
         return $actions;
     }
 
index a283de8..a1bc241 100644 (file)
  */
 class core_enrol_renderer extends plugin_renderer_base {
 
-    /**
-     * Renders a course enrolment table
-     *
-     * @param course_enrolment_table $table
-     * @param moodleform $mform Form that contains filter controls
-     * @return string
-     */
-    public function render_course_enrolment_users_table(course_enrolment_users_table $table,
-            moodleform $mform) {
-
-        $table->initialise_javascript();
-
-        $buttons = $table->get_manual_enrol_buttons();
-        $buttonhtml = '';
-        if (count($buttons) > 0) {
-            $buttonhtml .= html_writer::start_tag('div', array('class' => 'enrol_user_buttons enrol-users-page-action'));
-            foreach ($buttons as $button) {
-                $buttonhtml .= $this->render($button);
-            }
-            $buttonhtml .= html_writer::end_tag('div');
-        }
-
-        $content = '';
-        if (!empty($buttonhtml)) {
-            $content .= $buttonhtml;
-        }
-        $content .= html_writer::start_tag('div', array('class' => 'form-inline'));
-        $content .= $mform->render();
-        $content .= html_writer::end_tag('div');
-
-        $content .= $this->output->render($table->get_paging_bar());
-
-        // Check if the table has any bulk operations. If it does we want to wrap the table in a
-        // form so that we can capture and perform any required bulk operations.
-        if ($table->has_bulk_user_enrolment_operations()) {
-            $content .= html_writer::start_tag('form', array('action' => new moodle_url('/enrol/bulkchange.php'), 'method' => 'post'));
-            foreach ($table->get_combined_url_params() as $key => $value) {
-                if ($key == 'action') {
-                    continue;
-                }
-                $content .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $key, 'value' => $value));
-            }
-            $content .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'action', 'value' => 'bulkchange'));
-            $content .= html_writer::table($table);
-            $content .= html_writer::start_tag('div', array('class' => 'singleselect bulkuserop'));
-            $content .= html_writer::start_tag('select', array('name' => 'bulkuserop'));
-            $content .= html_writer::tag('option', get_string('withselectedusers', 'enrol'), array('value' => ''));
-            $options = array('' => get_string('withselectedusers', 'enrol'));
-            foreach ($table->get_bulk_user_enrolment_operations() as $operation) {
-                $content .= html_writer::tag('option', $operation->get_title(), array('value' => $operation->get_identifier()));
-            }
-            $content .= html_writer::end_tag('select');
-            $content .= html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('go')));
-            $content .= html_writer::end_tag('div');
-
-            $content .= html_writer::end_tag('form');
-        } else {
-            $content .= html_writer::table($table);
-        }
-        $content .= $this->output->render($table->get_paging_bar());
-        if (!empty($buttonhtml)) {
-            $content .= $buttonhtml;
-        }
-        return $content;
-    }
-
     /**
      * Renderers the enrol_user_button.
      *
index a1bfd9b..e612891 100644 (file)
@@ -534,18 +534,18 @@ class enrol_self_plugin extends enrol_plugin {
         $instance = $ue->enrolmentinstance;
         $params = $manager->get_moodlepage()->url->params();
         $params['ue'] = $ue->id;
-        if ($this->allow_unenrol($instance) && has_capability("enrol/self:unenrol", $context)) {
-            $url = new moodle_url('/enrol/unenroluser.php', $params);
-            $actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL);
-            $actions[] = new user_enrolment_action(new pix_icon('t/delete', get_string('unenrol', 'enrol')),
-                get_string('unenrol', 'enrol'), $url, $actionparams);
-        }
         if ($this->allow_manage($instance) && has_capability("enrol/self:manage", $context)) {
             $url = new moodle_url('/enrol/editenrolment.php', $params);
             $actionparams = array('class' => 'editenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_EDIT);
             $actions[] = new user_enrolment_action(new pix_icon('t/edit', get_string('editenrolment', 'enrol')),
                 get_string('editenrolment', 'enrol'), $url, $actionparams);
         }
+        if ($this->allow_unenrol($instance) && has_capability("enrol/self:unenrol", $context)) {
+            $url = new moodle_url('/enrol/unenroluser.php', $params);
+            $actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL);
+            $actions[] = new user_enrolment_action(new pix_icon('t/delete', get_string('unenrol', 'enrol')),
+                get_string('unenrol', 'enrol'), $url, $actionparams);
+        }
         return $actions;
     }
 
index 282f452..0a7aab9 100644 (file)
@@ -23,7 +23,7 @@ Feature: Users can be added to multiple groups at once
       | student1 | C1 | editingteacher |
 
   @javascript
-  Scenario: Adding a user to one group
+  Scenario: Adding a user to multiple groups
     Given I log in as "teacher1"
     And I am on "Course 1" course homepage
     And I follow "Participants"
@@ -35,15 +35,3 @@ Feature: Users can be added to multiple groups at once
     And I press key "27" in the field "Edit groups for \"Student 1\""
     And I click on "Save changes" "link" in the "student1" "table_row"
     Then I should see "Group 1, Group 2"
-
-  @javascript
-  Scenario: Adding a user to multiple group
-    Given I log in as "teacher1"
-    And I am on "Course 1" course homepage
-    And I navigate to "Enrolled users" node in "Course administration > Users"
-    And I click on "Add user into group" "link" in the "student1" "table_row"
-    When I set the field "Add user into group" to "Group 1, Group 2, Group 3"
-    And I press "Save changes"
-    Then I should see "Group 1"
-    And I should see "Group 2"
-    And I should see "Group 3"
diff --git a/enrol/tests/behat/filter_enrolled_users.feature b/enrol/tests/behat/filter_enrolled_users.feature
deleted file mode 100644 (file)
index 8edf458..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-@core_enrol @core_group
-Feature: Enrolled users can be filtered by group
-  In order to filter the list of enrolled users
-  As a teacher
-  I need to visit the enrolled users page and select a group to filter by
-
-  Background:
-    Given the following "courses" exist:
-      | fullname | shortname |
-      | Course 1 | C1        |
-      | Course 2 | C2        |
-    And the following "users" exist:
-      | username | firstname | lastname |
-      | student1 | Student   | 1        |
-      | student2 | Student   | 2        |
-      | student3 | Student   | 3        |
-      | teacher1 | Teacher   | 1        |
-    And the following "course enrolments" exist:
-      | user     | course | role           |
-      | student1 | C1     | student        |
-      | student2 | C1     | student        |
-      | student3 | C1     | student        |
-      | student1 | C2     | student        |
-      | student2 | C2     | student        |
-      | student3 | C2     | student        |
-      | teacher1 | C1     | editingteacher |
-      | teacher1 | C2     | editingteacher |
-    And the following "groups" exist:
-      | name    | course | idnumber |
-      | Group 1 | C1     | G1       |
-      | Group 2 | C1     | G2       |
-      | Group 3 | C2     | G3       |
-    And the following "group members" exist:
-      | user     | group |
-      | student2 | G1    |
-      | student2 | G2    |
-      | student3 | G2    |
-      | student1 | G3    |
-
-  Scenario Outline:
-    Given I log in as "teacher1"
-    And I am on "Course 1" course homepage
-    And I navigate to "Enrolled users" node in "Course administration > Users"
-
-    When I set the field "Group" to "<group>"
-    And I press "Filter"
-
-    Then I should see "<expected1>"
-    And I should see "<expected2>"
-    And I should see "<expected3>"
-    And I should not see "<notexpected1>"
-    And I should not see "<notexpected2>"
-    And I should see "<expected4>"
-
-    # Note the 'XX-IGNORE-XX' elements are for when there is less than 2 'not expected' items.
-    Examples:
-      | group            | expected1 | expected2 | expected3 | expected4        | notexpected1 | notexpected2 |
-      | All participants | Student 1 | Student 2 | Student 3 | 4 enrolled users | XX-IGNORE-XX | XX-IGNORE-XX |
-      | No group         | Student 1 |           |           | 2 enrolled users | Student 2    | Student 3    |
-      | Group 1          | Student 2 |           |           | 1 enrolled users | Student 1    | Student 3    |
-      | Group 2          | Student 2 | Student 3 |           | 2 enrolled users | Student 1    | XX-IGNORE-XX |
index f170c7a..528fe37 100644 (file)
@@ -1,6 +1,11 @@
 This files describes API changes in /enrol/* - plugins,
 information provided here is intended especially for developers.
 
+=== 3.4 ===
+
+* render_course_enrolment_users_table method has been removed from the renderer. The enrolled users page is now
+  combined with the participants page. /enrol/users.php no longer exists.
+
 === 3.3 ===
 
 * External function core_enrol_external::get_users_courses now return the user progress, start and the end course dates.
diff --git a/enrol/users.php b/enrol/users.php
deleted file mode 100644 (file)
index 403121d..0000000
+++ /dev/null
@@ -1,259 +0,0 @@
-<?php
-// 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/>.
-
-/**
- * Main course enrolment management UI, this is not compatible with frontpage course.
- *
- * @package    core_enrol
- * @copyright  2010 Petr Skoda {@link http://skodak.org}
- * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-require('../config.php');
-require_once("$CFG->dirroot/enrol/locallib.php");
-require_once("$CFG->dirroot/enrol/users_forms.php");
-require_once("$CFG->dirroot/enrol/renderer.php");
-require_once("$CFG->dirroot/group/lib.php");
-
-$id      = required_param('id', PARAM_INT); // course id
-$action  = optional_param('action', '', PARAM_ALPHANUMEXT);
-$filter  = optional_param('ifilter', 0, PARAM_INT);
-$search  = optional_param('search', '', PARAM_RAW);
-$role    = optional_param('role', 0, PARAM_INT);
-$fgroup  = optional_param('filtergroup', 0, PARAM_INT);
-$status  = optional_param('status', -1, PARAM_INT);
-$newcourse = optional_param('newcourse', false, PARAM_BOOL);
-
-// When users reset the form, redirect back to first page without other params.
-if (optional_param('resetbutton', '', PARAM_RAW) !== '') {
-    redirect('users.php?id=' . $id . '&newcourse=' . $newcourse);
-}
-
-$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
-$context = context_course::instance($course->id, MUST_EXIST);
-
-if ($course->id == SITEID) {
-    redirect(new moodle_url('/'));
-}
-
-require_login($course);
-require_capability('moodle/course:enrolreview', $context);
-$PAGE->set_pagelayout('admin');
-
-$manager = new course_enrolment_manager($PAGE, $course, $filter, $role, $search, $fgroup, $status);
-$table = new course_enrolment_users_table($manager, $PAGE);
-$PAGE->set_url('/enrol/users.php', $manager->get_url_params()+$table->get_url_params()+array('newcourse' => $newcourse));
-navigation_node::override_active_url(new moodle_url('/enrol/users.php', array('id' => $id)));
-
-// Check if there is an action to take
-if ($action) {
-
-    // Check if the page is confirmed (and sesskey is correct)
-    $confirm = optional_param('confirm', false, PARAM_BOOL) && confirm_sesskey();
-
-    $actiontaken = false;
-    $pagetitle = '';
-    $pageheading = '';
-    $mform = null;
-    $pagecontent = null;
-
-    switch ($action) {
-        /**
-         * Removes a role from the user with this course
-         */
-        case 'unassign':
-            if (has_capability('moodle/role:assign', $manager->get_context())) {
-                $role = required_param('roleid', PARAM_INT);
-                $user = required_param('user', PARAM_INT);
-                if ($confirm && $manager->unassign_role_from_user($user, $role)) {
-                    redirect($PAGE->url);
-                } else {
-                    $user = $DB->get_record('user', array('id'=>$user), '*', MUST_EXIST);
-                    $allroles = $manager->get_all_roles();
-                    $role = $allroles[$role];
-                    $yesurl = new moodle_url($PAGE->url, array('action'=>'unassign', 'roleid'=>$role->id, 'user'=>$user->id, 'confirm'=>1, 'sesskey'=>sesskey()));
-                    $message = get_string('unassignconfirm', 'role', array('user'=>fullname($user, true), 'role'=>$role->localname));
-                    $pagetitle = get_string('unassignarole', 'role', $role->localname);
-                    $pagecontent = $OUTPUT->confirm($message, $yesurl, $PAGE->url);
-                }
-                $actiontaken = true;
-            }
-            break;
-        /**
-         * Assigns a new role to a user enrolled within this course.
-         * A user must be enrolled in the course in order for this script to action
-         */
-        case 'assign':
-            $user = $DB->get_record('user', array('id'=>required_param('user', PARAM_INT)), '*', MUST_EXIST);
-            if (is_enrolled($context, $user) && has_capability('moodle/role:assign', $manager->get_context())) {
-                $mform = new enrol_users_assign_form(NULL, array('user'=>$user, 'course'=>$course, 'assignable'=>$manager->get_assignable_roles()));
-                $mform->set_data($PAGE->url->params());
-                $data = $mform->get_data();
-                if ($mform->is_cancelled() || ($data && array_key_exists($data->roleid, $manager->get_assignable_roles()) && $manager->assign_role_to_user($data->roleid, $user->id))) {
-                    redirect($PAGE->url);
-                } else {
-                    $pagetitle = get_string('assignroles', 'role');
-                }
-                $actiontaken = true;
-            }
-            break;
-        /**
-         * Removes the user from the given group
-         */
-        case 'removemember':
-            if (has_capability('moodle/course:managegroups', $manager->get_context())) {
-                $groupid = required_param('group', PARAM_INT);
-                $userid  = required_param('user', PARAM_INT);
-                $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
-                if ($confirm && $manager->remove_user_from_group($user, $groupid)) {
-                    redirect($PAGE->url);
-                } else {
-                    $group = $manager->get_group($groupid);
-                    if (!$group) {
-                        break;
-                    }
-                    $yesurl = new moodle_url($PAGE->url, array('action'=>'removemember', 'group'=>$groupid, 'user'=>$userid, 'confirm'=>1, 'sesskey'=>sesskey()));
-                    $message = get_string('removefromgroupconfirm', 'group', array('user'=>fullname($user, true), 'group'=>$group->name));
-                    $pagetitle = get_string('removefromgroup', 'group', $group->name);
-                    $pagecontent = $OUTPUT->confirm($message, $yesurl, $PAGE->url);
-                }
-                $actiontaken = true;
-            }
-            break;
-        /**
-         * Makes the user a member of a given group
-         */
-        case 'addmember':
-            if (has_capability('moodle/course:managegroups', $manager->get_context())) {
-                $userid = required_param('user', PARAM_INT);
-                $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
-
-                $mform = new enrol_users_addmember_form(NULL, array('user'=>$user, 'course'=>$course, 'allgroups'=>$manager->get_all_groups()));
-                $mform->set_data($PAGE->url->params());
-                $data = $mform->get_data();
-                if ($mform->is_cancelled()) {
-                    redirect($PAGE->url);
-                } if (!empty($data->groupids)) {
-                    foreach ($data->groupids as $groupid) {
-                        $manager->add_user_to_group($user, $groupid);
-                    }
-                    redirect($PAGE->url);
-                } else {
-                    $pagetitle = get_string('addgroup', 'group');
-                }
-                $actiontaken = true;
-            }
-            break;
-    }
-
-    // If we took an action display we need to display something special.
-    if ($actiontaken) {
-        if (empty($pageheading)) {
-            $pageheading = $pagetitle;
-        }
-        $PAGE->set_title($pagetitle);
-        $PAGE->set_heading($pageheading);
-        echo $OUTPUT->header();
-        echo $OUTPUT->heading(fullname($user));
-        if (!is_null($mform)) {
-            $mform->display();
-        } else {
-            echo $pagecontent;
-        }
-        echo $OUTPUT->footer();
-        exit;
-    }
-}
-
-
-$renderer = $PAGE->get_renderer('core_enrol');
-$userdetails = array('picture' => false, 'userfullnamedisplay' => false);
-// Get all the user names in a reasonable default order.
-$allusernames = get_all_user_name_fields(false, null, null, null, true);
-// Initialise the variable for the user's names in the table header.
-$usernameheader = null;
-// Get the alternative full name format for users with the viewfullnames capability.
-$fullusernames = $CFG->alternativefullnameformat;
-// If fullusernames is empty or accidentally set to language then fall back to default of just first and last name.
-if ($fullusernames == 'language' || empty($fullusernames)) {
-    // Set $a variables to return 'firstname' and 'lastname'.
-    $a = new stdClass();
-    $a->firstname = 'firstname';
-    $a->lastname = 'lastname';
-    // Getting the fullname display will ensure that the order in the language file is maintained.
-    $usernameheader = explode(' ', get_string('fullnamedisplay', null, $a));
-} else {
-    // If everything is as expected then put them in the order specified by the alternative full name format setting.
-    $usernameheader = order_in_string($allusernames, $fullusernames);
-}
-
-// Loop through each name and return the language string.
-foreach ($usernameheader as $key => $username) {
-    $userdetails[$username] = get_string($username);
-}
-$extrafields = get_extra_user_fields($context);
-foreach ($extrafields as $field) {
-    $userdetails[$field] = get_user_field_name($field);
-}
-
-$fields = array(
-    'userdetails' => $userdetails,
-    'lastcourseaccess' => get_string('lastcourseaccess'),
-    'role' => get_string('roles', 'role'),
-    'group' => get_string('groups', 'group'),
-    'enrol' => get_string('enrolmentinstances', 'enrol')
-);
-
-// Remove hidden fields if the user has no access
-if (!has_capability('moodle/course:viewhiddenuserfields', $context)) {
-    $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
-    if (isset($hiddenfields['lastaccess'])) {
-        unset($fields['lastcourseaccess']);
-    }
-    if (isset($hiddenfields['groups'])) {
-        unset($fields['group']);
-    }
-}
-
-$filterform = new enrol_users_filter_form('users.php', array('manager' => $manager, 'id' => $id, 'newcourse' => $newcourse),
-        'get', '', array('id' => 'filterform'));
-$filterform->set_data(array('search' => $search, 'ifilter' => $filter, 'role' => $role,
-    'filtergroup' => $fgroup, 'status' => $status));
-
-$table->set_fields($fields, $renderer);
-
-$canassign = has_capability('moodle/role:assign', $manager->get_context());
-$users = $manager->get_users_for_display($manager, $table->sort, $table->sortdirection, $table->page, $table->perpage);
-foreach ($users as $userid=>&$user) {
-    $user['picture'] = $OUTPUT->render($user['picture']);
-    $user['role'] = $renderer->user_roles_and_actions($userid, $user['roles'], $manager->get_assignable_roles(), $canassign, $PAGE->url);
-    $user['group'] = $renderer->user_groups_and_actions($userid, $user['groups'], $manager->get_all_groups(), has_capability('moodle/course:managegroups', $manager->get_context()), $PAGE->url);
-    $user['enrol'] = $renderer->user_enrolments_and_actions($user['enrolments']);
-}
-$table->set_total_users($manager->get_total_users());
-$table->set_users($users);
-
-$PAGE->set_title($PAGE->course->fullname.': '.get_string('totalenrolledusers', 'enrol', $manager->get_total_users()));
-$PAGE->set_heading($PAGE->title);
-
-echo $OUTPUT->header();
-echo $OUTPUT->heading(get_string('enrolledusers', 'enrol'));
-echo $renderer->render_course_enrolment_users_table($table, $filterform);
-if ($newcourse == 1) {
-    echo $OUTPUT->single_button(new moodle_url('/course/view.php', array('id' => $id)),
-    get_string('proceedtocourse', 'enrol'), 'GET', array('class' => 'enrol-users-page-action'));
-}
-echo $OUTPUT->footer();
index abbfe4f..20a9398 100644 (file)
@@ -43,7 +43,7 @@ Feature: Average grades are displayed in the gradebook
     And I turn editing mode off
     # Suspend a user
     And I navigate to "Enrolled users" node in "Course administration > Users"
-    And I click on "Edit" "link" in the "Student 2" "table_row"
+    And I click on "Edit enrolment" "link" in the "Student 2" "table_row"
     And I set the following fields to these values:
       | Status | Suspended |
     And I press "Save changes"
index 9917dd6..6375cf9 100644 (file)
@@ -31,6 +31,7 @@
 defined('MOODLE_INTERNAL') || die();
 
 $string['language'] = 'Γλώσσα';
+$string['moodlelogo'] = 'Λογότυπο Moodle';
 $string['next'] = 'Επόμενο';
 $string['previous'] = 'Προηγούμενο';
 $string['reload'] = 'Eπαναφόρτωση';
index 45cf7ad..e40bcf4 100644 (file)
@@ -31,4 +31,4 @@
 defined('MOODLE_INTERNAL') || die();
 
 $string['parentlanguage'] = 'es_mx';
-$string['thislanguage'] = 'Español de México para niños';
+$string['thislanguage'] = 'Español - México para niños';
index fe33c09..7ee500d 100644 (file)
@@ -44,6 +44,7 @@ $string['cannotunzipfile'] = 'فایل نمی‌تواند unzip شود';
 $string['componentisuptodate'] = 'کامپوننت به‌روز است';
 $string['dmlexceptiononinstall'] = '<p>یک خطای پایگاه داده رخ داد [{$a->errorcode}].<br />{$a->debuginfo}</p>';
 $string['downloadedfilecheckfailed'] = 'بررسی فایل دریافت‌شده ناموفق بود';
+$string['invalidmd5'] = 'متغیر بررسی نادرست بود - دوباره تلاش کنید';
 $string['missingrequiredfield'] = 'بعضی از فیلدهای ضروری خالی است';
 $string['remotedownloaderror'] = '<p>دانلود کامپوننت بر روی کارگزار شما ناموفق بود. لطفا تنظیمات پروکسی را بررسی کنید؛ افزونهٔ پی‌اچ‌پی cURL بسیار توصیه می‌شود.</p>
 <p>باید به‌صورت دستی فایل <a href="{$a->url}">{$a->url}</a> را دریافت کنید، آن را در «{$a->dest}» در کارگزار خود کپی کنید و آنجا از حالت فشرده خارج کنید.</p>';
index 72b71da..7cced02 100644 (file)
@@ -729,6 +729,7 @@ $string['eventcommentcreated'] = 'Comment created';
 $string['eventcommentdeleted'] = 'Comment deleted';
 $string['eventcommentsviewed'] = 'Comments viewed';
 $string['eventconfiglogcreated'] = 'Config log created';
+$string['eventcoursebackupcreated'] = 'Course backup created';
 $string['eventcoursecategorycreated'] = 'Category created';
 $string['eventcoursecategorydeleted'] = 'Category deleted';
 $string['eventcoursecategoryupdated'] = 'Category updated';
index 233e46e..e0e9f5d 100644 (file)
Binary files a/lib/amd/build/form-autocomplete.min.js and b/lib/amd/build/form-autocomplete.min.js differ
index 06f8a5f..efa71d9 100644 (file)
Binary files a/lib/amd/build/modal_factory.min.js and b/lib/amd/build/modal_factory.min.js differ
index 17e7adf..12f44eb 100644 (file)
@@ -687,19 +687,40 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
         });
         // Whenever the input field changes, update the suggestion list.
         if (options.showSuggestions) {
-            inputElement.on('input', function(e) {
-                var query = $(e.currentTarget).val();
-                var last = $(e.currentTarget).data('last-value');
-                // IE11 fires many more input events than required - even when the value has not changed.
-                // We need to only do this for real value changed events or the suggestions will be
-                // unclickable on IE11 (because they will be rebuilt before the click event fires).
-                // Note - because of this we cannot close the list when the query is empty or it will break
-                // on IE11.
-                if (last !== query) {
-                    updateSuggestions(options, state, query, originalSelect);
-                }
-                $(e.currentTarget).data('last-value', query);
-            });
+            // If this field uses ajax, set it up.
+            if (options.ajax) {
+                require([options.ajax], function(ajaxHandler) {
+                    var throttleTimeout = null;
+                    var handler = function(e) {
+                        updateAjax(e, options, state, originalSelect, ajaxHandler);
+                    };
+
+                    // For input events, we do not want to trigger many, many updates.
+                    var throttledHandler = function(e) {
+                        if (throttleTimeout !== null) {
+                            window.clearTimeout(throttleTimeout);
+                            throttleTimeout = null;
+                        }
+                        throttleTimeout = window.setTimeout(handler.bind(this, e), 300);
+                    };
+                    // Trigger an ajax update after the text field value changes.
+                    inputElement.on("input", throttledHandler);
+                });
+            } else {
+                inputElement.on('input', function(e) {
+                    var query = $(e.currentTarget).val();
+                    var last = $(e.currentTarget).data('last-value');
+                    // IE11 fires many more input events than required - even when the value has not changed.
+                    // We need to only do this for real value changed events or the suggestions will be
+                    // unclickable on IE11 (because they will be rebuilt before the click event fires).
+                    // Note - because of this we cannot close the list when the query is empty or it will break
+                    // on IE11.
+                    if (last !== query) {
+                        updateSuggestions(options, state, query, originalSelect);
+                    }
+                    $(e.currentTarget).data('last-value', query);
+                });
+            }
         }
     };
 
@@ -804,31 +825,10 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
                 // Add the event handlers.
                 addNavigation(options, state, originalSelect);
 
-                var inputElement = $(document.getElementById(state.inputId));
                 var suggestionsElement = $(document.getElementById(state.suggestionsId));
                 // Hide the suggestions by default.
                 suggestionsElement.hide().attr('aria-hidden', true);
 
-                // If this field uses ajax, set it up.
-                if (options.ajax) {
-                    require([options.ajax], function(ajaxHandler) {
-                        var throttleTimeout = null;
-                        var handler = function(e) {
-                            updateAjax(e, options, state, originalSelect, ajaxHandler);
-                        };
-
-                        // For input events, we do not want to trigger many, many updates.
-                        var throttledHandler = function(e) {
-                            if (throttleTimeout !== null) {
-                                window.clearTimeout(throttleTimeout);
-                                throttleTimeout = null;
-                            }
-                            throttleTimeout = window.setTimeout(handler.bind(this, e), 300);
-                        };
-                        // Trigger an ajax update after the text field value changes.
-                        inputElement.on("input", throttledHandler);
-                    });
-                }
                 // Show the current values in the selection list.
                 updateSelectionList(options, state, originalSelect);
                 return true;
index 52839b1..678bad8 100644 (file)
@@ -60,11 +60,22 @@ define(['jquery', 'core/modal_events', 'core/modal_registry', 'core/modal',
      */
     var setUpTrigger = function(modal, triggerElement) {
         if (typeof triggerElement != 'undefined') {
-            CustomEvents.define(triggerElement, [CustomEvents.events.activate]);
-            triggerElement.on(CustomEvents.events.activate, function(e, data) {
-                modal.show();
-                data.originalEvent.preventDefault();
-            });
+            if (Array.isArray(triggerElement)) {
+                var selector = triggerElement[1];
+                triggerElement = triggerElement[0];
+
+                CustomEvents.define(triggerElement, [CustomEvents.events.activate]);
+                triggerElement.on(CustomEvents.events.activate, selector, function(e, data) {
+                    modal.show();
+                    data.originalEvent.preventDefault();
+                });
+            } else {
+                CustomEvents.define(triggerElement, [CustomEvents.events.activate]);
+                triggerElement.on(CustomEvents.events.activate, function(e, data) {
+                    modal.show();
+                    data.originalEvent.preventDefault();
+                });
+            }
 
             modal.getRoot().on(ModalEvents.hidden, function() {
                 triggerElement.focus();
index 657f887..4af4bcb 100644 (file)
@@ -651,10 +651,10 @@ class auth_plugin_base {
         $data = [];
         foreach ($identityproviders as $idp) {
             if (!empty($idp['icon'])) {
-                // Pre-3.3 auth plugins provide icon as a pix_icon instance.
+                // Pre-3.3 auth plugins provide icon as a pix_icon instance. New auth plugins (since 3.3) provide iconurl.
                 $idp['iconurl'] = $output->image_url($idp['icon']->pix, $idp['icon']->component);
-            } else if ($idp['iconurl'] instanceof moodle_url) {
-                // New auth plugins (since 3.3) provide iconurl.
+            }
+            if ($idp['iconurl'] instanceof moodle_url) {
                 $idp['iconurl'] = $idp['iconurl']->out(false);
             }
             unset($idp['icon']);
index 58f043a..56f213c 100644 (file)
@@ -74,7 +74,7 @@ class no_teaching extends \core_analytics\local\target\binary {
             $url, $pix, get_string('view'));
 
         if (has_capability('moodle/course:enrolreview', $sampledata['context'])) {
-            $url = new \moodle_url('/enrol/users.php', array('id' => $course->id));
+            $url = new \moodle_url('/user/index.php', array('id' => $course->id));
             $pix = new \pix_icon('i/enrolusers', get_string('enrolledusers', 'enrol'));
             $actions['enrolusers'] = new \core_analytics\prediction_action('enrolusers', $prediction,
                 $url, $pix, get_string('enrolledusers', 'enrol'));
diff --git a/lib/classes/event/course_backup_created.php b/lib/classes/event/course_backup_created.php
new file mode 100644 (file)
index 0000000..46f810e
--- /dev/null
@@ -0,0 +1,118 @@
+<?php
+// 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/>.
+
+/**
+ * Course backup created event.
+ *
+ * @package    core
+ * @copyright  2017 Stephen Bourget
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace core\event;
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Course backup created event class.
+ *
+ * @property-read array $other {
+ *      Extra information about event.
+ *
+ *      - string format: Format of backup (moodle, imscc)
+ *      - int mode: execution mode.
+ *      - boolean interactive: Interactive mode (yes/no)
+ *      - string type: backup type
+ * }
+ *
+ * @package    core
+ * @since      Moodle 3.4
+ * @copyright  2017 Stephen Bourget
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class course_backup_created extends base {
+
+    /**
+     * Initialise the event data.
+     */
+    protected function init() {
+        $this->data['objecttable'] = 'course';
+        $this->data['crud'] = 'c';
+        $this->data['edulevel'] = self::LEVEL_TEACHING;
+    }
+
+    /**
+     * Returns localised general event name.
+     *
+     * @return string
+     */
+    public static function get_name() {
+        return get_string('eventcoursebackupcreated');
+    }
+
+    /**
+     * Returns non-localised description of what happened.
+     *
+     * @return string
+     */
+    public function get_description() {
+        return "The user with id '$this->userid' created a backup of the course with the id '$this->objectid'.";
+    }
+
+    /**
+     * Returns relevant URL.
+     *
+     * @return \moodle_url
+     */
+    public function get_url() {
+        return new \moodle_url('/course/view.php', array('id' => $this->objectid));
+    }
+
+    /**
+     * Custom validation.
+     *
+     * @throws \coding_exception
+     * @return void
+     */
+    protected function validate_data() {
+        parent::validate_data();
+
+        if (!isset($this->other['format'])) {
+            throw new \coding_exception('The \'format\' value must be set in other.');
+        }
+
+        if (!isset($this->other['mode'])) {
+            throw new \coding_exception('The \'mode\' value must be set in other.');
+        }
+
+        if (!isset($this->other['interactive'])) {
+            throw new \coding_exception('The \'interactive\' value must be set in other.');
+        }
+
+        if (!isset($this->other['type'])) {
+            throw new \coding_exception('The \'type\' value must be set in other.');
+        }
+    }
+
+    public static function get_objectid_mapping() {
+        return array('db' => 'course', 'restore' => 'course');
+    }
+
+    public static function get_other_mapping() {
+        // No need to map anything.
+        return false;
+    }
+}
index 384015a..2b76706 100644 (file)
@@ -75,7 +75,7 @@ class user_enrolment_created extends base {
      * @return \moodle_url
      */
     public function get_url() {
-        return new \moodle_url('/enrol/users.php', array('id' => $this->courseid));
+        return new \moodle_url('/user/index.php', array('id' => $this->courseid));
     }
 
     /**
index d872ec2..b343fbc 100644 (file)
@@ -76,7 +76,7 @@ class user_enrolment_deleted extends base {
      * @return \moodle_url
      */
     public function get_url() {
-        return new \moodle_url('/enrol/users.php', array('id' => $this->courseid));
+        return new \moodle_url('/user/index.php', array('id' => $this->courseid));
     }
 
     /**
index 909b7fa..e37d54e 100644 (file)
@@ -58,6 +58,16 @@ $functions = array(
         'capabilities'  => 'moodle/badges:viewotherbadges',
         'services'      => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
     ),
+    'core_calendar_get_calendar_monthly_view' => array(
+        'classname' => 'core_calendar_external',
+        'methodname' => 'get_calendar_monthly_view',
+        'description' => 'Fetch the monthly view data for a calendar',
+        'classpath' => 'calendar/externallib.php',
+        'type' => 'read',
+        'capabilities' => '',
+        'ajax' => true,
+        'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
+    ),
     'core_calendar_create_calendar_events' => array(
         'classname' => 'core_calendar_external',
         'methodname' => 'create_calendar_events',
index 7f81f17..a498039 100644 (file)
@@ -436,7 +436,7 @@ function enrol_add_course_navigation(navigation_node $coursenode, $course) {
     if ($course->id != SITEID) {
         // list all participants - allows assigning roles, groups, etc.
         if (has_capability('moodle/course:enrolreview', $coursecontext)) {
-            $url = new moodle_url('/enrol/users.php', array('id'=>$course->id));
+            $url = new moodle_url('/user/index.php', array('id'=>$course->id));
             $usersnode->add(get_string('enrolledusers', 'enrol'), $url, navigation_node::TYPE_SETTING, null, 'review', new pix_icon('i/enrolusers', ''));
         }
 
@@ -2873,7 +2873,7 @@ abstract class enrol_plugin {
         $a->course    = format_string($course->fullname, true, array('context'=>$context));
         $a->threshold = get_string('numdays', '', $instance->expirythreshold / (60*60*24));
         $a->users     = implode("\n", $users);
-        $a->extendurl = (string)new moodle_url('/enrol/users.php', array('id'=>$instance->courseid));
+        $a->extendurl = (string)new moodle_url('/user/index.php', array('id'=>$instance->courseid));
 
         $subject = get_string('expirymessageenrollersubject', 'enrol_'.$name, $a);
         $body = get_string('expirymessageenrollerbody', 'enrol_'.$name, $a);
index 692188e..e40f457 100644 (file)
@@ -43,15 +43,28 @@ class MoodleQuickForm_submit extends HTML_QuickForm_submit implements templatabl
         export_for_template as export_for_template_base;
     }
 
+    /**
+     * @var bool $primary Is this button a primary button?
+     */
+    protected $primary;
+
     /**
      * constructor
      *
      * @param string $elementName (optional) name of the field
      * @param string $value (optional) field label
      * @param string $attributes (optional) Either a typical HTML attribute string or an associative array
+     * @param bool|null $primary Is this button a primary button?
      */
-    public function __construct($elementName=null, $value=null, $attributes=null) {
+    public function __construct($elementName=null, $value=null, $attributes=null, $primary = null) {
         parent::__construct($elementName, $value, $attributes);
+
+        // Fallback to legacy behaviour if no value specified.
+        if (is_null($primary)) {
+            $this->primary = $this->getName() != 'cancel';
+        } else {
+            $this->primary = $primary;
+        }
     }
 
     /**
@@ -59,9 +72,9 @@ class MoodleQuickForm_submit extends HTML_QuickForm_submit implements templatabl
      *
      * @deprecated since Moodle 3.1
      */
-    public function MoodleQuickForm_submit($elementName=null, $value=null, $attributes=null) {
+    public function MoodleQuickForm_submit($elementName=null, $value=null, $attributes=null, $primary = null) {
         debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
-        self::__construct($elementName, $value, $attributes);
+        self::__construct($elementName, $value, $attributes, $primary);
     }
 
     /**
@@ -115,7 +128,7 @@ class MoodleQuickForm_submit extends HTML_QuickForm_submit implements templatabl
 
     public function export_for_template(renderer_base $output) {
         $context = $this->export_for_template_base($output);
-        if ($this->getName() == 'cancel') {
+        if (!$this->primary) {
             $context['secondary'] = true;
         }
         return $context;
index 33b011c..217fc4a 100644 (file)
Binary files a/lib/form/yui/build/moodle-form-dateselector/moodle-form-dateselector-debug.js and b/lib/form/yui/build/moodle-form-dateselector/moodle-form-dateselector-debug.js differ
index 2b4e22a..ca09d67 100644 (file)
Binary files a/lib/form/yui/build/moodle-form-dateselector/moodle-form-dateselector-min.js and b/lib/form/yui/build/moodle-form-dateselector/moodle-form-dateselector-min.js differ
index 33b011c..217fc4a 100644 (file)
Binary files a/lib/form/yui/build/moodle-form-dateselector/moodle-form-dateselector.js and b/lib/form/yui/build/moodle-form-dateselector/moodle-form-dateselector.js differ
index 278e352..bf84531 100644 (file)
@@ -67,7 +67,8 @@ M.form.dateselector = {
         this.panel = new Y.Overlay({
             visible: false,
             bodyContent: Y.Node.create('<div id="dateselector-calendar-content"></div>'),
-            id: 'dateselector-calendar-panel'
+            id: 'dateselector-calendar-panel',
+            constrain: true // constrain panel to viewport.
         });
         this.panel.render(document.body);
         // zIndex is added by panel.render() and is set to 0.
@@ -129,7 +130,6 @@ M.form.dateselector = {
                 ];
             }
 
-
             this.panel.set('align', {
                 node: this.currentowner.get('node').one('select'),
                 points: alignpoints
index f918112..87fd236 100644 (file)
@@ -524,7 +524,7 @@ abstract class oauth2_client extends curl {
     public function build_post_data($params) {
         $result = [];
         foreach ($params as $name => $value) {
-            $result[] = str_replace('&', '%26', $name) . '=' . str_replace('&', '%26', $value);
+            $result[] = urlencode($name) . '=' . urlencode($value);
         }
         return implode('&', $result);
     }
diff --git a/lib/templates/single_button.mustache b/lib/templates/single_button.mustache
new file mode 100644 (file)
index 0000000..9eca305
--- /dev/null
@@ -0,0 +1,61 @@
+{{!
+    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 core/single_button
+
+    Moodle template for a single button submit form.
+
+    Classes required for JS:
+    * none
+
+    Data attributes required for JS:
+    * none
+
+    Context variables required for this template:
+    * classes - a list of classes to wrap the form.
+    * method - get or post
+    * url - the action url to submit to
+    * formid - optional id value for the form
+    * params - array of params with name and value attributes
+    * primary - true if this is a primary action button
+    * id - id for the element
+    * tooltip - tooltip text for the button
+    * disabled - true if this element is disabled
+    * label - text to show on the button
+
+    Example context (json):
+    { "method" : "get",
+      "url" : "#",
+      "primary" : true,
+      "tooltip" : "This is a tooltip",
+      "label" : "This is a the button text"
+    }
+}}
+<div class="{{classes}}">
+    <form method="{{method}}" action="{{url}}" {{#formid}}id="{{formid}}"{{/formid}}>
+        {{#params}}
+            <input type="hidden" name="{{name}}" value="{{value}}">
+        {{/params}}
+        <button type="submit" class="btn {{#primary}}btn-primary{{/primary}}{{^primary}}btn-default{{/primary}}"
+            id="{{id}}"
+            title={{#quote}}{{tooltip}}{{/quote}}
+            {{#disabled}}disabled{{/disabled}}>{{label}}</button>
+    </form>
+</div>
+{{#hasactions}}
+    {{> core/actions }}
+{{/hasactions}}
index 10eaa29..0cea44c 100644 (file)
@@ -2215,7 +2215,7 @@ function send_headers($contenttype, $cacheable = true) {
  * @param string $addclass Additional class names for the link, or the arrow character.
  * @return string HTML string.
  */
-function link_arrow_right($text, $url='', $accesshide=false, $addclass='') {
+function link_arrow_right($text, $url='', $accesshide=false, $addclass='', $addparams = []) {
     global $OUTPUT; // TODO: move to output renderer.
     $arrowclass = 'arrow ';
     if (!$url) {
@@ -2234,7 +2234,16 @@ function link_arrow_right($text, $url='', $accesshide=false, $addclass='') {
         if ($addclass) {
             $class .= ' '.$addclass;
         }
-        return '<a class="'.$class.'" href="'.$url.'" title="'.preg_replace('/<.*?>/', '', $text).'">'.$htmltext.$arrow.'</a>';
+
+        $linkparams = [
+            'class' => $class,
+            'href' => $url,
+            'title' => preg_replace('/<.*?>/', '', $text),
+        ];
+
+        $linkparams += $addparams;
+
+        return html_writer::link($url, $htmltext . $arrow, $linkparams);
     }
     return $htmltext.$arrow;
 }
@@ -2248,7 +2257,7 @@ function link_arrow_right($text, $url='', $accesshide=false, $addclass='') {
  * @param string $addclass Additional class names for the link, or the arrow character.
  * @return string HTML string.
  */
-function link_arrow_left($text, $url='', $accesshide=false, $addclass='') {
+function link_arrow_left($text, $url='', $accesshide=false, $addclass='', $addparams = []) {
     global $OUTPUT; // TODO: move to utput renderer.
     $arrowclass = 'arrow ';
     if (! $url) {
@@ -2267,7 +2276,16 @@ function link_arrow_left($text, $url='', $accesshide=false, $addclass='') {
         if ($addclass) {
             $class .= ' '.$addclass;
         }
-        return '<a class="'.$class.'" href="'.$url.'" title="'.preg_replace('/<.*?>/', '', $text).'">'.$arrow.$htmltext.'</a>';
+
+        $linkparams = [
+            'class' => $class,
+            'href' => $url,
+            'title' => preg_replace('/<.*?>/', '', $text),
+        ];
+
+        $linkparams += $addparams;
+
+        return html_writer::link($url, $arrow . $htmltext, $linkparams);
     }
     return $arrow.$htmltext;
 }
index 268cd70..f0ad1b9 100644 (file)
@@ -149,7 +149,6 @@ foreach ($chapters as $ch) {
     $last = $ch->id;
 }
 
-$islastchapter = false;
 if ($book->navstyle) {
     $navprevicon = right_to_left() ? 'nav_next' : 'nav_prev';
     $navnexticon = right_to_left() ? 'nav_prev' : 'nav_next';
@@ -196,11 +195,15 @@ if ($book->navstyle) {
             $chnavigation .= ' <a title="' . $navexit . '" class="bookexit"  href="'.$returnurl.'">' .
                 '<span class="chaptername">' . $navexit . '&nbsp;' . $OUTPUT->uarrow() . '</span></a>';
         }
-
-        $islastchapter = true;
     }
 }
 
+// We need to discover if this is the last chapter to mark activity as completed.
+$islastchapter = false;
+if (!$nextid) {
+    $islastchapter = true;
+}
+
 book_view($book, $chapter, $islastchapter, $course, $cm, $context);
 
 // =====================================================
index bccea71..2366e45 100644 (file)
@@ -373,7 +373,8 @@ if (has_capability('mod/forum:pindiscussions', $modcontext)) {
 echo "</div></div>";
 
 if (forum_discussion_is_locked($forum, $discussion)) {
-    echo html_writer::div(get_string('discussionlocked', 'forum'), 'discussionlocked');
+    echo $OUTPUT->notification(get_string('discussionlocked', 'forum'),
+        \core\output\notification::NOTIFY_INFO . ' discussionlocked');
 }
 
 if (!empty($forum->blockafter) && !empty($forum->blockperiod)) {
index 5043840..6a53182 100644 (file)
@@ -92,10 +92,10 @@ function report_log_can_access_user_report($user, $course) {
     $today = false;
     $all = false;
 
-    if (has_capability('report/log:view', $coursecontext)) {
+    if (has_capability('report/log:viewtoday', $coursecontext)) {
         $today = true;
     }
-    if (has_capability('report/log:viewtoday', $coursecontext)) {
+    if (has_capability('report/log:view', $coursecontext)) {
         $all = true;
     }
 
index 3a3de07..47632cd 100644 (file)
@@ -11,7 +11,7 @@ $calendarEventUserColor: #dce7ec !default; // Pale blue.
     background-color: $calendarEventCourseColor;
 }
 
-.calendar_event_global {
+.calendar_event_site {
     background-color: $calendarEventGlobalColor;
 }
 
@@ -119,7 +119,7 @@ $calendarEventUserColor: #dce7ec !default; // Pale blue.
         }
 
         .calendar_event_course,
-        .calendar_event_global,
+        .calendar_event_site,
         .calendar_event_group,
         .calendar_event_user {
             border-width: 1px 1px 1px 12px;
@@ -130,7 +130,7 @@ $calendarEventUserColor: #dce7ec !default; // Pale blue.
             border-color: $calendarEventCourseColor;
         }
 
-        .calendar_event_global {
+        .calendar_event_site {
             border-color: $calendarEventGlobalColor;
         }
 
index 5a4aad2..15d05d2 100644 (file)
@@ -4,9 +4,26 @@
 
 // Add support for card. We map it to well.
 // This is not meant to be perfect - but at least applies some styles to a bs4 card.
-.card:extend(.well) {
+.card {
+    position: relative;
+    display: block;
+    margin-bottom: .75rem;
+    background-color: #fff;
+    border: 1px solid @wellBorder;
+    border-radius: 0;
 }
 
+.card-header {
+    padding: .75rem 1.25rem;
+    background-color: @wellBackground;
+    border-bottom: 1px solid @wellBorder;
+}
+
+.card-block {
+    padding: 1.25rem;
+}
+
+
 // Due to lessphp limitations, the following classes must be declared statically without use of a loop.
 .p-l-1 {
     padding-left: 1 * @baseFontSize !important;
index cbb29dc..59fdeb9 100644 (file)
@@ -10,7 +10,7 @@
 .calendar_event_course {
     background-color: @calendarEventCourseColor;
 }
-.calendar_event_global {
+.calendar_event_site {
     background-color: @calendarEventGlobalColor;
 }
 .calendar_event_group {
             margin: 10px auto;
         }
         .calendar_event_course,
-        .calendar_event_global,
+        .calendar_event_site,
         .calendar_event_group,
         .calendar_event_user {
             border-width: 1px 1px 1px 12px;
         .calendar_event_course {
             border-color: @calendarEventCourseColor;
         }
-        .calendar_event_global {
+        .calendar_event_site {
             border-color: @calendarEventGlobalColor;
         }
         .calendar_event_group {
                 }
                 .description {
                     background-color: @white;
-                    padding: 5px;
                     clear: both;
                 }
                 .commands {
index 066dc47..0772ef9 100644 (file)
@@ -5542,7 +5542,7 @@ img.iconsmall {
 .calendar_event_course {
   background-color: #ffd3bd;
 }
-.calendar_event_global {
+.calendar_event_site {
   background-color: #d6f8cd;
 }
 .calendar_event_group {
@@ -5630,7 +5630,7 @@ img.iconsmall {
   margin: 10px auto;
 }
 .path-calendar .maincalendar .calendar_event_course,
-.path-calendar .maincalendar .calendar_event_global,
+.path-calendar .maincalendar .calendar_event_site,
 .path-calendar .maincalendar .calendar_event_group,
 .path-calendar .maincalendar .calendar_event_user {
   border-width: 1px 1px 1px 12px;
@@ -5639,7 +5639,7 @@ img.iconsmall {
 .path-calendar .maincalendar .calendar_event_course {
   border-color: #ffd3bd;
 }
-.path-calendar .maincalendar .calendar_event_global {
+.path-calendar .maincalendar .calendar_event_site {
   border-color: #d6f8cd;
 }
 .path-calendar .maincalendar .calendar_event_group {
@@ -5708,7 +5708,6 @@ img.iconsmall {
 }
 .path-calendar .maincalendar .eventlist .event .description {
   background-color: #fff;
-  padding: 5px;
   clear: both;
 }
 .path-calendar .maincalendar .eventlist .event .commands a {
@@ -12929,8 +12928,7 @@ table th[class*="span"],
   -moz-border-radius: 4px;
   border-radius: 4px;
 }
-.well,
-.card {
+.well {
   min-height: 20px;
   padding: 19px;
   margin-bottom: 20px;
@@ -15631,8 +15629,7 @@ legend {
 .breadcrumb {
   background-color: #f5f5f5;
 }
-.well,
-.card {
+.well {
   border-color: #e3e3e3;
 }
 sup {
@@ -21614,6 +21611,22 @@ ul.indented-list {
   margin-left: 20px;
 }
 /* stylelint-disable declaration-no-important, block-no-empty */
+.card {
+  position: relative;
+  display: block;
+  margin-bottom: .75rem;
+  background-color: #fff;
+  border: 1px solid #e3e3e3;
+  border-radius: 0;
+}
+.card-header {
+  padding: .75rem 1.25rem;
+  background-color: #f5f5f5;
+  border-bottom: 1px solid #e3e3e3;
+}
+.card-block {
+  padding: 1.25rem;
+}
 .p-l-1 {
   padding-left: 14px !important;
 }
index f6bcb03..45ea47e 100644 (file)
@@ -22,6 +22,9 @@
 
     Example context (json):
     {
+         "urls": {
+            "noevents": "#"
+        }
     }
 }}
 <div data-region="event-list-container"
@@ -93,7 +96,7 @@
              alt="{{#str}} noevents, block_myoverview {{/str}}"
              role="presentation">
         <p class="text-muted m-t-1">{{#str}} noevents, block_myoverview {{/str}}</p>
-        <a href="{{viewurl}}" class="btn btn-secondary text-primary"
+        <a href="{{viewurl}}" class="btn"
            aria-label="{{#str}} viewcoursename, block_myoverview, {{fullnamedisplay}} {{/str}}">
             {{#str}} viewcourse, block_myoverview {{/str}}
         </a>
index e799799..e6c99b2 100644 (file)
@@ -29,7 +29,7 @@
 <div class="course-info-container" id="course-info-container-{{id}}">
     <div class="visible-desktop">
         {{> block_myoverview/progress-chart}}
-        <h4><a href="{{viewurl}}">{{fullnamedisplay}}</a></h4>
+        <h4><a href="{{viewurl}}" class="{{^visible}}dimmed{{/visible}}">{{fullnamedisplay}}</a></h4>
     </div>
     <div class="hidden-desktop">
         <div class="media">
@@ -39,7 +39,7 @@
                 </div>
             </div>
             <div class="media-body">
-                <h4 class="media-heading"><a href="{{viewurl}}">{{fullnamedisplay}}</a></h4>
+                <h4 class="media-heading"><a href="{{viewurl}}" class="{{^visible}}dimmed{{/visible}}">{{fullnamedisplay}}</a></h4>
             </div>
         </div>
     </div>
index ba7c132..d4c448a 100644 (file)
@@ -35,7 +35,7 @@
                 </div>
             </div>
             <div class="media-body">
-                <h4 class="media-heading"><a href="{{viewurl}}">{{fullnamedisplay}}</a></h4>
+                <h4 class="media-heading"><a href="{{viewurl}}" class="{{^visible}}dimmed{{/visible}}">{{fullnamedisplay}}</a></h4>
             </div>
         </div>
         <p class="text-muted">
index ea0b365..565c8dd 100644 (file)
Binary files a/user/amd/build/status_field.min.js and b/user/amd/build/status_field.min.js differ
index e57b7e9..3e1303b 100644 (file)
@@ -201,12 +201,37 @@ define(['core/templates',
                     "timeend": parentContainer.data('timeend')
                 };
 
-                var modalTitlePromise = Str.get_string('enroldetails', 'enrol');
+                // Get default string for the modal and modal type.
+                var strings = [
+                    {
+                        key: 'enroldetails',
+                        component: 'enrol'
+                    }
+                ];
+
+                // Find the edit enrolment link.
+                var editEnrolLink = detailsButton.next(SELECTORS.EDIT_ENROLMENT);
+                if (editEnrolLink.length) {
+                    // If there's an edit enrolment link for this user, clone it into the context for the modal.
+                    context.editenrollink = $('<div>').append(editEnrolLink.clone()).html();
+                }
+
+                var modalStringsPromise = Str.get_strings(strings);
                 var modalPromise = ModalFactory.create({large: true, type: ModalFactory.types.CANCEL});
-                $.when(modalTitlePromise, modalPromise).done(function(modalTitle, modal) {
+                $.when(modalStringsPromise, modalPromise).done(function(strings, modal) {
                     var modalBodyPromise = Template.render('core_user/status_details', context);
-                    modal.setTitle(modalTitle);
+                    modal.setTitle(strings[0]);
                     modal.setBody(modalBodyPromise);
+
+                    if (editEnrolLink.length) {
+                        modal.getRoot().on('click', SELECTORS.EDIT_ENROLMENT, function(e) {
+                            e.preventDefault();
+                            modal.hide();
+                            // Trigger click event for the edit enrolment link to show the edit enrolment modal.
+                            $(editEnrolLink).trigger('click');
+                        });
+                    }
+
                     modal.show();
 
                     // Handle hidden event.
@@ -320,4 +345,4 @@ define(['core/templates',
                 (new StatusFieldActions(config));
             }
         };
-    });
\ No newline at end of file
+    });
index 079f1cb..120e44e 100644 (file)
@@ -61,7 +61,7 @@
             {{#str}}enrolmentmethod, enrol{{/str}}
         </th>
         <td class="user-enrol-instance">
-            {{enrolinstancename}}
+            {{enrolinstancename}} {{{editenrollink}}}
         </td>
     </tr>
     <tr>
index eaeb4be..1fe2b52 100644 (file)
@@ -24,11 +24,11 @@ Feature: Edit user enrolment
     Given I log in as "teacher1"
     And I am on "Course 1" course homepage
     And I navigate to course participants
-    When I click on "//a[@data-action='editenrolment']" "xpath_element" in the "student1" "table_row"
+    When I click on "Edit enrolment" "icon" in the "student1" "table_row"
     And I should see "Edit Student 1's enrolment"
     And I set the field "Status" to "Suspended"
     And I click on "Save changes" "button"
-    And I click on "//a[@data-action='editenrolment']" "xpath_element" in the "student2" "table_row"
+    And I click on "Edit enrolment" "icon" in the "student2" "table_row"
     And I should see "Edit Student 2's enrolment"
     And I set the field "timeend[enabled]" to "1"
     And I set the field "timeend[day]" to "1"
@@ -44,7 +44,7 @@ Feature: Edit user enrolment
     Given I log in as "teacher1"
     And I am on "Course 1" course homepage
     And I navigate to course participants
-    When I click on "//a[@data-action='unenrol']" "xpath_element" in the "student1" "table_row"
+    When I click on "Unenrol" "icon" in the "student1" "table_row"
     And I click on "Yes" "button"
     Then I should not see "Student 1" in the "participants" "table"
 
@@ -53,26 +53,72 @@ Feature: Edit user enrolment
     Given I log in as "teacher1"
     And I am on "Course 1" course homepage
     And I navigate to course participants
-    When I click on "//a[@data-action='showdetails']" "xpath_element" in the "student1" "table_row"
+    When I click on "Enrolment details" "icon" in the "student1" "table_row"
     Then I should see "Enrolment details"
     And I should see "Student 1" in the "Full name" "table_row"
     And I should see "Active" in the "//td[@class='user-enrol-status']" "xpath_element"
+    And I should see "Manual enrolments" in the "Enrolment method" "table_row"
     And I press "Cancel"
-    And I click on "//a[@data-action='showdetails']" "xpath_element" in the "student2" "table_row"
+    And I click on "Enrolment details" "icon" in the "student2" "table_row"
     And I should see "Enrolment details"
     And I should see "Student 2" in the "Full name" "table_row"
     And I should see "Suspended" in the "//td[@class='user-enrol-status']" "xpath_element"
+    And I should see "Manual enrolments" in the "Enrolment method" "table_row"
+    And "Edit enrolment" "icon" should exist in the "Enrolment method" "table_row"
+
+  @javascript
+  Scenario: View a student's enrolment details for a student enrolled via course meta link where editing can't be done
+    Given the following "users" exist:
+      | username  | firstname | lastname | email                 |
+      | student3  | Student   | 3        | student3@example.com  |
+    And the following "courses" exist:
+      | fullname | shortname | format |
+      | Course 2 | C2        | topics |
+    And the following "course enrolments" exist:
+      | user      | course | role           | status |
+      | student3  | C2     | student        |    0   |
+    And I log in as "admin"
+    And I navigate to "Manage enrol plugins" node in "Site administration > Plugins > Enrolments"
+    And I click on "Enable" "link" in the "Course meta link" "table_row"
+    And I am on "Course 1" course homepage
+    And I add "Course meta link" enrolment method with:
+      | Link course  | C2      |
+    And I log out
+    And I log in as "teacher1"
+    And I am on "Course 1" course homepage
+    When I navigate to course participants
+    Then I should see "Student 3" in the "participants" "table"
+    And "Edit enrolment" "icon" should not exist in the "student3" "table_row"
+    And "Unenrol" "icon" should not exist in the "student3" "table_row"
+    And I click on "Enrolment details" "icon" in the "student3" "table_row"
+    And I should see "Enrolment details"
+    And I should see "Student 3" in the "Full name" "table_row"
+    And I should see "Active" in the "//td[@class='user-enrol-status']" "xpath_element"
+    And I should see "Course meta link (Course 2)" in the "Enrolment method" "table_row"
+    And "Edit enrolment" "icon" should not exist in the "Enrolment method" "table_row"
+
+  @javascript
+  Scenario: Edit a student's enrolment details from the status dialogue
+    Given I log in as "teacher1"
+    And I am on "Course 1" course homepage
+    And I navigate to course participants
+    When I click on "Enrolment details" "icon" in the "student2" "table_row"
+    And I click on "Edit enrolment" "icon" in the "Enrolment method" "table_row"
+    And I should see "Edit Student 2's enrolment"
+    And I set the field "Status" to "Active"
+    And I click on "Save changes" "button"
+    Then I should see "Active" in the "student2" "table_row"
 
   # Without JS, the user should be redirected to the original edit enrolment form.
   Scenario: Edit a user's enrolment without JavaScript
     Given I log in as "teacher1"
     And I am on "Course 1" course homepage
     And I navigate to course participants
-    When I click on "//a[@data-action='editenrolment']" "xpath_element" in the "student1" "table_row"
+    When I click on "Edit enrolment" "link" in the "student1" "table_row"
     And I should see "Student 1"
     And I set the field "Status" to "Suspended"
     And I click on "Save changes" "button"
-    And I click on "//a[@data-action='editenrolment']" "xpath_element" in the "student2" "table_row"
+    And I click on "Edit enrolment" "link" in the "student2" "table_row"
     And I should see "Student 2"
     And I set the field "timeend[enabled]" to "1"
     And I set the field "timeend[day]" to "1"
@@ -88,6 +134,6 @@ Feature: Edit user enrolment
     Given I log in as "teacher1"
     And I am on "Course 1" course homepage
     And I navigate to course participants
-    When I click on "//a[@data-action='unenrol']" "xpath_element" in the "student1" "table_row"
+    When I click on "Unenrol" "link" in the "student1" "table_row"
     And I click on "Continue" "button"
     Then I should not see "Student 1" in the "participants" "table"
index 945c926..6c1203d 100644 (file)
 
 defined('MOODLE_INTERNAL') || die();
 
-$version  = 2017081000.00;              // YYYYMMDD      = weekly release date of this DEV branch.
+$version  = 2017081700.00;              // YYYYMMDD      = weekly release date of this DEV branch.
                                         //         RR    = release increments - 00 in DEV branches.
                                         //           .XX = incremental changes.
 
-$release  = '3.4dev (Build: 20170810)'; // Human-friendly version name
+$release  = '3.4dev (Build: 20170817)'; // Human-friendly version name
 
 $branch   = '34';                       // This version's branch.
 $maturity = MATURITY_ALPHA;             // This version's maturity level.