Commit 430746d3 authored by ilya's avatar ilya
Browse files

MDL-66431 core: Remove activity chooser user preference.

This commit removes activity chooser user preference and
course preference page. Separate dropdowns to activity and
resource is also removed.
parent 0a986fdf
......@@ -269,7 +269,6 @@ preferences,moodle|/user/preferences.php|t/preferences',
$setting = new admin_setting_configcheckbox('cachejs', new lang_string('cachejs', 'admin'), new lang_string('cachejs_help', 'admin'), 1);
$setting->set_updatedcallback('js_reset_all_caches');
$temp->add($setting);
$temp->add(new admin_setting_configcheckbox('modchooserdefault', new lang_string('modchooserdefault', 'admin'), new lang_string('configmodchooserdefault', 'admin'), 1));
$ADMIN->add('appearance', $temp);
// Link to tag management interface.
......
......@@ -272,100 +272,21 @@ class core_course_renderer extends plugin_renderer_base {
* @return string
*/
function course_section_add_cm_control($course, $section, $sectionreturn = null, $displayoptions = array()) {
global $CFG, $USER;
// The returned control HTML can be one of the following:
// - Only the non-ajax control (select menus of activities and resources) with a noscript fallback for non js clients.
// Please note that non-ajax control has been deprecated and it will be removed in the future.
// - Only the ajax control (the link which when clicked produces the activity chooser modal). No noscript fallback.
// - [Behat only]: The non-ajax control and optionally the ajax control (depending on site settings). If included, the link
// takes priority and the non-ajax control is wrapped in a <noscript>.
// Behat requires the third case because some features run with JS, some do not. We must include the noscript fallback.
$behatsite = defined('BEHAT_SITE_RUNNING');
$nonajaxcontrol = '';
$ajaxcontrol = '';
$courseajaxenabled = course_ajax_enabled($course);
$userchooserenabled = get_user_preferences('usemodchooser', $CFG->modchooserdefault);
// Decide what combination of controls to output:
// During behat runs, both controls can be used in conjunction to provide non-js fallback.
// During normal use only one control or the other will be output. No non-js fallback is needed.
$rendernonajaxcontrol = $behatsite || !$courseajaxenabled || !$userchooserenabled || $course->id != $this->page->course->id;
$renderajaxcontrol = $courseajaxenabled && $userchooserenabled && $course->id == $this->page->course->id;
$courseajaxenabled = course_ajax_enabled($course);
// The non-ajax control, which includes an entirely non-js (<noscript>) fallback too.
// Non ajax control is under deprecated, $rendernonajaxcontrol will be removed in later versions.
$rendernonajaxcontrol = !$courseajaxenabled || $course->id != $this->page->course->id;
if ($rendernonajaxcontrol) {
$vertical = !empty($displayoptions['inblock']);
// Check to see if user can add menus.
if (!has_capability('moodle/course:manageactivities', context_course::instance($course->id))
|| !$this->page->user_is_editing()) {
return '';
}
// Retrieve all modules with associated metadata.
$contentitemservice = \core_course\local\factory\content_item_service_factory::get_content_item_service();
$urlparams = ['section' => $section];
if (!is_null($sectionreturn)) {
$urlparams['sr'] = $sectionreturn;
}
$modules = $contentitemservice->get_content_items_for_user_in_course($USER, $course, $urlparams);
// Return if there are no content items to add.
if (empty($modules)) {
return '';
}
// We'll sort resources and activities into two lists.
$activities = array(MOD_CLASS_ACTIVITY => array(), MOD_CLASS_RESOURCE => array());
foreach ($modules as $module) {
$activityclass = MOD_CLASS_ACTIVITY;
if ($module->archetype == MOD_ARCHETYPE_RESOURCE) {
$activityclass = MOD_CLASS_RESOURCE;
} else if ($module->archetype === MOD_ARCHETYPE_SYSTEM) {
// System modules cannot be added by user, do not add to dropdown.
continue;
}
$link = $module->link;
$activities[$activityclass][$link] = $module->title;
}
$straddactivity = get_string('addactivity');
$straddresource = get_string('addresource');
$sectionname = get_section_name($course, $section);
$strresourcelabel = get_string('addresourcetosection', null, $sectionname);
$stractivitylabel = get_string('addactivitytosection', null, $sectionname);
$nonajaxcontrol = html_writer::start_tag('div', array('class' => 'section_add_menus', 'id' => 'add_menus-section-'
. $section));
if (!$vertical) {
$nonajaxcontrol .= html_writer::start_tag('div', array('class' => 'horizontal'));
}
if (!empty($activities[MOD_CLASS_RESOURCE])) {
$select = new url_select($activities[MOD_CLASS_RESOURCE], '', array('' => $straddresource), "ressection$section");
$select->set_help_icon('resources');
$select->set_label($strresourcelabel, array('class' => 'accesshide'));
$nonajaxcontrol .= $this->output->render($select);
}
if (!empty($activities[MOD_CLASS_ACTIVITY])) {
$select = new url_select($activities[MOD_CLASS_ACTIVITY], '', array('' => $straddactivity), "section$section");
$select->set_help_icon('activities');
$select->set_label($stractivitylabel, array('class' => 'accesshide'));
$nonajaxcontrol .= $this->output->render($select);
}
if (!$vertical) {
$nonajaxcontrol .= html_writer::end_tag('div');
}
$nonajaxcontrol .= html_writer::end_tag('div');
}
// The ajax control - the 'Add an activity or resource' link.
if ($renderajaxcontrol) {
// The non-ajax control, which includes an entirely non-js (<noscript>) fallback too.
return $this->course_section_add_cm_control_nonajax($course, $section, $sectionreturn, $displayoptions);
} else {
// The ajax control - the 'Add an activity or resource' link.
// The module chooser link.
$straddeither = get_string('addresourceoractivity');
$ajaxcontrol = html_writer::start_tag('div', array('class' => 'mdl-right'));
......@@ -384,18 +305,100 @@ class core_course_renderer extends plugin_renderer_base {
// Load the JS for the modal.
$this->course_activitychooser($course->id);
return $ajaxcontrol;
}
}
/**
* Render the deprecated nonajax activity chooser.
*
* @deprecated since Moodle 3.11
*
* @todo MDL-71331 deprecate this function
* @param stdClass $course the course object
* @param int $section relative section number (field course_sections.section)
* @param int $sectionreturn The section to link back to
* @param array $displayoptions additional display options, for example blocks add
* option 'inblock' => true, suggesting to display controls vertically
* @return string
*/
private function course_section_add_cm_control_nonajax($course, $section, $sectionreturn = null,
$displayoptions = array()): string {
global $USER;
$vertical = !empty($displayoptions['inblock']);
// Check to see if user can add menus.
if (
!has_capability('moodle/course:manageactivities', context_course::instance($course->id))
|| !$this->page->user_is_editing()
) {
return '';
}
debugging('non-js dropdowns are deprecated.', DEBUG_DEVELOPER);
// Retrieve all modules with associated metadata.
$contentitemservice = \core_course\local\factory\content_item_service_factory::get_content_item_service();
$urlparams = ['section' => $section];
if (!is_null($sectionreturn)) {
$urlparams['sr'] = $sectionreturn;
}
$modules = $contentitemservice->get_content_items_for_user_in_course($USER, $course, $urlparams);
// Behat only: If both controls are being included in the HTML,
// show the link by default and only fall back to the selects if js is disabled.
if ($behatsite && $renderajaxcontrol) {
$nonajaxcontrol = html_writer::tag('div', $nonajaxcontrol, array('class' => 'hiddenifjs addresourcedropdown'));
$ajaxcontrol = html_writer::tag('div', $ajaxcontrol, array('class' => 'visibleifjs addresourcemodchooser'));
// Return if there are no content items to add.
if (empty($modules)) {
return '';
}
// If behat is running, we should have the non-ajax control + the ajax control.
// Otherwise, we'll have one or the other.
return $ajaxcontrol . $nonajaxcontrol;
// We'll sort resources and activities into two lists.
$activities = array(MOD_CLASS_ACTIVITY => array(), MOD_CLASS_RESOURCE => array());
foreach ($modules as $module) {
$activityclass = MOD_CLASS_ACTIVITY;
if ($module->archetype == MOD_ARCHETYPE_RESOURCE) {
$activityclass = MOD_CLASS_RESOURCE;
} else if ($module->archetype === MOD_ARCHETYPE_SYSTEM) {
// System modules cannot be added by user, do not add to dropdown.
continue;
}
$link = $module->link;
$activities[$activityclass][$link] = $module->title;
}
$straddactivity = get_string('addactivity');
$straddresource = get_string('addresource');
$sectionname = get_section_name($course, $section);
$strresourcelabel = get_string('addresourcetosection', null, $sectionname);
$stractivitylabel = get_string('addactivitytosection', null, $sectionname);
$nonajaxcontrol = html_writer::start_tag('div', array('class' => 'section_add_menus', 'id' => 'add_menus-section-'
. $section));
if (!$vertical) {
$nonajaxcontrol .= html_writer::start_tag('div', array('class' => 'horizontal'));
}
if (!empty($activities[MOD_CLASS_RESOURCE])) {
$select = new url_select($activities[MOD_CLASS_RESOURCE], '', array('' => $straddresource), "ressection$section");
$select->set_help_icon('resources');
$select->set_label($strresourcelabel, array('class' => 'accesshide'));
$nonajaxcontrol .= $this->output->render($select);
}
if (!empty($activities[MOD_CLASS_ACTIVITY])) {
$select = new url_select($activities[MOD_CLASS_ACTIVITY], '', array('' => $straddactivity), "section$section");
$select->set_help_icon('activities');
$select->set_label($stractivitylabel, array('class' => 'accesshide'));
$nonajaxcontrol .= $this->output->render($select);
}
if (!$vertical) {
$nonajaxcontrol .= html_writer::end_tag('div');
}
$nonajaxcontrol .= html_writer::end_tag('div');
return $nonajaxcontrol;
}
/**
......
......@@ -55,6 +55,7 @@ renderer and course format renderer:
- Given the activity date information in "<ActivityName>" should exist
- activity_dates_information_in_activity_should_not_exist()
- Given the activity date information in "<ActivityName>" should not exist
* A user preference usemodchooser has been removed and the activities/resources (non-ajax) activity chooser has been deprecated and will be removed in the future.
=== 3.10 ===
......
......@@ -149,7 +149,6 @@ $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['configallowattachments'] = 'If enabled, emails sent from the site can have attachments, such as badges.';
$string['configenableactivitychooser'] = 'The activity chooser is a dialog box with a short description of each activity and resource. If disabled, separate resource and activity drop-down 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['configallowcategorythemes'] = 'If you enable this, then themes can be set at the category level. This will affect all child categories and courses unless they have specifically set their own theme. WARNING: Enabling category themes may affect performance.';
......@@ -297,7 +296,6 @@ $string['configminpasswordlength'] = 'Passwords must be at least these many char
$string['configminpasswordlower'] = 'Passwords must have at least these many lower case letters.';
$string['configminpasswordnonalphanum'] = 'Passwords must have at least these many non-alphanumeric characters.';
$string['configminpasswordupper'] = 'Passwords must have at least these many upper case letters.';
$string['configmodchooserdefault'] = 'Should the activity chooser be presented to users by default?';
$string['configmycoursesperpage'] = 'Maximum number of courses to display in any list of a user\'s own courses';
$string['configmymoodleredirect'] = 'This setting forces redirects to /my on login for non-admins and replaces the top level site navigation with /my';
$string['configmypagelocked'] = 'This setting prevents the default page from being edited by any non-admins';
......@@ -554,7 +552,6 @@ $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['enableanalytics'] = 'Analytics';
$string['enableblogs'] = 'Enable blogs';
$string['enablecalendarexport'] = 'Enable calendar export';
......@@ -853,7 +850,6 @@ $string['mnetrestore_extusers_mismatch'] = '<strong>Note:</strong> This backup f
$string['mnetrestore_extusers_noadmin'] = '<strong>Note:</strong> This backup file seems to come from a different Moodle installation and contains remote Moodle Network user accounts. You are not allowed to execute this type of restore. Contact the administrator of the site or, alternatively, restore this course without any user information (modules, files...)';
$string['mnetrestore_extusers_switchuserauth'] = 'Remote Moodle Network user {$a->username} (coming from {$a->mnethosturl}) switched to local {$a->auth} authenticated user.';
$string['mobilenotconfiguredwarning'] = 'The Moodle app is not enabled.';
$string['modchooserdefault'] = 'Activity chooser default';
$string['modeditdefaults'] = 'Default values for activity settings';
$string['modsettings'] = 'Manage activities';
$string['modulesecurity'] = 'Module security';
......@@ -1533,3 +1529,9 @@ $string['requestcategoryselection'] = 'Enable category selection';
// Deprecated since Moodle 3.9.
$string['availablelicenses'] = 'Available licences';
$string['managelicenses'] = 'Manage licences';
// Deprecated since Moodle 3.11.
$string['configenableactivitychooser'] = 'The activity chooser is a dialog box with a short description of each activity and resource. If disabled, separate resource and activity drop-down menus are provided instead.';
$string['enableactivitychooser'] = 'Enable activity chooser';
$string['configmodchooserdefault'] = 'Should the activity chooser be presented to users by default?';
$string['modchooserdefault'] = 'Activity chooser default';
......@@ -150,3 +150,6 @@ aimid,core
yahooid,core
icqnumber,core
msnid,core
configenableactivitychooser,core_admin
enableactivitychooser,core_admin
coursepreferences,core
......@@ -345,7 +345,6 @@ $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.';
......@@ -2324,3 +2323,4 @@ $string['yahooid'] = 'Yahoo ID';
$string['skypeid'] = 'Skype ID';
$string['icqnumber'] = 'ICQ number';
$string['msnid'] = 'MSN ID';
$string['coursepreferences'] = 'Course preferences';
......@@ -947,8 +947,6 @@ class core_user {
return ($USER->id != $user->id && (has_capability('moodle/user:update', $systemcontext) ||
($user->timecreated > time() - 10 && has_capability('moodle/user:create', $systemcontext))));
});
$preferences['usemodchooser'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'default' => 1,
'choices' => array(0, 1));
$preferences['forum_markasreadonnotification'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'default' => 1,
'choices' => array(0, 1));
$preferences['htmleditor'] = array('type' => PARAM_NOTAGS, 'null' => NULL_ALLOWED,
......
......@@ -2642,5 +2642,13 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2021052500.87);
}
if ($oldversion < 2021052500.90) {
// Remove usemodchooser user preference for every user.
$DB->delete_records('user_preferences', ['name' => 'usemodchooser']);
// Main savepoint reached.
upgrade_main_savepoint(true, 2021052500.90);
}
return true;
}
......@@ -5087,15 +5087,6 @@ 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');
}
}
// Add "Calendar preferences" link.
if (isloggedin() && !isguestuser($user)) {
if ($currentuser && has_capability('moodle/user:editownprofile', $systemcontext) ||
......
<?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'));
}
}
\ No newline at end of file
<?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()) {
useredit_update_user_preference(['id' => $user->id,
'preference_usemodchooser' => $data->enableactivitychooser]);
redirect($redirect, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS);
}
// 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();
......@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2021052500.89; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2021052500.90; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.0dev (Build: 20210430)'; // Human-friendly version name
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment