MDL-39959: Replace Legacy events - Groups

This combines the following changes:

* Event for group member added
* Event for group member removed
* Event for group created
* Event for grouping created
* Event for group updated
* Event for grouping updated
* Event for group deleted
* Event for grouping deleted
* Adding tests for deleting functions
* Bulk remove of members uses low-level API

    The reason for this is that a bulk event has no value from a logging
    perspective as it is not granular. So now, the API is a bit slower,
    but the information the events contain makes sense, beside this is
    not (and should not be) used very often.

    The reason why the events_trigger_legacy() is kept is because we
    cannot create a new event for this, as we don't encourage developers
    to created bulk events, for the reasons mentioned above.

    I removed the call that gets the user record from the function
    groups_remove_member() as it was not required and only appeared
    to check if the user existed. It appears to be safe not to do
    this check as nothing would fail down the line.

* Bulk unassign of groupings uses low-level API

    As the previous commit, we keep the legacy event for now as it would
    be wrong to create a new event to replace it.

    Also, the code has been changed to call the low-level API to unassign
    groups from groupins, even though at the moment there are no
    events for that function.

* Bulk deletion of groups uses low-level API

    Again, we keep the legacy event because replacing it would force
    us to create a new event that does not make sense. See MDL-41312.

* Bulk deleting of groupings uses low-level API
* Asserting legacy event name in unit tests
* Minor SQL query and code improvements
This commit is contained in:
Frederic Massart 2013-08-19 16:17:49 +08:00 committed by Damyon Wiese
parent 11b80a6044
commit 861b0510e5
12 changed files with 1325 additions and 87 deletions

View File

@ -64,8 +64,9 @@ function groups_add_member($grouporid, $userorid, $component=null, $itemid=0) {
$group = $DB->get_record('groups', array('id'=>$groupid), '*', MUST_EXIST);
}
//check if the user a participant of the group course
if (!is_enrolled(context_course::instance($group->courseid), $userid)) {
// Check if the user a participant of the group course.
$context = context_course::instance($group->courseid);
if (!is_enrolled($context, $userid)) {
return false;
}
@ -99,16 +100,23 @@ function groups_add_member($grouporid, $userorid, $component=null, $itemid=0) {
$DB->insert_record('groups_members', $member);
//update group info
// Update group info, and group object.
$DB->set_field('groups', 'timemodified', $member->timeadded, array('id'=>$groupid));
$group->timemodified = $member->timeadded;
//trigger groups events
$eventdata = new stdClass();
$eventdata->groupid = $groupid;
$eventdata->userid = $userid;
$eventdata->component = $member->component;
$eventdata->itemid = $member->itemid;
events_trigger('groups_member_added', $eventdata);
// Trigger group event.
$params = array(
'context' => $context,
'objectid' => $groupid,
'relateduserid' => $userid,
'other' => array(
'component' => $member->component,
'itemid' => $member->itemid
)
);
$event = \core\event\group_member_added::create($params);
$event->add_record_snapshot('groups', $group);
$event->trigger();
return true;
}
@ -174,10 +182,8 @@ function groups_remove_member($grouporid, $userorid) {
if (is_object($userorid)) {
$userid = $userorid->id;
$user = $userorid;
} else {
$userid = $userorid;
$user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
}
if (is_object($grouporid)) {
@ -194,14 +200,20 @@ function groups_remove_member($grouporid, $userorid) {
$DB->delete_records('groups_members', array('groupid'=>$groupid, 'userid'=>$userid));
//update group info
$DB->set_field('groups', 'timemodified', time(), array('id'=>$groupid));
// Update group info.
$time = time();
$DB->set_field('groups', 'timemodified', $time, array('id' => $groupid));
$group->timemodified = $time;
//trigger groups events
$eventdata = new stdClass();
$eventdata->groupid = $groupid;
$eventdata->userid = $userid;
events_trigger('groups_member_removed', $eventdata);
// Trigger group event.
$params = array(
'context' => context_course::instance($group->courseid),
'objectid' => $groupid,
'relateduserid' => $userid
);
$event = \core\event\group_member_removed::create($params);
$event->add_record_snapshot('groups', $group);
$event->trigger();
return true;
}
@ -257,8 +269,14 @@ function groups_create_group($data, $editform = false, $editoroptions = false) {
// Invalidate the grouping cache for the course
cache_helper::invalidate_by_definition('core', 'groupdata', array(), array($course->id));
//trigger groups events
events_trigger('groups_group_created', $group);
// Trigger group event.
$params = array(
'context' => $context,
'objectid' => $group->id
);
$event = \core\event\group_created::create($params);
$event->add_record_snapshot('groups', $group);
$event->trigger();
return $group->id;
}
@ -289,8 +307,6 @@ function groups_create_grouping($data, $editoroptions=null) {
}
$id = $DB->insert_record('groupings', $data);
//trigger groups events
$data->id = $id;
if ($editoroptions !== null) {
@ -304,7 +320,14 @@ function groups_create_grouping($data, $editoroptions=null) {
// Invalidate the grouping cache for the course
cache_helper::invalidate_by_definition('core', 'groupdata', array(), array($data->courseid));
events_trigger('groups_grouping_created', $data);
// Trigger group event.
$params = array(
'context' => context_course::instance($data->courseid),
'objectid' => $id
);
$event = \core\event\grouping_created::create($params);
$event->set_legacy_eventdata($data);
$event->trigger();
return $id;
}
@ -376,9 +399,14 @@ function groups_update_group($data, $editform = false, $editoroptions = false) {
groups_update_group_icon($group, $data, $editform);
}
//trigger groups events
events_trigger('groups_group_updated', $group);
// Trigger group event.
$params = array(
'context' => $context,
'objectid' => $group->id
);
$event = \core\event\group_updated::create($params);
$event->add_record_snapshot('groups', $group);
$event->trigger();
return true;
}
@ -408,8 +436,14 @@ function groups_update_grouping($data, $editoroptions=null) {
// Invalidate the group data.
cache_helper::invalidate_by_definition('core', 'groupdata', array(), array($data->courseid));
//trigger groups events
events_trigger('groups_grouping_updated', $data);
// Trigger group event.
$params = array(
'context' => context_course::instance($data->courseid),
'objectid' => $data->id
);
$event = \core\event\grouping_updated::create($params);
$event->set_legacy_eventdata($data);
$event->trigger();
return true;
}
@ -454,8 +488,14 @@ function groups_delete_group($grouporid) {
// Invalidate the grouping cache for the course
cache_helper::invalidate_by_definition('core', 'groupdata', array(), array($group->courseid));
//trigger groups events
events_trigger('groups_group_deleted', $group);
// Trigger group event.
$params = array(
'context' => $context,
'objectid' => $groupid
);
$event = \core\event\group_deleted::create($params);
$event->add_record_snapshot('groups', $group);
$event->trigger();
return true;
}
@ -499,8 +539,14 @@ function groups_delete_grouping($groupingorid) {
// Invalidate the grouping cache for the course
cache_helper::invalidate_by_definition('core', 'groupdata', array(), array($grouping->courseid));
//trigger groups events
events_trigger('groups_grouping_deleted', $grouping);
// Trigger group event.
$params = array(
'context' => $context,
'objectid' => $groupingid
);
$event = \core\event\grouping_deleted::create($params);
$event->add_record_snapshot('groupings', $grouping);
$event->trigger();
return true;
}
@ -521,23 +567,27 @@ function groups_delete_group_members($courseid, $userid=0, $showfeedback=false)
return false;
}
$params = array('courseid'=>$courseid);
// Select * so that the function groups_remove_member() gets the whole record.
$groups = $DB->get_recordset('groups', array('courseid' => $courseid));
foreach ($groups as $group) {
if ($userid) {
$userids = array($userid);
} else {
$userids = $DB->get_fieldset_select('groups_members', 'userid', 'groupid = :groupid', array('groupid' => $group->id));
}
if ($userid) {
$usersql = "AND userid = :userid";
$params['userid'] = $userid;
} else {
$usersql = "";
foreach ($userids as $id) {
groups_remove_member($group, $id);
}
}
$groupssql = "SELECT id FROM {groups} g WHERE g.courseid = :courseid";
$DB->delete_records_select('groups_members', "groupid IN ($groupssql) $usersql", $params);
//trigger groups events
// TODO MDL-41312 Remove events_trigger_legacy('groups_members_removed').
// This event is kept here for backwards compatibility, because it cannot be
// translated to a new event as it is wrong.
$eventdata = new stdClass();
$eventdata->courseid = $courseid;
$eventdata->userid = $userid;
events_trigger('groups_members_removed', $eventdata);
events_trigger_legacy('groups_members_removed', $eventdata);
if ($showfeedback) {
echo $OUTPUT->notification(get_string('deleted').' - '.get_string('groupmembers', 'group'), 'notifysuccess');
@ -557,13 +607,20 @@ function groups_delete_groupings_groups($courseid, $showfeedback=false) {
global $DB, $OUTPUT;
$groupssql = "SELECT id FROM {groups} g WHERE g.courseid = ?";
$DB->delete_records_select('groupings_groups', "groupid IN ($groupssql)", array($courseid));
$results = $DB->get_recordset_select('groupings_groups', "groupid IN ($groupssql)",
array($courseid), '', 'groupid, groupingid');
foreach ($results as $result) {
groups_unassign_grouping($result->groupingid, $result->groupid, false);
}
// Invalidate the grouping cache for the course
cache_helper::invalidate_by_definition('core', 'groupdata', array(), array($courseid));
//trigger groups events
events_trigger('groups_groupings_groups_removed', $courseid);
// TODO MDL-41312 Remove events_trigger_legacy('groups_groupings_groups_removed').
// This event is kept here for backwards compatibility, because it cannot be
// translated to a new event as it is wrong.
events_trigger_legacy('groups_groupings_groups_removed', $courseid);
// no need to show any feedback here - we delete usually first groupings and then groups
@ -580,31 +637,18 @@ function groups_delete_groupings_groups($courseid, $showfeedback=false) {
function groups_delete_groups($courseid, $showfeedback=false) {
global $CFG, $DB, $OUTPUT;
// delete any uses of groups
// Any associated files are deleted as part of groups_delete_groupings_groups
groups_delete_groupings_groups($courseid, $showfeedback);
groups_delete_group_members($courseid, 0, $showfeedback);
// delete group pictures and descriptions
$context = context_course::instance($courseid);
$fs = get_file_storage();
$fs->delete_area_files($context->id, 'group');
// delete group calendar events
$groupssql = "SELECT id FROM {groups} g WHERE g.courseid = ?";
$DB->delete_records_select('event', "groupid IN ($groupssql)", array($courseid));
$context = context_course::instance($courseid);
$fs = get_file_storage();
$fs->delete_area_files($context->id, 'group');
$DB->delete_records('groups', array('courseid'=>$courseid));
$groups = $DB->get_recordset('groups', array('courseid' => $courseid));
foreach ($groups as $group) {
groups_delete_group($group);
}
// Invalidate the grouping cache for the course
cache_helper::invalidate_by_definition('core', 'groupdata', array(), array($courseid));
// trigger groups events
events_trigger('groups_groups_deleted', $courseid);
// TODO MDL-41312 Remove events_trigger_legacy('groups_groups_deleted').
// This event is kept here for backwards compatibility, because it cannot be
// translated to a new event as it is wrong.
events_trigger_legacy('groups_groups_deleted', $courseid);
if ($showfeedback) {
echo $OUTPUT->notification(get_string('deleted').' - '.get_string('groups', 'group'), 'notifysuccess');
@ -623,28 +667,18 @@ function groups_delete_groups($courseid, $showfeedback=false) {
function groups_delete_groupings($courseid, $showfeedback=false) {
global $DB, $OUTPUT;
// delete any uses of groupings
$sql = "DELETE FROM {groupings_groups}
WHERE groupingid in (SELECT id FROM {groupings} g WHERE g.courseid = ?)";
$DB->execute($sql, array($courseid));
$groupings = $DB->get_recordset_select('groupings', 'courseid = ?', array($courseid));
foreach ($groupings as $grouping) {
groups_delete_grouping($grouping);
}
// remove the default groupingid from course
$DB->set_field('course', 'defaultgroupingid', 0, array('id'=>$courseid));
// remove the groupingid from all course modules
$DB->set_field('course_modules', 'groupingid', 0, array('course'=>$courseid));
// Delete all files associated with groupings for this course
$context = context_course::instance($courseid);
$fs = get_file_storage();
$fs->delete_area_files($context->id, 'grouping');
$DB->delete_records('groupings', array('courseid'=>$courseid));
// Invalidate the grouping cache for the course
// Invalidate the grouping cache for the course.
cache_helper::invalidate_by_definition('core', 'groupdata', array(), array($courseid));
// trigger groups events
events_trigger('groups_groupings_deleted', $courseid);
// TODO MDL-41312 Remove events_trigger_legacy('groups_groupings_deleted').
// This event is kept here for backwards compatibility, because it cannot be
// translated to a new event as it is wrong.
events_trigger_legacy('groups_groupings_deleted', $courseid);
if ($showfeedback) {
echo $OUTPUT->notification(get_string('deleted').' - '.get_string('groupings', 'group'), 'notifysuccess');

385
group/tests/lib_test.php Normal file
View File

@ -0,0 +1,385 @@
<?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/>.
/**
* Unit tests for group lib.
*
* @package core_group
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/group/lib.php');
/**
* Group lib testcase.
*
* @package core_group
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_group_lib_testcase extends advanced_testcase {
public function test_member_added_event() {
$this->resetAfterTest();
$this->setAdminUser();
$course = $this->getDataGenerator()->create_course();
$user = $this->getDataGenerator()->create_user();
$group = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
$this->getDataGenerator()->enrol_user($user->id, $course->id);
$sink = $this->redirectEvents();
groups_add_member($group->id, $user->id, 'mod_workshop', '123');
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$expected = new stdClass();
$expected->groupid = $group->id;
$expected->userid = $user->id;
$expected->component = 'mod_workshop';
$expected->itemid = '123';
$this->assertEventLegacyData($expected, $event);
$this->assertSame('groups_member_added', $event->get_legacy_eventname());
$this->assertInstanceOf('\core\event\group_member_added', $event);
$this->assertEquals($user->id, $event->relateduserid);
$this->assertEquals(context_course::instance($course->id), $event->get_context());
$this->assertEquals($group->id, $event->objectid);
}
public function test_member_removed_event() {
$this->resetAfterTest();
$this->setAdminUser();
$course = $this->getDataGenerator()->create_course();
$user = $this->getDataGenerator()->create_user();
$group = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
$this->getDataGenerator()->enrol_user($user->id, $course->id);
$this->getDataGenerator()->create_group_member(array('userid' => $user->id, 'groupid' => $group->id));
$sink = $this->redirectEvents();
groups_remove_member($group->id, $user->id);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$expected = new stdClass();
$expected->groupid = $group->id;
$expected->userid = $user->id;
$this->assertEventLegacyData($expected, $event);
$this->assertSame('groups_member_removed', $event->get_legacy_eventname());
$this->assertInstanceOf('\core\event\group_member_removed', $event);
$this->assertEquals($user->id, $event->relateduserid);
$this->assertEquals(context_course::instance($course->id), $event->get_context());
$this->assertEquals($group->id, $event->objectid);
}
public function test_group_created_event() {
$this->resetAfterTest();
$this->setAdminUser();
$course = $this->getDataGenerator()->create_course();
$sink = $this->redirectEvents();
$group = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\core\event\group_created', $event);
$this->assertEventLegacyData($group, $event);
$this->assertSame('groups_group_created', $event->get_legacy_eventname());
$this->assertEquals(context_course::instance($course->id), $event->get_context());
$this->assertEquals($group->id, $event->objectid);
}
public function test_grouping_created_event() {
$this->resetAfterTest();
$this->setAdminUser();
$course = $this->getDataGenerator()->create_course();
$sink = $this->redirectEvents();
$group = $this->getDataGenerator()->create_grouping(array('courseid' => $course->id));
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\core\event\grouping_created', $event);
// 'Repairing' the object for comparison because of type of variables being wrong.
$group->id = (int) $group->id;
$group->timemodified = (int) $group->timemodified;
$group->timecreated = (int) $group->timecreated;
unset($group->idnumber);
unset($group->configdata);
$this->assertEventLegacyData($group, $event);
$this->assertSame('groups_grouping_created', $event->get_legacy_eventname());
$this->assertEquals(context_course::instance($course->id), $event->get_context());
$this->assertEquals($group->id, $event->objectid);
}
public function test_group_updated_event() {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$group = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
$sink = $this->redirectEvents();
$data = new stdClass();
$data->id = $group->id;
$data->courseid = $course->id;
$data->name = 'Backend team';
groups_update_group($data);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\core\event\group_updated', $event);
$group->name = $data->name;
$this->assertEventLegacyData($group, $event);
$this->assertSame('groups_group_updated', $event->get_legacy_eventname());
$this->assertEquals(context_course::instance($course->id), $event->get_context());
$this->assertEquals($group->id, $event->objectid);
}
public function test_grouping_updated_event() {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$group = $this->getDataGenerator()->create_grouping(array('courseid' => $course->id));
$sink = $this->redirectEvents();
$data = new stdClass();
$data->id = $group->id;
$data->courseid = $course->id;
$data->name = 'Backend team';
$mostaccuratetimemodified = time();
groups_update_grouping($data);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\core\event\grouping_updated', $event);
// 'Repairing' the object for comparison because of type of variables being wrong.
$data->id = (int) $group->id;
$data->timemodified = $mostaccuratetimemodified;
$this->assertEventLegacyData($data, $event);
$this->assertSame('groups_grouping_updated', $event->get_legacy_eventname());
$this->assertEquals(context_course::instance($course->id), $event->get_context());
$this->assertEquals($group->id, $event->objectid);
}
public function test_group_deleted_event() {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$group = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
$sink = $this->redirectEvents();
groups_delete_group($group->id);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\core\event\group_deleted', $event);
$this->assertEventLegacyData($group, $event);
$this->assertSame('groups_group_deleted', $event->get_legacy_eventname());
$this->assertEquals(context_course::instance($course->id), $event->get_context());
$this->assertEquals($group->id, $event->objectid);
}
public function test_grouping_deleted_event() {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$group = $this->getDataGenerator()->create_grouping(array('courseid' => $course->id));
$sink = $this->redirectEvents();
groups_delete_grouping($group->id);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\core\event\grouping_deleted', $event);
$this->assertEventLegacyData($group, $event);
$this->assertSame('groups_grouping_deleted', $event->get_legacy_eventname());
$this->assertEquals(context_course::instance($course->id), $event->get_context());
$this->assertEquals($group->id, $event->objectid);
}
public function test_groups_delete_group_members() {
global $DB;
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($user1->id, $course->id);
$this->getDataGenerator()->enrol_user($user2->id, $course->id);
$group1 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
$group2 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
// Test deletion of all the users.
$this->getDataGenerator()->create_group_member(array('groupid' => $group1->id, 'userid' => $user1->id));
$this->getDataGenerator()->create_group_member(array('groupid' => $group2->id, 'userid' => $user1->id));
$this->getDataGenerator()->create_group_member(array('groupid' => $group1->id, 'userid' => $user2->id));
$this->assertTrue($DB->record_exists('groups_members', array('groupid' => $group1->id, 'userid' => $user1->id)));
$this->assertTrue($DB->record_exists('groups_members', array('groupid' => $group2->id, 'userid' => $user1->id)));
$this->assertTrue($DB->record_exists('groups_members', array('groupid' => $group1->id, 'userid' => $user2->id)));
groups_delete_group_members($course->id);
$this->assertFalse($DB->record_exists('groups_members', array('groupid' => $group1->id, 'userid' => $user1->id)));
$this->assertFalse($DB->record_exists('groups_members', array('groupid' => $group2->id, 'userid' => $user1->id)));
$this->assertFalse($DB->record_exists('groups_members', array('groupid' => $group1->id, 'userid' => $user2->id)));
// Test deletion of a specific user.
$this->getDataGenerator()->create_group_member(array('groupid' => $group1->id, 'userid' => $user1->id));
$this->getDataGenerator()->create_group_member(array('groupid' => $group2->id, 'userid' => $user1->id));
$this->getDataGenerator()->create_group_member(array('groupid' => $group1->id, 'userid' => $user2->id));
$this->assertTrue($DB->record_exists('groups_members', array('groupid' => $group1->id, 'userid' => $user1->id)));
$this->assertTrue($DB->record_exists('groups_members', array('groupid' => $group2->id, 'userid' => $user1->id)));
$this->assertTrue($DB->record_exists('groups_members', array('groupid' => $group1->id, 'userid' => $user2->id)));
groups_delete_group_members($course->id, $user2->id);
$this->assertTrue($DB->record_exists('groups_members', array('groupid' => $group1->id, 'userid' => $user1->id)));
$this->assertTrue($DB->record_exists('groups_members', array('groupid' => $group2->id, 'userid' => $user1->id)));
$this->assertFalse($DB->record_exists('groups_members', array('groupid' => $group1->id, 'userid' => $user2->id)));
}
public function test_groups_remove_member() {
global $DB;
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($user1->id, $course->id);
$this->getDataGenerator()->enrol_user($user2->id, $course->id);
$group1 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
$group2 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
$this->getDataGenerator()->create_group_member(array('groupid' => $group1->id, 'userid' => $user1->id));
$this->getDataGenerator()->create_group_member(array('groupid' => $group2->id, 'userid' => $user1->id));
$this->getDataGenerator()->create_group_member(array('groupid' => $group1->id, 'userid' => $user2->id));
$this->assertTrue($DB->record_exists('groups_members', array('groupid' => $group1->id, 'userid' => $user1->id)));
$this->assertTrue($DB->record_exists('groups_members', array('groupid' => $group2->id, 'userid' => $user1->id)));
$this->assertTrue($DB->record_exists('groups_members', array('groupid' => $group1->id, 'userid' => $user2->id)));
groups_remove_member($group1->id, $user1->id);
$this->assertFalse($DB->record_exists('groups_members', array('groupid' => $group1->id, 'userid' => $user1->id)));
$this->assertTrue($DB->record_exists('groups_members', array('groupid' => $group2->id, 'userid' => $user1->id)));
$this->assertTrue($DB->record_exists('groups_members', array('groupid' => $group1->id, 'userid' => $user2->id)));
groups_remove_member($group1->id, $user2->id);
$this->assertTrue($DB->record_exists('groups_members', array('groupid' => $group2->id, 'userid' => $user1->id)));
$this->assertFalse($DB->record_exists('groups_members', array('groupid' => $group1->id, 'userid' => $user2->id)));
groups_remove_member($group2->id, $user1->id);
$this->assertFalse($DB->record_exists('groups_members', array('groupid' => $group2->id, 'userid' => $user1->id)));
}
public function test_groups_delete_groupings_groups() {
global $DB;
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$course2 = $this->getDataGenerator()->create_course();
$group1 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
$group2 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
$group1c2 = $this->getDataGenerator()->create_group(array('courseid' => $course2->id));
$grouping1 = $this->getDataGenerator()->create_grouping(array('courseid' => $course->id));
$grouping2 = $this->getDataGenerator()->create_grouping(array('courseid' => $course->id));
$grouping1c2 = $this->getDataGenerator()->create_grouping(array('courseid' => $course2->id));
$this->getDataGenerator()->create_grouping_group(array('groupingid' => $grouping1->id, 'groupid' => $group1->id));
$this->getDataGenerator()->create_grouping_group(array('groupingid' => $grouping1->id, 'groupid' => $group2->id));
$this->getDataGenerator()->create_grouping_group(array('groupingid' => $grouping2->id, 'groupid' => $group1->id));
$this->getDataGenerator()->create_grouping_group(array('groupingid' => $grouping1c2->id, 'groupid' => $group1c2->id));
$this->assertTrue($DB->record_exists('groupings_groups', array('groupid' => $group1->id, 'groupingid' => $grouping1->id)));
$this->assertTrue($DB->record_exists('groupings_groups', array('groupid' => $group2->id, 'groupingid' => $grouping1->id)));
$this->assertTrue($DB->record_exists('groupings_groups', array('groupid' => $group1->id, 'groupingid' => $grouping2->id)));
$this->assertTrue($DB->record_exists('groupings_groups',
array('groupid' => $group1c2->id, 'groupingid' => $grouping1c2->id)));
groups_delete_groupings_groups($course->id);
$this->assertFalse($DB->record_exists('groupings_groups', array('groupid' => $group1->id, 'groupingid' => $grouping1->id)));
$this->assertFalse($DB->record_exists('groupings_groups', array('groupid' => $group2->id, 'groupingid' => $grouping1->id)));
$this->assertFalse($DB->record_exists('groupings_groups', array('groupid' => $group1->id, 'groupingid' => $grouping2->id)));
$this->assertTrue($DB->record_exists('groupings_groups',
array('groupid' => $group1c2->id, 'groupingid' => $grouping1c2->id)));
}
public function test_groups_delete_groups() {
global $DB;
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$course2 = $this->getDataGenerator()->create_course();
$group1 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
$group2 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
$group1c2 = $this->getDataGenerator()->create_group(array('courseid' => $course2->id));
$grouping1 = $this->getDataGenerator()->create_grouping(array('courseid' => $course->id));
$grouping2 = $this->getDataGenerator()->create_grouping(array('courseid' => $course->id));
$user1 = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($user1->id, $course->id);
$this->getDataGenerator()->create_group_member(array('groupid' => $group1->id, 'userid' => $user1->id));
$this->getDataGenerator()->create_grouping_group(array('groupid' => $group1->id, 'groupingid' => $grouping1->id));
$this->assertTrue($DB->record_exists('groups', array('id' => $group1->id, 'courseid' => $course->id)));
$this->assertTrue($DB->record_exists('groups', array('id' => $group2->id, 'courseid' => $course->id)));
$this->assertTrue($DB->record_exists('groups', array('id' => $group1c2->id, 'courseid' => $course2->id)));
$this->assertTrue($DB->record_exists('groups_members', array('groupid' => $group1->id, 'userid' => $user1->id)));
$this->assertTrue($DB->record_exists('groupings', array('id' => $grouping1->id, 'courseid' => $course->id)));
$this->assertTrue($DB->record_exists('groupings_groups', array('groupid' => $group1->id, 'groupingid' => $grouping1->id)));
groups_delete_groups($course->id);
$this->assertFalse($DB->record_exists('groups', array('id' => $group1->id, 'courseid' => $course->id)));
$this->assertFalse($DB->record_exists('groups', array('id' => $group2->id, 'courseid' => $course->id)));
$this->assertTrue($DB->record_exists('groups', array('id' => $group1c2->id, 'courseid' => $course2->id)));
$this->assertFalse($DB->record_exists('groups_members', array('groupid' => $group1->id, 'userid' => $user1->id)));
$this->assertTrue($DB->record_exists('groupings', array('id' => $grouping1->id, 'courseid' => $course->id)));
$this->assertFalse($DB->record_exists('groupings_groups', array('groupid' => $group1->id, 'groupingid' => $grouping1->id)));
}
public function test_groups_delete_groupings() {
global $DB;
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$course2 = $this->getDataGenerator()->create_course();
$group1 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
$grouping1 = $this->getDataGenerator()->create_grouping(array('courseid' => $course->id));
$grouping2 = $this->getDataGenerator()->create_grouping(array('courseid' => $course->id));
$grouping1c2 = $this->getDataGenerator()->create_grouping(array('courseid' => $course2->id));
$this->getDataGenerator()->create_grouping_group(array('groupid' => $group1->id, 'groupingid' => $grouping1->id));
$this->assertTrue($DB->record_exists('groups', array('id' => $group1->id, 'courseid' => $course->id)));
$this->assertTrue($DB->record_exists('groupings', array('id' => $grouping1->id, 'courseid' => $course->id)));
$this->assertTrue($DB->record_exists('groupings', array('id' => $grouping2->id, 'courseid' => $course->id)));
$this->assertTrue($DB->record_exists('groupings', array('id' => $grouping1c2->id, 'courseid' => $course2->id)));
$this->assertTrue($DB->record_exists('groupings_groups', array('groupid' => $group1->id, 'groupingid' => $grouping1->id)));
groups_delete_groupings($course->id);
$this->assertTrue($DB->record_exists('groups', array('id' => $group1->id, 'courseid' => $course->id)));
$this->assertFalse($DB->record_exists('groupings', array('id' => $grouping1->id, 'courseid' => $course->id)));
$this->assertFalse($DB->record_exists('groupings', array('id' => $grouping2->id, 'courseid' => $course->id)));
$this->assertTrue($DB->record_exists('groupings', array('id' => $grouping1c2->id, 'courseid' => $course2->id)));
$this->assertFalse($DB->record_exists('groupings_groups', array('groupid' => $group1->id, 'groupingid' => $grouping1->id)));
}
}

View File

@ -67,6 +67,14 @@ $string['errorremovenotpermitted'] = 'You do not have permission to remove autom
$string['errorselectone'] = 'Please select a single group before choosing this option';
$string['errorselectsome'] = 'Please select one or more groups before choosing this option';
$string['evenallocation'] = 'Note: To keep group allocation even, the actual number of members per group differs from the number you specified.';
$string['event_group_created'] = 'Group created';
$string['event_group_deleted'] = 'Group deleted';
$string['event_group_member_added'] = 'Group member added';
$string['event_group_member_removed'] = 'Group member removed';
$string['event_group_updated'] = 'Group updated';
$string['event_grouping_created'] = 'Grouping created';
$string['event_grouping_deleted'] = 'Grouping deleted';
$string['event_grouping_updated'] = 'Grouping updated';
$string['existingmembers'] = 'Existing members: {$a}';
$string['filtergroups'] = 'Filter groups by:';
$string['group'] = 'Group';

View File

@ -0,0 +1,93 @@
<?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/>.
/**
* core_group created event.
*
* @package core_group
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\event;
defined('MOODLE_INTERNAL') || die();
/**
* core_group created event class.
*
* @package core_group
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class group_created extends \core\event\base {
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "User {$this->userid} created the group {$this->objectid}.";
}
/**
* Legacy event data if get_legacy_eventname() is not empty.
*
* @return stdClass
*/
protected function get_legacy_eventdata() {
return $this->get_record_snapshot('groups', $this->objectid);
}
/**
* Return the legacy event name.
*
* @return string
*/
public static function get_legacy_eventname() {
return 'groups_group_created';
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_group_created', 'group');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/group/index.php', array('id' => $this->courseid));
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'c';
$this->data['level'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'groups';
}
}

View File

@ -0,0 +1,93 @@
<?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/>.
/**
* core_group deleted event.
*
* @package core_group
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\event;
defined('MOODLE_INTERNAL') || die();
/**
* core_group deleted event class.
*
* @package core_group
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class group_deleted extends \core\event\base {
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "User {$this->userid} deleted the group {$this->objectid}.";
}
/**
* Legacy event data if get_legacy_eventname() is not empty.
*
* @return stdClass
*/
protected function get_legacy_eventdata() {
return $this->get_record_snapshot('groups', $this->objectid);
}
/**
* Return the legacy event name.
*
* @return string
*/
public static function get_legacy_eventname() {
return 'groups_group_deleted';
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_group_deleted', 'group');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/group/index.php', array('id' => $this->courseid));
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'd';
$this->data['level'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'groups';
}
}

View File

@ -0,0 +1,110 @@
<?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/>.
/**
* core_group member added event.
*
* @package core_group
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\event;
defined('MOODLE_INTERNAL') || die();
/**
* core_group member added event class.
*
* @package core_group
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class group_member_added extends \core\event\base {
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "User {$this->userid} added user {$this->relateduserid} to group {$this->objectid}.";
}
/**
* Legacy event data if get_legacy_eventname() is not empty.
*
* @return stdClass
*/
protected function get_legacy_eventdata() {
$eventdata = new \stdClass();
$eventdata->groupid = $this->objectid;
$eventdata->userid = $this->relateduserid;
$eventdata->component = $this->other['component'];
$eventdata->itemid = $this->other['itemid'];
return $eventdata;
}
/**
* Return the legacy event name.
*
* @return string
*/
public static function get_legacy_eventname() {
return 'groups_member_added';
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_group_member_added', 'group');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/group/index.php', array('id' => $this->courseid));
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'c';
$this->data['level'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'groups';
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (!isset($this->other['component']) || !isset($this->other['itemid'])) {
throw new \coding_exception('The component and itemid need to be set in $other, even if empty.');
}
}
}

View File

@ -0,0 +1,96 @@
<?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/>.
/**
* core_group member removed event.
*
* @package core_group
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\event;
defined('MOODLE_INTERNAL') || die();
/**
* core_group member removed event class.
*
* @package core_group
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class group_member_removed extends \core\event\base {
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "User {$this->userid} removed user {$this->relateduserid} from group {$this->objectid}.";
}
/**
* Legacy event data if get_legacy_eventname() is not empty.
*
* @return stdClass
*/
protected function get_legacy_eventdata() {
$eventdata = new \stdClass();
$eventdata->groupid = $this->objectid;
$eventdata->userid = $this->relateduserid;
return $eventdata;
}
/**
* Return the legacy event name.
*
* @return string
*/
public static function get_legacy_eventname() {
return 'groups_member_removed';
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_group_member_removed', 'group');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/group/index.php', array('id' => $this->courseid));
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'd';
$this->data['level'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'groups';
}
}

View File

@ -0,0 +1,93 @@
<?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/>.
/**
* core_group updated event.
*
* @package core_group
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\event;
defined('MOODLE_INTERNAL') || die();
/**
* core_group updated event class.
*
* @package core_group
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class group_updated extends \core\event\base {
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "User {$this->userid} updated the group {$this->objectid}.";
}
/**
* Legacy event data if get_legacy_eventname() is not empty.
*
* @return stdClass
*/
protected function get_legacy_eventdata() {
return $this->get_record_snapshot('groups', $this->objectid);
}
/**
* Return the legacy event name.
*
* @return string
*/
public static function get_legacy_eventname() {
return 'groups_group_updated';
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_group_updated', 'group');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/group/index.php', array('id' => $this->courseid));
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'u';
$this->data['level'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'groups';
}
}

View File

@ -0,0 +1,110 @@
<?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/>.
/**
* core_group grouping created event.
*
* @package core_group
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\event;
defined('MOODLE_INTERNAL') || die();
/**
* core_group grouping created event class.
*
* @package core_group
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class grouping_created extends \core\event\base {
/**
* Legacy data.
*
* @var mixed
*/
protected $legacydata;
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "User {$this->userid} created the grouping {$this->objectid}.";
}
/**
* Legacy event data if get_legacy_eventname() is not empty.
*
* @return stdClass
*/
protected function get_legacy_eventdata() {
return $this->legacydata;
}
/**
* Return the legacy event name.
*
* @return string
*/
public static function get_legacy_eventname() {
return 'groups_grouping_created';
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_grouping_created', 'group');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/group/groupings/index.php', array('id' => $this->courseid));
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'c';
$this->data['level'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'groupings';
}
/**
* Set legacy data.
*
* @param mixed $legacydata.
* @return void
*/
public function set_legacy_eventdata($legacydata) {
$this->legacydata = $legacydata;
}
}

View File

@ -0,0 +1,100 @@
<?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/>.
/**
* core_group grouping deleted event.
*
* @package core_group
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\event;
defined('MOODLE_INTERNAL') || die();
/**
* core_group grouping deleted event class.
*
* @package core_group
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class grouping_deleted extends \core\event\base {
/**
* Legacy data.
*
* @var mixed
*/
protected $legacydata;
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "User {$this->userid} deleted the grouping {$this->objectid}.";
}
/**
* Legacy event data if get_legacy_eventname() is not empty.
*
* @return stdClass
*/
protected function get_legacy_eventdata() {
return $this->get_record_snapshot('groupings', $this->objectid);
}
/**
* Return the legacy event name.
*
* @return string
*/
public static function get_legacy_eventname() {
return 'groups_grouping_deleted';
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_grouping_deleted', 'group');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/group/groupings/index.php', array('id' => $this->courseid));
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'd';
$this->data['level'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'groupings';
}
}

View File

@ -0,0 +1,110 @@
<?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/>.
/**
* core_group grouping updated event.
*
* @package core_group
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\event;
defined('MOODLE_INTERNAL') || die();
/**
* core_group grouping updated event class.
*
* @package core_group
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class grouping_updated extends \core\event\base {
/**
* Legacy data.
*
* @var mixed
*/
protected $legacydata;
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "User {$this->userid} updated the grouping {$this->objectid}.";
}
/**
* Legacy event data if get_legacy_eventname() is not empty.
*
* @return stdClass
*/
protected function get_legacy_eventdata() {
return $this->legacydata;
}
/**
* Return the legacy event name.
*
* @return string
*/
public static function get_legacy_eventname() {
return 'groups_grouping_updated';
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_grouping_updated', 'group');
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/group/groupings/index.php', array('id' => $this->courseid));
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'u';
$this->data['level'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'groupings';
}
/**
* Set legacy data.
*
* @param mixed $legacydata.
* @return void
*/
public function set_legacy_eventdata($legacydata) {
$this->legacydata = $legacydata;
}
}

View File

@ -104,6 +104,12 @@ Event triggering and event handlers:
* All existing events and event handlers should be replaced by new
event classes and matching new event observers.
* See http://docs.moodle.org/dev/Event_2 for more information.
* The following events will be entirely removed, though they can still
be captured using handlers, but they should not be used any more.
* groups_members_removed -> \core\event\group_member_removed
* groups_groupings_groups_removed -> (no replacement)
* groups_groups_deleted -> \core\event\group_deleted
* groups_groupings_deleted -> \core\event\grouping_deleted
=== 2.5.1 ===