Skip to content

Commit

Permalink
MDL-66431 core: Remove activity chooser user preference.
Browse files Browse the repository at this point in the history
This commit removes activity chooser user preference and
course preference page. Separate dropdowns to activity and
resource is also removed.
  • Loading branch information
ilyatregubov committed May 1, 2021
1 parent 0a986fd commit 430746d
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 247 deletions.
1 change: 0 additions & 1 deletion admin/settings/appearance.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@
$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.
Expand Down
195 changes: 99 additions & 96 deletions course/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,100 +272,21 @@ public function course_section_cm_edit_actions($actions, cm_info $mod = null, $d
* @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'));
Expand All @@ -384,18 +305,100 @@ function course_section_add_cm_control($course, $section, $sectionreturn = null,

// 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;
}

/**
Expand Down
1 change: 1 addition & 0 deletions course/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===

Expand Down
10 changes: 6 additions & 4 deletions lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@
$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.';
Expand Down Expand Up @@ -297,7 +296,6 @@
$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';
Expand Down Expand Up @@ -554,7 +552,6 @@
* 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';
Expand Down Expand Up @@ -853,7 +850,6 @@
$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';
Expand Down Expand Up @@ -1533,3 +1529,9 @@
// 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';
3 changes: 3 additions & 0 deletions lang/en/deprecated.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,6 @@ aimid,core
yahooid,core
icqnumber,core
msnid,core
configenableactivitychooser,core_admin
enableactivitychooser,core_admin
coursepreferences,core
2 changes: 1 addition & 1 deletion lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@
$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.';
Expand Down Expand Up @@ -2324,3 +2323,4 @@
$string['skypeid'] = 'Skype ID';
$string['icqnumber'] = 'ICQ number';
$string['msnid'] = 'MSN ID';
$string['coursepreferences'] = 'Course preferences';
2 changes: 0 additions & 2 deletions lib/classes/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -947,8 +947,6 @@ protected static function fill_preferences_cache() {
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,
Expand Down
8 changes: 8 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
9 changes: 0 additions & 9 deletions lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -5087,15 +5087,6 @@ protected function generate_user_settings($courseid, $userid, $gstitle='usercurr
}
}

// 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) ||
Expand Down
Loading

0 comments on commit 430746d

Please sign in to comment.