Skip to content

Instantly share code, notes, and snippets.

@andrewnicols
Last active June 29, 2016 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewnicols/5bdc7648510528b07f41ddad328713b6 to your computer and use it in GitHub Desktop.
Save andrewnicols/5bdc7648510528b07f41ddad328713b6 to your computer and use it in GitHub Desktop.
2266 integration:master> git rebase --preserve-merges -i 41226e16f5fe33682376de53e5606c9b5d09d4fc~1
pick 41226e1 Merge branch 'MDL-31012-master' of git://github.com/marinaglancy/moodle
pick d9dea47 Merge branch 'wip-mdl-54974' of https://github.com/rajeshtaneja/moodle
pick 2fe4901 Merge branch 'MDL-54964-master' of git://github.com/jleyva/moodle
pick 823ef81 Merge branch 'MDL-54935_m32v1' of git://github.com/sbourget/moodle
pick 83f83b5 Merge branch 'MDL-54755_master' of https://github.com/StudiUM/moodle
pick 57355eb MDL-54755 core: Correct behat language
pick 3c35e24 Merge branch 'MDL-54911_m32v3' of https://github.com/sbourget/moodle
pick cd2d94c Merge branch 'MDL-54910_m32v2' of https://github.com/sbourget/moodle
pick ccd3b96 Merge branch 'MDL-54601-master' of git://github.com/jleyva/moodle
pick c92bc26 Merge branch 'MDL-54909-master' of git://github.com/crazyserver/moodle
pick 73507c1 Merge branch 'MDL-54991-master' of git://github.com/crazyserver/moodle
pick a3bed41 Merge branch 'MDL-55002-master-enfix' of git://github.com/mudrd8mz/moodle
pick 512703d Merge branch 'MDL-54868-master' of git://github.com/cameron1729/moodle
pick 974c14d Merge branch 'MDL-41945-master' of git://github.com/cameron1729/moodle
pick eb39cfd Merge branch 'MDL-54865-master' of git://github.com/ryanwyllie/moodle
pick f0a6d6d Merge branch 'MDL-32135_m32v2' of https://github.com/sbourget/moodle
pick b758f03 Merge branch 'MDL-54993' of https://github.com/sk-unikent/moodle
pick 4c8a787 Merge branch 'MDL-55027_master' of git://github.com/markn86/moodle
pick ce7fcf8 Merge branch 'MDL-55022-master' of git://github.com/junpataleta/moodle
pick 2c123b2 Merge branch 'MDL-54104-master' of git://github.com/jleyva/moodle
pick 699d2bb Merge branch 'MDL-54855-master' of git://github.com/crazyserver/moodle
pick eec0878 Merge branch 'wip-MDL-47113-master' of git://github.com/abgreeve/moodle
pick 241f46c Merge branch 'MDL-54610_master' of https://github.com/snake/moodle
# Rebase 22a0896..241f46c onto 22a0896 (23 command(s))
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
pick d9dea47 Merge branch 'wip-mdl-54974' of https://github.com/rajeshtaneja/moodle
pick 2fe4901 Merge branch 'MDL-54964-master' of git://github.com/jleyva/moodle
pick 823ef81 Merge branch 'MDL-54935_m32v1' of git://github.com/sbourget/moodle
pick 83f83b5 Merge branch 'MDL-54755_master' of https://github.com/StudiUM/moodle
pick 57355eb MDL-54755 core: Correct behat language
pick 3c35e24 Merge branch 'MDL-54911_m32v3' of https://github.com/sbourget/moodle
pick cd2d94c Merge branch 'MDL-54910_m32v2' of https://github.com/sbourget/moodle
pick ccd3b96 Merge branch 'MDL-54601-master' of git://github.com/jleyva/moodle
pick c92bc26 Merge branch 'MDL-54909-master' of git://github.com/crazyserver/moodle
pick 73507c1 Merge branch 'MDL-54991-master' of git://github.com/crazyserver/moodle
pick a3bed41 Merge branch 'MDL-55002-master-enfix' of git://github.com/mudrd8mz/moodle
pick 512703d Merge branch 'MDL-54868-master' of git://github.com/cameron1729/moodle
pick 974c14d Merge branch 'MDL-41945-master' of git://github.com/cameron1729/moodle
pick eb39cfd Merge branch 'MDL-54865-master' of git://github.com/ryanwyllie/moodle
pick f0a6d6d Merge branch 'MDL-32135_m32v2' of https://github.com/sbourget/moodle
pick b758f03 Merge branch 'MDL-54993' of https://github.com/sk-unikent/moodle
pick 4c8a787 Merge branch 'MDL-55027_master' of git://github.com/markn86/moodle
pick ce7fcf8 Merge branch 'MDL-55022-master' of git://github.com/junpataleta/moodle
pick 2c123b2 Merge branch 'MDL-54104-master' of git://github.com/jleyva/moodle
pick 699d2bb Merge branch 'MDL-54855-master' of git://github.com/crazyserver/moodle
pick eec0878 Merge branch 'wip-MDL-47113-master' of git://github.com/abgreeve/moodle
pick 241f46c Merge branch 'MDL-54610_master' of https://github.com/snake/moodle
# Rebase 22a0896..241f46c onto 22a0896 (23 command(s))
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
Auto-merging mod/assign/upgrade.txt
CONFLICT (content): Merge conflict in mod/assign/upgrade.txt
Auto-merging mod/assign/externallib.php
Automatic merge failed; fix conflicts and then commit the result.
Error redoing merge 699d2bb8fcc8487d161edfbbbde1f2603ed58c37
2267 integration:(HEAD detached from 2ebf0fe)> git st
HEAD detached from 2ebf0fe
You have unmerged paths.
(fix conflicts and run "git commit")
Changes to be committed:
modified: mod/assign/externallib.php
modified: mod/assign/tests/externallib_test.php
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: mod/assign/upgrade.txt
enrol/manual/locallib.php | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
enrol/manual/tests/behat/manual_enrolment_bulk.feature | 70 ----------------------------------------------------------------------
enrol/self/classes/deleteselectedusers_form.php | 38 --------------------------------------
enrol/self/classes/deleteselectedusers_operation.php | 99 ---------------------------------------------------------------------------------------------------
enrol/self/classes/editselectedusers_form.php | 38 --------------------------------------
enrol/self/classes/editselectedusers_operation.php | 103 -------------------------------------------------------------------------------------------------------
enrol/self/lang/en/enrol_self.php | 4 ----
enrol/self/lib.php | 17 -----------------
enrol/self/tests/behat/self_enrolment_bulk.feature | 87 ---------------------------------------------------------------------------------------
lib/enrollib.php | 117 ++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------
mod/lti/lang/en/lti.php | 2 +-
11 files changed, 106 insertions(+), 553 deletions(-)
diff --git a/enrol/manual/locallib.php b/enrol/manual/locallib.php
index 153ed5d..89b99df 100644
--- a/enrol/manual/locallib.php
+++ b/enrol/manual/locallib.php
@@ -189,31 +189,93 @@ class enrol_manual_editselectedusers_operation extends enrol_bulk_enrolment_oper
* @param stdClass $properties The data returned by the form.
*/
public function process(course_enrolment_manager $manager, array $users, stdClass $properties) {
+ global $DB, $USER;
if (!has_capability("enrol/manual:manage", $manager->get_context())) {
return false;
}
- // From array of users get the list of enrol instances and user enrolments to update.
- // This should be only one enrol instance but we build an array to be sure.
- $instances = [];
- $enrolments = [];
+ // Get all of the user enrolment id's.
+ $ueids = array();
+ $instances = array();
foreach ($users as $user) {
foreach ($user->enrolments as $enrolment) {
- if ($this->plugin->allow_manage($enrolment)) {
- $instances[$enrolment->enrolmentinstance->id] = $enrolment->enrolmentinstance;
- $enrolment->userid = $user->id;
- $enrolments[$enrolment->enrolmentinstance->id][$enrolment->id] = $enrolment;
+ $ueids[] = $enrolment->id;
+ if (!array_key_exists($enrolment->id, $instances)) {
+ $instances[$enrolment->id] = $enrolment;
}
}
}
+ // Check that each instance is manageable by the current user.
foreach ($instances as $instance) {
- $this->plugin->bulk_update_user_enrol($instance, $enrolments[$instance->id],
- $properties->status, $properties->timestart, $properties->timeend);
+ if (!$this->plugin->allow_manage($instance)) {
+ return false;
+ }
}
- return true;
+ // Collect the known properties.
+ $status = $properties->status;
+ $timestart = $properties->timestart;
+ $timeend = $properties->timeend;
+
+ list($ueidsql, $params) = $DB->get_in_or_equal($ueids, SQL_PARAMS_NAMED);
+
+ $updatesql = array();
+ if ($status == ENROL_USER_ACTIVE || $status == ENROL_USER_SUSPENDED) {
+ $updatesql[] = 'status = :status';
+ $params['status'] = (int)$status;
+ }
+ if (!empty($timestart)) {
+ $updatesql[] = 'timestart = :timestart';
+ $params['timestart'] = (int)$timestart;
+ }
+ if (!empty($timeend)) {
+ $updatesql[] = 'timeend = :timeend';
+ $params['timeend'] = (int)$timeend;
+ }
+ if (empty($updatesql)) {
+ return true;
+ }
+
+ // Update the modifierid.
+ $updatesql[] = 'modifierid = :modifierid';
+ $params['modifierid'] = (int)$USER->id;
+
+ // Update the time modified.
+ $updatesql[] = 'timemodified = :timemodified';
+ $params['timemodified'] = time();
+
+ // Build the SQL statement.
+ $updatesql = join(', ', $updatesql);
+ $sql = "UPDATE {user_enrolments}
+ SET $updatesql
+ WHERE id $ueidsql";
+
+ if ($DB->execute($sql, $params)) {
+ foreach ($users as $user) {
+ foreach ($user->enrolments as $enrolment) {
+ $enrolment->courseid = $enrolment->enrolmentinstance->courseid;
+ $enrolment->enrol = 'manual';
+ // Trigger event.
+ $event = \core\event\user_enrolment_updated::create(
+ array(
+ 'objectid' => $enrolment->id,
+ 'courseid' => $enrolment->courseid,
+ 'context' => context_course::instance($enrolment->courseid),
+ 'relateduserid' => $user->id,
+ 'other' => array('enrol' => 'manual')
+ )
+ );
+ $event->trigger();
+ }
+ }
+ // Delete cached course contacts for this course because they may be affected.
+ cache::make('core', 'coursecontacts')->delete($manager->get_context()->instanceid);
+ return true;
+ }
+
+ return false;
}
/**
diff --git a/enrol/manual/tests/behat/manual_enrolment_bulk.feature b/enrol/manual/tests/behat/manual_enrolment_bulk.feature
deleted file mode 100644
index bdef8ea..0000000
--- a/enrol/manual/tests/behat/manual_enrolment_bulk.feature
+++ /dev/null
@@ -1,70 +0,0 @@
-@enrol @enrol_manual
-Feature: Teacher is able to bulk edit or delete manual enrolments
- In order to manage enrolments
- As a teacher
- I need to be able to bulk edit or delete manual enrolments
-
- Background:
- Given the following "users" exist:
- | username | firstname | lastname | email |
- | teacher1 | Teacher | 1 | teacher1@example.com |
- | student1 | Student | 1 | student1@example.com |
- | student2 | Student | 2 | student2@example.com |
- | student3 | Student | 3 | student2@example.com |
- And the following "courses" exist:
- | fullname | shortname | format |
- | Course 1 | C1 | topics |
- And the following "course enrolments" exist:
- | user | course | role |
- | teacher1 | C1 | editingteacher |
- | student1 | C1 | student |
- | student2 | C1 | student |
- | student3 | C1 | student |
-
- @javascript
- Scenario: Bulk delete self enrolments
- When I log in as "teacher1"
- And I follow "Course 1"
- And I navigate to "Enrolled users" node in "Course administration > Users"
- And I set the field "Enrolment methods" to "Manual"
- And I press "Filter"
- And I click on "input[type=checkbox]" "css_element" in the "Student 1" "table_row"
- And I click on "input[type=checkbox]" "css_element" in the "Student 3" "table_row"
- And I set the field "bulkuserop" to "Delete selected user enrolments"
- And I press "Go"
- Then I should see "Student 1"
- And I should see "Student 3"
- And I should not see "Student 2"
- And I should see "Are you sure you want to delete these users enrolments?"
- And I press "Unenrol users"
- And I should not see "Student 1"
- And I should not see "Student 3"
- And I should see "Student 2"
- And I log out
-
- @javascript
- Scenario: Bulk edit self enrolments
- When I log in as "teacher1"
- And I follow "Course 1"
- And I navigate to "Enrolled users" node in "Course administration > Users"
- And I set the field "Enrolment methods" to "Manual"
- And I press "Filter"
- And I click on "input[type=checkbox]" "css_element" in the "Student 1" "table_row"
- And I click on "input[type=checkbox]" "css_element" in the "Student 3" "table_row"
- And I set the field "bulkuserop" to "Edit selected user enrolments"
- And I press "Go"
- Then I should see "Student 1"
- And I should see "Student 3"
- And I should not see "Student 2"
- And I set the field "Alter status" to "Suspended"
- And I press "Save changes"
- And I click on "Edit" "link" in the "Student 1" "table_row"
- And the field "Status" matches value "Suspended"
- And I press "Cancel"
- And I click on "Edit" "link" in the "Student 2" "table_row"
- And the field "Status" matches value "Active"
- And I press "Cancel"
- And I click on "Edit" "link" in the "Student 3" "table_row"
- And the field "Status" matches value "Suspended"
- And I press "Cancel"
- And I log out
diff --git a/enrol/self/classes/deleteselectedusers_form.php b/enrol/self/classes/deleteselectedusers_form.php
deleted file mode 100644
index decb0a5..0000000
--- a/enrol/self/classes/deleteselectedusers_form.php
+++ /dev/null
@@ -1,38 +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/>.
-
-/**
- * Contains class enrol_self_editselectedusers_form
- *
- * @copyright 2016 Marina Glancy
- * @package enrol_self
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-require_once($CFG->dirroot . '/enrol/bulkchange_forms.php');
-
-/**
- * The form to collect required information when bulk editing users enrolments.
- *
- * @copyright 2016 Marina Glancy
- * @package enrol_self
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class enrol_self_deleteselectedusers_form extends enrol_bulk_enrolment_confirm_form {
-
-}
diff --git a/enrol/self/classes/deleteselectedusers_operation.php b/enrol/self/classes/deleteselectedusers_operation.php
deleted file mode 100644
index 41b5063..0000000
--- a/enrol/self/classes/deleteselectedusers_operation.php
+++ /dev/null
@@ -1,99 +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/>.
-
-/**
- * Contains class enrol_self_deleteselectedusers_operation
- *
- * @copyright 2016 Marina Glancy
- * @package enrol_self
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-require_once($CFG->dirroot . '/enrol/locallib.php');
-
-/**
- * A bulk operation for the self enrolment plugin to edit selected users.
- *
- * @copyright 2016 Marina Glancy
- * @package enrol_self
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class enrol_self_deleteselectedusers_operation extends enrol_bulk_enrolment_operation {
-
- /**
- * Returns the title to display for this bulk operation.
- *
- * @return string
- */
- public function get_identifier() {
- return 'deleteselectedusers';
- }
-
- /**
- * Returns the identifier for this bulk operation. This is the key used when the plugin
- * returns an array containing all of the bulk operations it supports.
- *
- * @return string
- */
- public function get_title() {
- return get_string('deleteselectedusers', 'enrol_self');
- }
-
- /**
- * Returns a enrol_bulk_enrolment_operation extension form to be used
- * in collecting required information for this operation to be processed.
- *
- * @param string|moodle_url|null $defaultaction
- * @param mixed $defaultcustomdata
- * @return enrol_self_editselectedusers_form
- */
- public function get_form($defaultaction = null, $defaultcustomdata = null) {
- if (!array($defaultcustomdata)) {
- $defaultcustomdata = array();
- }
- $defaultcustomdata['title'] = $this->get_title();
- $defaultcustomdata['message'] = get_string('confirmbulkdeleteenrolment', 'enrol_self');
- $defaultcustomdata['button'] = get_string('unenrolusers', 'enrol_self');
- return new enrol_self_deleteselectedusers_form($defaultaction, $defaultcustomdata);
- }
-
- /**
- * Processes the bulk operation request for the given userids with the provided properties.
- *
- * @param course_enrolment_manager $manager
- * @param array $users array of users and their enrolments as returned
- * by {@link course_enrolment_manager::get_users_enrolments()}
- * @param stdClass $properties The data returned by the form.
- * @return bool false if capability/plugin check failed, true otherwise
- */
- public function process(course_enrolment_manager $manager, array $users, stdClass $properties) {
- if (!has_capability("enrol/self:unenrol", $manager->get_context())) {
- return false;
- }
- foreach ($users as $user) {
- foreach ($user->enrolments as $enrolment) {
- $plugin = $enrolment->enrolmentplugin;
- $instance = $enrolment->enrolmentinstance;
- if ($plugin->allow_unenrol_user($instance, $enrolment)) {
- $plugin->unenrol_user($instance, $user->id);
- }
- }
- }
- return true;
- }
-}
diff --git a/enrol/self/classes/editselectedusers_form.php b/enrol/self/classes/editselectedusers_form.php
deleted file mode 100644
index 817dc85..0000000
--- a/enrol/self/classes/editselectedusers_form.php
+++ /dev/null
@@ -1,38 +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/>.
-
-/**
- * Contains class enrol_self_deleteselectedusers_operation
- *
- * @copyright 2016 Marina Glancy
- * @package enrol_self
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-require_once($CFG->dirroot . '/enrol/bulkchange_forms.php');
-
-/**
- * The form to confirm the intention to bulk delete users enrolments.
- *
- * @copyright 2016 Marina Glancy
- * @package enrol_self
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class enrol_self_editselectedusers_form extends enrol_bulk_enrolment_change_form {
-
-}
diff --git a/enrol/self/classes/editselectedusers_operation.php b/enrol/self/classes/editselectedusers_operation.php
deleted file mode 100644
index ad87678..0000000
--- a/enrol/self/classes/editselectedusers_operation.php
+++ /dev/null
@@ -1,103 +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/>.
-
-/**
- * Contains class enrol_self_editselectedusers_operation
- *
- * @copyright 2016 Marina Glancy
- * @package enrol_self
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-require_once($CFG->dirroot . '/enrol/locallib.php');
-
-/**
- * A bulk operation for the self enrolment plugin to edit selected users.
- *
- * @copyright 2016 Marina Glancy
- * @package enrol_self
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class enrol_self_editselectedusers_operation extends enrol_bulk_enrolment_operation {
-
- /**
- * Returns the title to display for this bulk operation.
- *
- * @return string
- */
- public function get_title() {
- return get_string('editselectedusers', 'enrol_self');
- }
-
- /**
- * Returns the identifier for this bulk operation. This is the key used when the plugin
- * returns an array containing all of the bulk operations it supports.
- */
- public function get_identifier() {
- return 'editselectedusers';
- }
-
- /**
- * Processes the bulk operation request for given users with the provided properties.
- *
- * @param course_enrolment_manager $manager
- * @param array $users array of users and their enrolments as returned
- * by {@link course_enrolment_manager::get_users_enrolments()}
- * @param stdClass $properties The data returned by the form, see get_form()
- * @return bool false if capability/plugin check failed, true otherwise
- */
- public function process(course_enrolment_manager $manager, array $users, stdClass $properties) {
-
- if (!has_capability("enrol/self:manage", $manager->get_context())) {
- return false;
- }
-
- // From array of users get the list of enrol instances and user enrolments to update.
- // This should be only one enrol instance but we build an array to be sure.
- $instances = [];
- $enrolments = [];
- foreach ($users as $user) {
- foreach ($user->enrolments as $enrolment) {
- if ($this->plugin->allow_manage($enrolment)) {
- $instances[$enrolment->enrolmentinstance->id] = $enrolment->enrolmentinstance;
- $enrolment->userid = $user->id;
- $enrolments[$enrolment->enrolmentinstance->id][$enrolment->id] = $enrolment;
- }
- }
- }
-
- foreach ($instances as $instance) {
- $this->plugin->bulk_update_user_enrol($instance, $enrolments[$instance->id],
- $properties->status, $properties->timestart, $properties->timeend);
- }
-
- return true;
- }
-
- /**
- * Returns a enrol_bulk_enrolment_operation extension form to be used
- * in collecting required information for this operation to be processed.
- *
- * @param string|moodle_url|null $defaultaction
- * @param mixed $defaultcustomdata
- * @return enrol_self_editselectedusers_form
- */
- public function get_form($defaultaction = null, $defaultcustomdata = null) {
- return new enrol_self_editselectedusers_form($defaultaction, $defaultcustomdata);
- }
-}
diff --git a/enrol/self/lang/en/enrol_self.php b/enrol/self/lang/en/enrol_self.php
index 864158d..1af38c6 100644
--- a/enrol/self/lang/en/enrol_self.php
+++ b/enrol/self/lang/en/enrol_self.php
@@ -28,7 +28,6 @@ $string['canntenrollate'] = 'You cannot enrol any more, since enrolment ended on
$string['cohortnonmemberinfo'] = 'Only members of cohort \'{$a}\' can self-enrol.';
$string['cohortonly'] = 'Only cohort members';
$string['cohortonly_help'] = 'Self enrolment may be restricted to members of a specified cohort only. Note that changing this setting has no effect on existing enrolments.';
-$string['confirmbulkdeleteenrolment'] = 'Are you sure you want to delete these users enrolments?';
$string['customwelcomemessage'] = 'Custom welcome message';
$string['customwelcomemessage_help'] = 'A custom welcome message may be added as plain text or Moodle-auto format, including HTML tags and multi-lang tags.
@@ -40,8 +39,6 @@ The following placeholders may be included in the message:
* User fullname {$a->fullname}';
$string['defaultrole'] = 'Default role assignment';
$string['defaultrole_desc'] = 'Select role which should be assigned to users during self enrolment';
-$string['deleteselectedusers'] = 'Delete selected user enrolments';
-$string['editselectedusers'] = 'Edit selected user enrolments';
$string['enrolenddate'] = 'End date';
$string['enrolenddate_help'] = 'If enabled, users can enrol themselves until this date only.';
$string['enrolenddaterror'] = 'Enrolment end date cannot be earlier than start date';
@@ -108,7 +105,6 @@ $string['status'] = 'Allow existing enrolments';
$string['status_desc'] = 'Enable self enrolment method in new courses.';
$string['status_help'] = 'If enabled together with \'Allow new enrolments\' disabled, only users who self enrolled previously can access the course. If disabled, this self enrolment method is effectively disabled, since all existing self enrolments are suspended and new users cannot self enrol.';
$string['unenrol'] = 'Unenrol user';
-$string['unenrolusers'] = 'Unenrol users';
$string['unenrolselfconfirm'] = 'Do you really want to unenrol yourself from course "{$a}"?';
$string['unenroluser'] = 'Do you really want to unenrol "{$a->user}" from course "{$a->course}"?';
$string['usepasswordpolicy'] = 'Use password policy';
diff --git a/enrol/self/lib.php b/enrol/self/lib.php
index f35e6f3..7b2827e 100644
--- a/enrol/self/lib.php
+++ b/enrol/self/lib.php
@@ -561,23 +561,6 @@ class enrol_self_plugin extends enrol_plugin {
}
/**
- * The enrol_self plugin has several bulk operations that can be performed.
- * @param course_enrolment_manager $manager
- * @return array
- */
- public function get_bulk_operations(course_enrolment_manager $manager) {
- $context = $manager->get_context();
- $bulkoperations = array();
- if (has_capability("enrol/self:manage", $context)) {
- $bulkoperations['editselectedusers'] = new enrol_self_editselectedusers_operation($manager, $this);
- }
- if (has_capability("enrol/self:unenrol", $context)) {
- $bulkoperations['deleteselectedusers'] = new enrol_self_deleteselectedusers_operation($manager, $this);
- }
- return $bulkoperations;
- }
-
- /**
* Restore instance and map settings.
*
* @param restore_enrolments_structure_step $step
diff --git a/enrol/self/tests/behat/self_enrolment_bulk.feature b/enrol/self/tests/behat/self_enrolment_bulk.feature
deleted file mode 100644
index f6f190f..0000000
--- a/enrol/self/tests/behat/self_enrolment_bulk.feature
+++ /dev/null
@@ -1,87 +0,0 @@
-@enrol @enrol_self
-Feature: Teacher is able to bulk edit or delete self enrolments
- In order to manage enrolments
- As a teacher
- I need to be able to bulk edit or delete self enrolments
-
- Background:
- Given the following "users" exist:
- | username | firstname | lastname | email |
- | teacher1 | Teacher | 1 | teacher1@example.com |
- | student1 | Student | 1 | student1@example.com |
- | student2 | Student | 2 | student2@example.com |
- | student3 | Student | 3 | student2@example.com |
- And the following "courses" exist:
- | fullname | shortname | format |
- | Course 1 | C1 | topics |
- And the following "course enrolments" exist:
- | user | course | role |
- | teacher1 | C1 | editingteacher |
- And I log in as "teacher1"
- And I follow "Course 1"
- And I add "Self enrolment" enrolment method with:
- | Custom instance name | Test student enrolment |
- And I log out
- And I log in as "student1"
- And I am on site homepage
- And I follow "Course 1"
- And I press "Enrol me"
- And I log out
- And I log in as "student2"
- And I am on site homepage
- And I follow "Course 1"
- And I press "Enrol me"
- And I log out
- And I log in as "student3"
- And I am on site homepage
- And I follow "Course 1"
- And I press "Enrol me"
- And I log out
-
- @javascript
- Scenario: Bulk delete self enrolments
- When I log in as "teacher1"
- And I follow "Course 1"
- And I navigate to "Enrolled users" node in "Course administration > Users"
- And I set the field "Enrolment methods" to "Test student enrolment"
- And I press "Filter"
- And I click on "input[type=checkbox]" "css_element" in the "Student 1" "table_row"
- And I click on "input[type=checkbox]" "css_element" in the "Student 3" "table_row"
- And I set the field "bulkuserop" to "Delete selected user enrolments"
- And I press "Go"
- Then I should see "Student 1"
- And I should see "Student 3"
- And I should not see "Student 2"
- And I should see "Are you sure you want to delete these users enrolments?"
- And I press "Unenrol users"
- And I should not see "Student 1"
- And I should not see "Student 3"
- And I should see "Student 2"
- And I log out
-
- @javascript
- Scenario: Bulk edit self enrolments
- When I log in as "teacher1"
- And I follow "Course 1"
- And I navigate to "Enrolled users" node in "Course administration > Users"
- And I set the field "Enrolment methods" to "Test student enrolment"
- And I press "Filter"
- And I click on "input[type=checkbox]" "css_element" in the "Student 1" "table_row"
- And I click on "input[type=checkbox]" "css_element" in the "Student 3" "table_row"
- And I set the field "bulkuserop" to "Edit selected user enrolments"
- And I press "Go"
- Then I should see "Student 1"
- And I should see "Student 3"
- And I should not see "Student 2"
- And I set the field "Alter status" to "Suspended"
- And I press "Save changes"
- And I click on "Edit" "link" in the "Student 1" "table_row"
- And the field "Status" matches value "Suspended"
- And I press "Cancel"
- And I click on "Edit" "link" in the "Student 2" "table_row"
- And the field "Status" matches value "Active"
- And I press "Cancel"
- And I click on "Edit" "link" in the "Student 3" "table_row"
- And the field "Status" matches value "Suspended"
- And I press "Cancel"
- And I log out
diff --git a/lib/enrollib.php b/lib/enrollib.php
index 14ec80c..f42e639 100644
--- a/lib/enrollib.php
+++ b/lib/enrollib.php
@@ -1375,25 +1375,6 @@ abstract class enrol_plugin {
* @return void
*/
public function update_user_enrol(stdClass $instance, $userid, $status = NULL, $timestart = NULL, $timeend = NULL) {
- global $DB;
- $enrolments = $DB->get_records('user_enrolments', ['enrolid' => $instance->id, 'userid' => $userid]);
- $this->bulk_update_user_enrol($instance, $enrolments, $status, $timestart, $timeend);
- }
-
- /**
- * Store user_enrolments changes and trigger event.
- *
- * This method is used from update_user_enrol and from bulk update operations.
- * There are no capabilities checks here.
- *
- * @param stdClass $instance record from table enrol
- * @param array $enrolments list of records from table user_enrolments for the given enrol instance
- * @param int $status new status (null for no changes)
- * @param int $timestart new timestart (null for no changes)
- * @param int $timeend new timeend (null for no changes)
- * @return void
- */
- public function bulk_update_user_enrol(stdClass $instance, $enrolments, $status = null, $timestart = null, $timeend = null) {
global $DB, $USER, $CFG;
$name = $this->get_name();
@@ -1402,86 +1383,52 @@ abstract class enrol_plugin {
throw new coding_exception('invalid enrol instance!');
}
- if (($status === null && $timestart === null && $timeend === null) || empty($enrolments)) {
- // Nothing to do.
- return;
- }
-
- // Find enrolments that need changing.
- foreach ($enrolments as $ueid => $ue) {
- if ($ue->enrolid != $instance->id) {
- // Inconsistent data, user enrolment record does not correspond to enrol isntance, skip.
- unset($enrolments[$ueid]);
- continue;
- }
- $modified = false;
- if (isset($status) and $ue->status != $status) {
- $enrolments[$ueid]->status = $status;
- $modified = true;
- }
- if (isset($timestart) and $ue->timestart != $timestart) {
- $enrolments[$ueid]->timestart = $timestart;
- $modified = true;
- }
- if (isset($timeend) and $ue->timeend != $timeend) {
- $enrolments[$ueid]->timeend = $timeend;
- $modified = true;
- }
- if (!$modified) {
- unset($enrolments[$ueid]);
- }
- }
-
- if (empty($enrolments)) {
- // No users enrolments need updating.
+ if (!$ue = $DB->get_record('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$userid))) {
+ // weird, user not enrolled
return;
}
- // Update all users in bulk.
- list($ueidsql, $params) = $DB->get_in_or_equal(array_keys($enrolments), SQL_PARAMS_NAMED);
- $updatesql = 'modifierid = :modifierid, timemodified = :timemodified';
- $params += [
- 'modifierid' => $USER->id,
- 'timemodified' => time(),
- 'status' => $status,
- 'timestart' => $timestart,
- 'timeend' => $timeend
- ];
- if (isset($status) && ($status == ENROL_USER_ACTIVE || $status == ENROL_USER_SUSPENDED)) {
- $updatesql .= ', status = :status';
+ $modified = false;
+ if (isset($status) and $ue->status != $status) {
+ $ue->status = $status;
+ $modified = true;
}
- if (isset($timestart)) {
- $updatesql .= ', timestart = :timestart';
+ if (isset($timestart) and $ue->timestart != $timestart) {
+ $ue->timestart = $timestart;
+ $modified = true;
}
- if (isset($timeend)) {
- $updatesql .= ', timeend = :timeend';
+ if (isset($timeend) and $ue->timeend != $timeend) {
+ $ue->timeend = $timeend;
+ $modified = true;
}
- $sql = "UPDATE {user_enrolments} SET $updatesql WHERE id $ueidsql";
- $DB->execute($sql, $params);
+ if (!$modified) {
+ // no change
+ return;
+ }
- // Reset enrol caches.
- context_course::instance($instance->courseid)->mark_dirty();
+ $ue->modifierid = $USER->id;
+ $DB->update_record('user_enrolments', $ue);
+ context_course::instance($instance->courseid)->mark_dirty(); // reset enrol caches
// Invalidate core_access cache for get_suspended_userids.
cache_helper::invalidate_by_definition('core', 'suspended_userids', array(), array($instance->courseid));
- require_once($CFG->libdir . '/coursecatlib.php');
-
- // Trigger events one by one.
- foreach ($enrolments as $ue) {
- $event = \core\event\user_enrolment_updated::create([
- 'objectid' => $ue->id,
- 'courseid' => $instance->courseid,
- 'context' => context_course::instance($instance->courseid),
- 'relateduserid' => $ue->userid,
- 'other' => array('enrol' => $name)
- ]);
- $event->trigger();
+ // Trigger event.
+ $event = \core\event\user_enrolment_updated::create(
+ array(
+ 'objectid' => $ue->id,
+ 'courseid' => $instance->courseid,
+ 'context' => context_course::instance($instance->courseid),
+ 'relateduserid' => $ue->userid,
+ 'other' => array('enrol' => $name)
+ )
+ );
+ $event->trigger();
- coursecat::user_enrolment_changed($instance->courseid, $ue->userid,
+ require_once($CFG->libdir . '/coursecatlib.php');
+ coursecat::user_enrolment_changed($instance->courseid, $ue->userid,
$ue->status, $ue->timestart, $ue->timeend);
- }
}
/**
diff --git a/mod/lti/lang/en/lti.php b/mod/lti/lang/en/lti.php
index 86d64c6..8fcd75e 100644
--- a/mod/lti/lang/en/lti.php
+++ b/mod/lti/lang/en/lti.php
@@ -80,7 +80,7 @@ $string['basiclti'] = 'LTI';
$string['basiclti_base_string'] = 'LTI OAuth base string';
$string['basiclti_endpoint'] = 'LTI launch endpoint';
$string['basiclti_in_new_window'] = 'Your activity has opened in a new window';
-$string['basiclti_in_new_window_open'] = 'Open in new window';
+$string['basiclti_in_new_window_open'] = 'Click here if the new window has not opened';
$string['basiclti_parameters'] = 'LTI launch parameters';
$string['basicltiactivities'] = 'LTI activities';
$string['basicltifieldset'] = 'Custom example fieldset';
2024 integration:master> git push origin master --force
Counting objects: 90, done.
Delta compression using up to 6 threads.
Compressing objects: 100% (77/77), done.
Writing objects: 100% (90/90), 14.03 KiB | 0 bytes/s, done.
Total 90 (delta 62), reused 10 (delta 10)
To git@git.in.moodle.com:moodle/integration.git
+ 241f46c...2ce6407 master -> master (forced update)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment