mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
Merge branch 'wip-MDL-53399' of https://github.com/JoeyAndres/moodle
This commit is contained in:
commit
c6d20e61e3
@ -58,7 +58,6 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
public function __construct(moodle_page $page, $target) {
|
||||
$this->strings = new stdClass;
|
||||
parent::__construct($page, $target);
|
||||
$this->add_modchoosertoggle();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,8 +65,12 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
*
|
||||
* Theme can overwrite as an empty function to exclude it (for example if theme does not
|
||||
* use modchooser at all)
|
||||
*
|
||||
* @deprecated since 3.2
|
||||
*/
|
||||
protected function add_modchoosertoggle() {
|
||||
debugging('core_course_renderer::add_modchoosertoggle() is deprecated.', DEBUG_DEVELOPER);
|
||||
|
||||
global $CFG;
|
||||
|
||||
// Only needs to be done once per page.
|
||||
@ -182,9 +185,7 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
array(array('courseid' => $course->id, 'closeButtonTitle' => get_string('close', 'editor')))
|
||||
);
|
||||
$this->page->requires->strings_for_js(array(
|
||||
'addresourceoractivity',
|
||||
'modchooserenable',
|
||||
'modchooserdisable',
|
||||
'addresourceoractivity'
|
||||
), 'moodle');
|
||||
|
||||
// Add the header
|
||||
@ -406,9 +407,6 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
/**
|
||||
* Renders HTML for the menus to add activities and resources to the current course
|
||||
*
|
||||
* Note, if theme overwrites this function and it does not use modchooser,
|
||||
* see also {@link core_course_renderer::add_modchoosertoggle()}
|
||||
*
|
||||
* @param stdClass $course
|
||||
* @param int $section relative section number (field course_sections.section)
|
||||
* @param int $sectionreturn The section to link back to
|
||||
|
@ -17,7 +17,6 @@
|
||||
$move = optional_param('move', 0, PARAM_INT);
|
||||
$marker = optional_param('marker',-1 , PARAM_INT);
|
||||
$switchrole = optional_param('switchrole',-1, PARAM_INT); // Deprecated, use course/switchrole.php instead.
|
||||
$modchooser = optional_param('modchooser', -1, PARAM_BOOL);
|
||||
$return = optional_param('return', 0, PARAM_LOCALURL);
|
||||
|
||||
$params = array();
|
||||
@ -178,11 +177,6 @@
|
||||
redirect($PAGE->url);
|
||||
}
|
||||
}
|
||||
if (($modchooser == 1) && confirm_sesskey()) {
|
||||
set_user_preference('usemodchooser', $modchooser);
|
||||
} else if (($modchooser == 0) && confirm_sesskey()) {
|
||||
set_user_preference('usemodchooser', $modchooser);
|
||||
}
|
||||
|
||||
if (has_capability('moodle/course:sectionvisibility', $context)) {
|
||||
if ($hide && confirm_sesskey()) {
|
||||
|
@ -56,9 +56,6 @@ Y.extend(MODCHOOSER, M.core.chooserdialogue, {
|
||||
// Initialize existing sections and register for dynamically created sections
|
||||
this.setup_for_section();
|
||||
M.course.coursebase.register_module(this);
|
||||
|
||||
// Catch the page toggle
|
||||
Y.all('.block_settings #settingsnav .type_course .modchoosertoggle a').on('click', this.toggle_mod_chooser, this);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -132,62 +129,6 @@ Y.extend(MODCHOOSER, M.core.chooserdialogue, {
|
||||
this.display_chooser(e);
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggle availability of the activity chooser.
|
||||
*
|
||||
* @method toggle_mod_chooser
|
||||
* @param {EventFacade} e
|
||||
*/
|
||||
toggle_mod_chooser : function(e) {
|
||||
// Get the add section link
|
||||
var modchooserlinks = Y.all('div.addresourcemodchooser');
|
||||
|
||||
// Get the dropdowns
|
||||
var dropdowns = Y.all('div.addresourcedropdown');
|
||||
|
||||
if (modchooserlinks.size() === 0) {
|
||||
// Continue with non-js action if there are no modchoosers to add
|
||||
return;
|
||||
}
|
||||
|
||||
// We need to update the text and link
|
||||
var togglelink = Y.one('.block_settings #settingsnav .type_course .modchoosertoggle a');
|
||||
|
||||
// The actual text is in the last child
|
||||
var toggletext = togglelink.get('lastChild');
|
||||
|
||||
var usemodchooser;
|
||||
// Determine whether they're currently hidden
|
||||
if (modchooserlinks.item(0).hasClass('visibleifjs')) {
|
||||
// The modchooser is currently visible, hide it
|
||||
usemodchooser = 0;
|
||||
modchooserlinks
|
||||
.removeClass('visibleifjs')
|
||||
.addClass('hiddenifjs');
|
||||
dropdowns
|
||||
.addClass('visibleifjs')
|
||||
.removeClass('hiddenifjs');
|
||||
toggletext.set('data', M.util.get_string('modchooserenable', 'moodle'));
|
||||
togglelink.set('href', togglelink.get('href').replace('off', 'on'));
|
||||
} else {
|
||||
// The modchooser is currently not visible, show it
|
||||
usemodchooser = 1;
|
||||
modchooserlinks
|
||||
.addClass('visibleifjs')
|
||||
.removeClass('hiddenifjs');
|
||||
dropdowns
|
||||
.removeClass('visibleifjs')
|
||||
.addClass('hiddenifjs');
|
||||
toggletext.set('data', M.util.get_string('modchooserdisable', 'moodle'));
|
||||
togglelink.set('href', togglelink.get('href').replace('on', 'off'));
|
||||
}
|
||||
|
||||
M.util.set_user_preference('usemodchooser', usemodchooser);
|
||||
|
||||
// Prevent the page from reloading
|
||||
e.preventDefault();
|
||||
},
|
||||
|
||||
/**
|
||||
* Helper function to set the value of a hidden radio button when a
|
||||
* selection is made.
|
||||
|
@ -1 +1 @@
|
||||
YUI.add("moodle-course-modchooser",function(e,t){var n={PAGECONTENT:"body",SECTION:null,SECTIONMODCHOOSER:"span.section-modchooser-link",SITEMENU:"div.block_site_main_menu",SITETOPIC:"div.sitetopic"},r="course-modchooser",i=function(){i.superclass.constructor.apply(this,arguments)};e.extend(i,M.core.chooserdialogue,{sectionid:null,initializer:function(){var t=M.course.format.get_sectionwrapperclass();t&&(n.SECTION="."+t);var r=e.one(".chooserdialoguebody"),i=e.one(".choosertitle"),s={};this.setup_chooser_dialogue(r,i,s),this.setup_for_section(),M.course.coursebase.register_module(this),e.all(".block_settings #settingsnav .type_course .modchoosertoggle a").on("click",this.toggle_mod_chooser,this)},setup_for_section:function(t){t||(t=n.PAGECONTENT),e.one(t).all(n.SITETOPIC).each(function(e){this._setup_for_section(e)},this),n.SECTION&&e.one(t).all(n.SECTION).each(function(e){this._setup_for_section(e)},this),e.one(t).all(n.SITEMENU).each(function(e){this._setup_for_section(e)},this)},_setup_for_section:function(t){var r=t.one(n.SECTIONMODCHOOSER);if(!r)return;var i=e.Node.create("<a href='#' />");r.get("children").each(function(e){i.appendChild(e)}),r.insertBefore(i),i.on("click",this.display_mod_chooser,this)},display_mod_chooser:function(e){if(e.target.ancestor(n.SITETOPIC))this.sectionid=1;else if(e.target.ancestor(n.SECTION)){var t=e.target.ancestor(n.SECTION);this.sectionid=t.get("id").replace("section-","")}else e.target.ancestor(n.SITEMENU)&&(this.sectionid=0);this.display_chooser(e)},toggle_mod_chooser:function(t){var n=e.all("div.addresourcemodchooser"),r=e.all("div.addresourcedropdown");if(n.size()===0)return;var i=e.one(".block_settings #settingsnav .type_course .modchoosertoggle a"),s=i.get("lastChild"),o;n.item(0).hasClass("visibleifjs")?(o=0,n.removeClass("visibleifjs").addClass("hiddenifjs"),r.addClass("visibleifjs").removeClass("hiddenifjs"),s.set("data",M.util.get_string("modchooserenable","moodle")),i.set("href",i.get("href").replace("off","on"))):(o=1,n.addClass("visibleifjs").removeClass("hiddenifjs"),r.removeClass("visibleifjs").addClass("hiddenifjs"),s.set("data",M.util.get_string("modchooserdisable","moodle")),i.set("href",i.get("href").replace("on","off"))),M.util.set_user_preference("usemodchooser",o),t.preventDefault()},option_selected:function(e){this.hiddenRadioValue.setAttrs({name:"jump",value:e.get("value")+"§ion="+this.sectionid})}},{NAME:r,ATTRS:{maxheight:{value:800}}}),M.course=M.course||{},M.course.init_chooser=function(e){return new i(e)}},"@VERSION@",{requires:["moodle-core-chooserdialogue","moodle-course-coursebase"]});
|
||||
YUI.add("moodle-course-modchooser",function(e,t){var n={PAGECONTENT:"body",SECTION:null,SECTIONMODCHOOSER:"span.section-modchooser-link",SITEMENU:"div.block_site_main_menu",SITETOPIC:"div.sitetopic"},r="course-modchooser",i=function(){i.superclass.constructor.apply(this,arguments)};e.extend(i,M.core.chooserdialogue,{sectionid:null,initializer:function(){var t=M.course.format.get_sectionwrapperclass();t&&(n.SECTION="."+t);var r=e.one(".chooserdialoguebody"),i=e.one(".choosertitle"),s={};this.setup_chooser_dialogue(r,i,s),this.setup_for_section(),M.course.coursebase.register_module(this)},setup_for_section:function(t){t||(t=n.PAGECONTENT),e.one(t).all(n.SITETOPIC).each(function(e){this._setup_for_section(e)},this),n.SECTION&&e.one(t).all(n.SECTION).each(function(e){this._setup_for_section(e)},this),e.one(t).all(n.SITEMENU).each(function(e){this._setup_for_section(e)},this)},_setup_for_section:function(t){var r=t.one(n.SECTIONMODCHOOSER);if(!r)return;var i=e.Node.create("<a href='#' />");r.get("children").each(function(e){i.appendChild(e)}),r.insertBefore(i),i.on("click",this.display_mod_chooser,this)},display_mod_chooser:function(e){if(e.target.ancestor(n.SITETOPIC))this.sectionid=1;else if(e.target.ancestor(n.SECTION)){var t=e.target.ancestor(n.SECTION);this.sectionid=t.get("id").replace("section-","")}else e.target.ancestor(n.SITEMENU)&&(this.sectionid=0);this.display_chooser(e)},option_selected:function(e){this.hiddenRadioValue.setAttrs({name:"jump",value:e.get("value")+"§ion="+this.sectionid})}},{NAME:r,ATTRS:{maxheight:{value:800}}}),M.course=M.course||{},M.course.init_chooser=function(e){return new i(e)}},"@VERSION@",{requires:["moodle-core-chooserdialogue","moodle-course-coursebase"]});
|
||||
|
@ -56,9 +56,6 @@ Y.extend(MODCHOOSER, M.core.chooserdialogue, {
|
||||
// Initialize existing sections and register for dynamically created sections
|
||||
this.setup_for_section();
|
||||
M.course.coursebase.register_module(this);
|
||||
|
||||
// Catch the page toggle
|
||||
Y.all('.block_settings #settingsnav .type_course .modchoosertoggle a').on('click', this.toggle_mod_chooser, this);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -132,62 +129,6 @@ Y.extend(MODCHOOSER, M.core.chooserdialogue, {
|
||||
this.display_chooser(e);
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggle availability of the activity chooser.
|
||||
*
|
||||
* @method toggle_mod_chooser
|
||||
* @param {EventFacade} e
|
||||
*/
|
||||
toggle_mod_chooser : function(e) {
|
||||
// Get the add section link
|
||||
var modchooserlinks = Y.all('div.addresourcemodchooser');
|
||||
|
||||
// Get the dropdowns
|
||||
var dropdowns = Y.all('div.addresourcedropdown');
|
||||
|
||||
if (modchooserlinks.size() === 0) {
|
||||
// Continue with non-js action if there are no modchoosers to add
|
||||
return;
|
||||
}
|
||||
|
||||
// We need to update the text and link
|
||||
var togglelink = Y.one('.block_settings #settingsnav .type_course .modchoosertoggle a');
|
||||
|
||||
// The actual text is in the last child
|
||||
var toggletext = togglelink.get('lastChild');
|
||||
|
||||
var usemodchooser;
|
||||
// Determine whether they're currently hidden
|
||||
if (modchooserlinks.item(0).hasClass('visibleifjs')) {
|
||||
// The modchooser is currently visible, hide it
|
||||
usemodchooser = 0;
|
||||
modchooserlinks
|
||||
.removeClass('visibleifjs')
|
||||
.addClass('hiddenifjs');
|
||||
dropdowns
|
||||
.addClass('visibleifjs')
|
||||
.removeClass('hiddenifjs');
|
||||
toggletext.set('data', M.util.get_string('modchooserenable', 'moodle'));
|
||||
togglelink.set('href', togglelink.get('href').replace('off', 'on'));
|
||||
} else {
|
||||
// The modchooser is currently not visible, show it
|
||||
usemodchooser = 1;
|
||||
modchooserlinks
|
||||
.addClass('visibleifjs')
|
||||
.removeClass('hiddenifjs');
|
||||
dropdowns
|
||||
.removeClass('visibleifjs')
|
||||
.addClass('hiddenifjs');
|
||||
toggletext.set('data', M.util.get_string('modchooserdisable', 'moodle'));
|
||||
togglelink.set('href', togglelink.get('href').replace('on', 'off'));
|
||||
}
|
||||
|
||||
M.util.set_user_preference('usemodchooser', usemodchooser);
|
||||
|
||||
// Prevent the page from reloading
|
||||
e.preventDefault();
|
||||
},
|
||||
|
||||
/**
|
||||
* Helper function to set the value of a hidden radio button when a
|
||||
* selection is made.
|
||||
|
59
course/yui/src/modchooser/js/modchooser.js
vendored
59
course/yui/src/modchooser/js/modchooser.js
vendored
@ -54,9 +54,6 @@ Y.extend(MODCHOOSER, M.core.chooserdialogue, {
|
||||
// Initialize existing sections and register for dynamically created sections
|
||||
this.setup_for_section();
|
||||
M.course.coursebase.register_module(this);
|
||||
|
||||
// Catch the page toggle
|
||||
Y.all('.block_settings #settingsnav .type_course .modchoosertoggle a').on('click', this.toggle_mod_chooser, this);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -130,62 +127,6 @@ Y.extend(MODCHOOSER, M.core.chooserdialogue, {
|
||||
this.display_chooser(e);
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggle availability of the activity chooser.
|
||||
*
|
||||
* @method toggle_mod_chooser
|
||||
* @param {EventFacade} e
|
||||
*/
|
||||
toggle_mod_chooser : function(e) {
|
||||
// Get the add section link
|
||||
var modchooserlinks = Y.all('div.addresourcemodchooser');
|
||||
|
||||
// Get the dropdowns
|
||||
var dropdowns = Y.all('div.addresourcedropdown');
|
||||
|
||||
if (modchooserlinks.size() === 0) {
|
||||
// Continue with non-js action if there are no modchoosers to add
|
||||
return;
|
||||
}
|
||||
|
||||
// We need to update the text and link
|
||||
var togglelink = Y.one('.block_settings #settingsnav .type_course .modchoosertoggle a');
|
||||
|
||||
// The actual text is in the last child
|
||||
var toggletext = togglelink.get('lastChild');
|
||||
|
||||
var usemodchooser;
|
||||
// Determine whether they're currently hidden
|
||||
if (modchooserlinks.item(0).hasClass('visibleifjs')) {
|
||||
// The modchooser is currently visible, hide it
|
||||
usemodchooser = 0;
|
||||
modchooserlinks
|
||||
.removeClass('visibleifjs')
|
||||
.addClass('hiddenifjs');
|
||||
dropdowns
|
||||
.addClass('visibleifjs')
|
||||
.removeClass('hiddenifjs');
|
||||
toggletext.set('data', M.util.get_string('modchooserenable', 'moodle'));
|
||||
togglelink.set('href', togglelink.get('href').replace('off', 'on'));
|
||||
} else {
|
||||
// The modchooser is currently not visible, show it
|
||||
usemodchooser = 1;
|
||||
modchooserlinks
|
||||
.addClass('visibleifjs')
|
||||
.removeClass('hiddenifjs');
|
||||
dropdowns
|
||||
.removeClass('visibleifjs')
|
||||
.addClass('hiddenifjs');
|
||||
toggletext.set('data', M.util.get_string('modchooserdisable', 'moodle'));
|
||||
togglelink.set('href', togglelink.get('href').replace('on', 'off'));
|
||||
}
|
||||
|
||||
M.util.set_user_preference('usemodchooser', usemodchooser);
|
||||
|
||||
// Prevent the page from reloading
|
||||
e.preventDefault();
|
||||
},
|
||||
|
||||
/**
|
||||
* Helper function to set the value of a hidden radio button when a
|
||||
* selection is made.
|
||||
|
@ -126,6 +126,7 @@ $string['componentinstalled'] = 'Component installed';
|
||||
$string['computedfromlogs'] = 'Computed from logs since {$a}.';
|
||||
$string['condifmodeditdefaults'] = 'Default values are used in the settings form when creating a new activity or resource.';
|
||||
$string['confeditorhidebuttons'] = 'Select the buttons that should be hidden in the HTML editor.';
|
||||
$string['configenableactivitychooser'] = 'The activity chooser is a dialog box with a short description of each activity and resource. If disabled, separate resource and activity dropdown menus are provided instead.';
|
||||
$string['configallcountrycodes'] = 'This is the list of countries that may be selected in various places, for example in a user\'s profile. If blank (the default) the list in countries.php in the standard English language pack is used. That is the list from ISO 3166-1. Otherwise, you can specify a comma-separated list of codes, for example \'GB,FR,ES\'. If you add new, non-standard codes here, you will need to add them to countries.php in \'en\' and your language pack.';
|
||||
$string['configallowassign'] = 'You can allow people who have the roles on the left side to assign some of the column roles to other people';
|
||||
$string['configallowblockstodock'] = 'If enabled and supported by the selected theme users can choose to move blocks to a special dock.';
|
||||
@ -458,6 +459,7 @@ $string['emoticons_desc'] = 'This form defines the emoticons (or smileys) used a
|
||||
* Alternative text (optional) - String identifier and component of the alternative text of the emoticon.';
|
||||
$string['emoticonsreset'] = 'Reset emoticons setting to default values';
|
||||
$string['emptysettingvalue'] = 'Empty';
|
||||
$string['enableactivitychooser'] = 'Enable activity chooser';
|
||||
$string['enableblogs'] = 'Enable blogs';
|
||||
$string['enablecalendarexport'] = 'Enable calendar export';
|
||||
$string['enablecomments'] = 'Enable comments';
|
||||
|
@ -29,10 +29,12 @@ manageofficialtags,core_tag
|
||||
settypeofficial,core_tag
|
||||
filetoolarge,core
|
||||
maxbytesforfile,core
|
||||
modchooserenable,core
|
||||
modchooserdisable,core
|
||||
maxbytes,core_error
|
||||
downloadcsv,core_table
|
||||
downloadexcel,core_table
|
||||
downloadods,core_table
|
||||
downloadoptions,core_table
|
||||
downloadtsv,core_table
|
||||
downloadxhtml,core_table
|
||||
downloadxhtml,core_table
|
@ -322,6 +322,7 @@ $string['courseformats'] = 'Course formats';
|
||||
$string['courseformatoptions'] = 'Formatting options for {$a}';
|
||||
$string['courseformatudpate'] = 'Update format';
|
||||
$string['courseprofiles'] = 'Course profiles';
|
||||
$string['coursepreferences'] = 'Course preferences';
|
||||
$string['coursegrades'] = 'Course grades';
|
||||
$string['coursehelpcategory'] = 'Position the course on the course listing and may make it easier for students to find it.';
|
||||
$string['coursehelpforce'] = 'Force the course group mode to every activity in the course.';
|
||||
@ -1161,8 +1162,6 @@ $string['moodlelogo'] = 'Moodle logo';
|
||||
$string['month'] = 'Month';
|
||||
$string['months'] = 'Months';
|
||||
$string['modified'] = 'Modified';
|
||||
$string['modchooserenable'] = 'Activity chooser on';
|
||||
$string['modchooserdisable'] = 'Activity chooser off';
|
||||
$string['moduleintro'] = 'Description';
|
||||
$string['modulesetup'] = 'Setting up module tables';
|
||||
$string['modulesuccess'] = '{$a} tables have been set up correctly';
|
||||
@ -2027,3 +2026,7 @@ $string['zippingbackup'] = 'Zipping backup';
|
||||
// Deprecated since Moodle 3.1.
|
||||
$string['filetoolarge'] = 'is too large to upload';
|
||||
$string['maxbytesforfile'] = 'The file {$a} is larger than the maximum size allowed.';
|
||||
|
||||
// Deprecated since Moodle 3.2.
|
||||
$string['modchooserenable'] = 'Activity chooser on';
|
||||
$string['modchooserdisable'] = 'Activity chooser off';
|
@ -4453,6 +4453,15 @@ class settings_navigation extends navigation_node {
|
||||
}
|
||||
}
|
||||
|
||||
// Add "Course preferences" link.
|
||||
if (isloggedin() && !isguestuser($user)) {
|
||||
if ($currentuser && has_capability('moodle/user:editownprofile', $systemcontext) ||
|
||||
has_capability('moodle/user:editprofile', $usercontext)) {
|
||||
$url = new moodle_url('/user/course.php', array('id' => $user->id, 'course' => $course->id));
|
||||
$useraccount->add(get_string('coursepreferences'), $url, self::TYPE_SETTING, null, 'coursepreferences');
|
||||
}
|
||||
}
|
||||
|
||||
// View the roles settings.
|
||||
if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override',
|
||||
'moodle/role:manage'), $usercontext)) {
|
||||
|
67
user/classes/course_form.php
Normal file
67
user/classes/course_form.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Form to edit a users course preferences.
|
||||
*
|
||||
* These are stored as columns in the user table, which
|
||||
* is why they are in /user and not /course or /admin.
|
||||
*
|
||||
* @copyright 2016 Joey Andres <jandres@ualberta.ca>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @package core_user
|
||||
*/
|
||||
|
||||
namespace core_user;
|
||||
|
||||
if (!defined('MOODLE_INTERNAL')) {
|
||||
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
|
||||
}
|
||||
|
||||
require_once($CFG->dirroot.'/lib/formslib.php');
|
||||
|
||||
/**
|
||||
* Class user_course_form.
|
||||
*
|
||||
* @copyright 2016 Joey Andres <jandres@ualberta.ca>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class course_form extends \moodleform {
|
||||
|
||||
/**
|
||||
* Define the form.
|
||||
*/
|
||||
public function definition () {
|
||||
global $COURSE;
|
||||
|
||||
$mform = $this->_form;
|
||||
|
||||
$mform->addElement('advcheckbox',
|
||||
'enableactivitychooser',
|
||||
get_string('enableactivitychooser', 'admin'),
|
||||
get_string('configenableactivitychooser', 'admin'));
|
||||
$mform->setDefault('enableactivitychooser',
|
||||
get_user_preferences('usemodchooser', true, $this->_customdata['userid']));
|
||||
|
||||
// Add some extra hidden fields.
|
||||
$mform->addElement('hidden', 'id');
|
||||
$mform->setType('id', PARAM_INT);
|
||||
$mform->addElement('hidden', 'course', $COURSE->id);
|
||||
$mform->setType('course', PARAM_INT);
|
||||
|
||||
$this->add_action_buttons(true, get_string('savechanges'));
|
||||
}
|
||||
}
|
65
user/course.php
Normal file
65
user/course.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Allows you to edit course preference.
|
||||
*
|
||||
* @copyright 2016 Joey Andres <jandres@ualberta.ca>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @package core_user
|
||||
*/
|
||||
|
||||
require_once(__DIR__ . "/../config.php");
|
||||
require_once($CFG->dirroot.'/user/editlib.php');
|
||||
|
||||
$userid = optional_param('id', $USER->id, PARAM_INT); // User id.
|
||||
$courseid = optional_param('course', SITEID, PARAM_INT); // Course id (defaults to Site).
|
||||
|
||||
$PAGE->set_url('/user/course.php', array('id' => $userid, 'course' => $courseid));
|
||||
|
||||
list($user, $course) = useredit_setup_preference_page($userid, $courseid);
|
||||
|
||||
// Create form.
|
||||
$courseform = new core_user\course_form(null, array('userid' => $user->id));
|
||||
|
||||
$courseform->set_data($user);
|
||||
|
||||
$redirect = new moodle_url("/user/preferences.php", array('userid' => $user->id));
|
||||
if ($courseform->is_cancelled()) {
|
||||
redirect($redirect);
|
||||
} else if ($data = $courseform->get_data()) {
|
||||
set_user_preference('usemodchooser', $data->enableactivitychooser, $user);
|
||||
|
||||
redirect($redirect);
|
||||
}
|
||||
|
||||
// Display page header.
|
||||
$streditmycourse = get_string('coursepreferences');
|
||||
$userfullname = fullname($user, true);
|
||||
|
||||
$PAGE->navbar->includesettingsbase = true;
|
||||
|
||||
$PAGE->set_title("$course->shortname: $streditmycourse");
|
||||
$PAGE->set_heading($userfullname);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($streditmycourse);
|
||||
|
||||
// Finally display THE form.
|
||||
$courseform->display();
|
||||
|
||||
// And proper footer.
|
||||
echo $OUTPUT->footer();
|
36
user/tests/behat/course_preference.feature
Normal file
36
user/tests/behat/course_preference.feature
Normal file
@ -0,0 +1,36 @@
|
||||
@core @core_user
|
||||
Feature: As a user, "Course preferences" allows me to set my course preference(s).
|
||||
Background:
|
||||
Given I log in as "admin"
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname | format |
|
||||
| Course 1 | C1 | topics |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| admin | C1 | editingteacher |
|
||||
And I am on site homepage
|
||||
And I follow "Preferences" in the user menu
|
||||
And I follow "Course preferences"
|
||||
|
||||
@javascript
|
||||
Scenario: As a user, "activity chooser" should be the default.
|
||||
# See that the "activity chooser" is enabled by default.
|
||||
Given the field "enableactivitychooser" matches value "1"
|
||||
# See that the "activity chooser" is actually shown by default in course page.
|
||||
When I am on homepage
|
||||
And I follow "Course 1"
|
||||
And I should not see "Add an activity or resource" in the "Topic 1" "section"
|
||||
And I turn editing mode on
|
||||
Then I should see "Add an activity or resource" in the "Topic 1" "section"
|
||||
And I should not see "Add a resource..." in the "Topic 1" "section"
|
||||
|
||||
@javascript
|
||||
Scenario: As a user, "activity chooser" should be disabled when I uncheck it in "Course preferences"
|
||||
Given I set the field "enableactivitychooser" to "0"
|
||||
And I press "Save changes"
|
||||
When I am on homepage
|
||||
And I follow "Course 1"
|
||||
And I should not see "Add a resource..." in the "Topic 1" "section"
|
||||
And I turn editing mode on
|
||||
Then I should see "Add a resource..." in the "Topic 1" "section"
|
||||
And I should not see "Add an activity or resource" in the "Topic 1" "section"
|
Loading…
x
Reference in New Issue
Block a user