diff --git a/cohort/lib.php b/cohort/lib.php index 66396393168..51ac01c163f 100644 --- a/cohort/lib.php +++ b/cohort/lib.php @@ -85,6 +85,7 @@ function cohort_update_cohort($cohort) { 'context' => context::instance_by_id($cohort->contextid), 'objectid' => $cohort->id, )); + $event->add_record_snapshot('cohort', $cohort); $event->trigger(); } diff --git a/cohort/tests/cohortlib_test.php b/cohort/tests/cohortlib_test.php index 7011258a825..64f40c7e7b6 100644 --- a/cohort/tests/cohortlib_test.php +++ b/cohort/tests/cohortlib_test.php @@ -104,6 +104,8 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { $this->assertEquals('cohort', $event->objecttable); $this->assertEquals($id, $event->objectid); $this->assertEquals($cohort->contextid, $event->contextid); + $this->assertEquals($cohort, $event->get_record_snapshot('cohort', $id)); + $this->assertEventLegacyData($cohort, $event); } public function test_cohort_update_cohort() { @@ -172,6 +174,8 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { $this->assertEquals('cohort', $event->objecttable); $this->assertEquals($updatedcohort->id, $event->objectid); $this->assertEquals($updatedcohort->contextid, $event->contextid); + $this->assertEquals($cohort, $event->get_record_snapshot('cohort', $id)); + $this->assertEventLegacyData($cohort, $event); } public function test_cohort_delete_cohort() { @@ -207,6 +211,8 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { $this->assertInstanceOf('\core\event\cohort_deleted', $event); $this->assertEquals('cohort', $event->objecttable); $this->assertEquals($cohort->id, $event->objectid); + $this->assertEquals($cohort, $event->get_record_snapshot('cohort', $cohort->id)); + $this->assertEventLegacyData($cohort, $event); } public function test_cohort_delete_category() { @@ -240,9 +246,9 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { public function test_cohort_add_member_event() { global $USER; + $this->resetAfterTest(); // Setup the data. - $this->resetAfterTest(); $cohort = $this->getDataGenerator()->create_cohort(); $user = $this->getDataGenerator()->create_user(); @@ -263,6 +269,7 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { $this->assertEquals($cohort->id, $event->objectid); $this->assertEquals($user->id, $event->relateduserid); $this->assertEquals($USER->id, $event->userid); + $this->assertEventLegacyData((object) array('cohortid' => $cohort->id, 'userid' => $user->id), $event); } public function test_cohort_remove_member() { @@ -282,9 +289,9 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { public function test_cohort_remove_member_event() { global $USER; + $this->resetAfterTest(); // Setup the data. - $this->resetAfterTest(); $cohort = $this->getDataGenerator()->create_cohort(); $user = $this->getDataGenerator()->create_user(); cohort_add_member($cohort->id, $user->id); @@ -305,6 +312,7 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { $this->assertEquals($cohort->id, $event->objectid); $this->assertEquals($user->id, $event->relateduserid); $this->assertEquals($USER->id, $event->userid); + $this->assertEventLegacyData((object) array('cohortid' => $cohort->id, 'userid' => $user->id), $event); } public function test_cohort_is_member() { diff --git a/lang/en/cohort.php b/lang/en/cohort.php index ec04a5c9514..44e659929ad 100644 --- a/lang/en/cohort.php +++ b/lang/en/cohort.php @@ -45,6 +45,11 @@ $string['delconfirm'] = 'Do you really want to delete cohort \'{$a}\'?'; $string['description'] = 'Description'; $string['duplicateidnumber'] = 'Cohort with the same ID number already exists'; $string['editcohort'] = 'Edit cohort'; +$string['event_cohort_created'] = 'Cohort created'; +$string['event_cohort_deleted'] = 'Cohort deleted'; +$string['event_cohort_member_added'] = 'User added to a cohort'; +$string['event_cohort_member_removed'] = 'User removed from a cohort'; +$string['event_cohort_updated'] = 'Cohort updated'; $string['external'] = 'External cohort'; $string['idnumber'] = 'Cohort ID'; $string['memberscount'] = 'Cohort size'; diff --git a/lib/classes/event/cohort_created.php b/lib/classes/event/cohort_created.php index d97cc72ebcd..2ea7ad20a39 100644 --- a/lib/classes/event/cohort_created.php +++ b/lib/classes/event/cohort_created.php @@ -14,19 +14,34 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -namespace core\event; - /** - * Cohort created event. + * Cohort updated event. * * @package core * @copyright 2013 Dan Poltawski * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace core\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * Cohort created event class. + * + * @package core + * @copyright 2013 Dan Poltawski + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class cohort_created extends base { + + /** + * Init method. + * + * @return void + */ protected function init() { $this->data['crud'] = 'c'; + // TODO MDL-41040. $this->data['level'] = 50; $this->data['objecttable'] = 'cohort'; } @@ -34,25 +49,24 @@ class cohort_created extends base { /** * Returns localised general event name. * - * @return string|\lang_string + * @return string */ public static function get_name() { - //TODO: localise - return 'Cohort created'; + return get_string('event_cohort_created', 'core_cohort'); } /** - * Returns localised description of what happened. + * Returns description of what happened. * - * @return string|\lang_string + * @return string */ public function get_description() { - //TODO: localise return 'Cohort '.$this->objectid.' was created by '.$this->userid.' at context '.$this->contextid; } /** * Returns relevant URL. + * * @return \moodle_url */ public function get_url() { @@ -60,20 +74,20 @@ class cohort_created extends base { } /** - * Does this event replace legacy event? + * Return legacy event name. * - * @return null|string legacy event name + * @return string legacy event name */ - public function get_legacy_eventname() { + public static function get_legacy_eventname() { return 'cohort_added'; } /** - * Legacy event data if get_legacy_eventname() is not empty. + * Return legacy event data. * - * @return mixed + * @return stdClass */ - public function get_legacy_eventdata() { + protected function get_legacy_eventdata() { return $this->get_record_snapshot('cohort', $this->objectid); } } diff --git a/lib/classes/event/cohort_deleted.php b/lib/classes/event/cohort_deleted.php index af5365ac6af..f2d1f32ecf1 100644 --- a/lib/classes/event/cohort_deleted.php +++ b/lib/classes/event/cohort_deleted.php @@ -14,8 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -namespace core\event; - /** * Cohort deleted event. * @@ -24,9 +22,26 @@ namespace core\event; * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace core\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * Cohort deleted event class. + * + * @package core + * @copyright 2013 Dan Poltawski + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class cohort_deleted extends base { + + /** + * Init method. + * + * @return void + */ protected function init() { $this->data['crud'] = 'd'; + // TODO MDL-41040. $this->data['level'] = 50; $this->data['objecttable'] = 'cohort'; } @@ -34,25 +49,24 @@ class cohort_deleted extends base { /** * Returns localised general event name. * - * @return string|\lang_string + * @return string */ public static function get_name() { - //TODO: localise - return 'Cohort deleted'; + return get_string('event_core_deleted', 'core_cohort'); } /** - * Returns localised description of what happened. + * Returns description of what happened. * - * @return string|\lang_string + * @return string */ public function get_description() { - //TODO: localise return 'Cohort '.$this->objectid.' was deleted by '.$this->userid.' from context '.$this->contextid; } /** * Returns relevant URL. + * * @return \moodle_url */ public function get_url() { @@ -60,20 +74,20 @@ class cohort_deleted extends base { } /** - * Does this event replace legacy event? + * Return legacy event name. * * @return null|string legacy event name */ - public function get_legacy_eventname() { + public static function get_legacy_eventname() { return 'cohort_deleted'; } /** - * Legacy event data if get_legacy_eventname() is not empty. + * Return legacy event data. * - * @return mixed + * @return stdClass */ - public function get_legacy_eventdata() { + protected function get_legacy_eventdata() { return $this->get_record_snapshot('cohort', $this->objectid); } } diff --git a/lib/classes/event/cohort_member_added.php b/lib/classes/event/cohort_member_added.php index 74e03f0c98a..95efb882bd1 100644 --- a/lib/classes/event/cohort_member_added.php +++ b/lib/classes/event/cohort_member_added.php @@ -14,19 +14,34 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -namespace core\event; - /** - * User added to a cohort + * User added to a cohort event. * * @package core * @copyright 2013 Dan Poltawski * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace core\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * User added to a cohort event class. + * + * @package core + * @copyright 2013 Dan Poltawski + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class cohort_member_added extends base { + + /** + * Init method. + * + * @return void + */ protected function init() { $this->data['crud'] = 'c'; + // TODO MDL-41040. $this->data['level'] = 50; $this->data['objecttable'] = 'cohort'; } @@ -34,25 +49,24 @@ class cohort_member_added extends base { /** * Returns localised general event name. * - * @return string|\lang_string + * @return string */ public static function get_name() { - //TODO: localise - return 'User added to a cohort'; + return get_string('event_cohort_member_added', 'core_cohort'); } /** - * Returns localised description of what happened. + * Returns description of what happened. * - * @return string|\lang_string + * @return string */ public function get_description() { - //TODO: localise - return 'User '.$this->relateduserid.' was added to cohort '.$this->objectid.' by:'.$this->userid; + return 'User '.$this->relateduserid.' was added to cohort '.$this->objectid.' by user '.$this->userid; } /** * Returns relevant URL. + * * @return \moodle_url */ public function get_url() { @@ -60,20 +74,20 @@ class cohort_member_added extends base { } /** - * Does this event replace legacy event? + * Return legacy event name. * - * @return null|string legacy event name + * @return string legacy event name. */ - public function get_legacy_eventname() { + public static function get_legacy_eventname() { return 'cohort_member_added'; } /** - * Legacy event data if get_legacy_eventname() is not empty. + * Return legacy event data. * - * @return mixed + * @return stdClass */ - public function get_legacy_eventdata() { + protected function get_legacy_eventdata() { $data = new \stdClass(); $data->cohortid = $this->objectid; $data->userid = $this->relateduserid; diff --git a/lib/classes/event/cohort_member_removed.php b/lib/classes/event/cohort_member_removed.php index 9282672dd3c..e452715960e 100644 --- a/lib/classes/event/cohort_member_removed.php +++ b/lib/classes/event/cohort_member_removed.php @@ -14,10 +14,19 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * User removed from a cohort event. + * + * @package core + * @copyright 2013 Dan Poltawski + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + namespace core\event; +defined('MOODLE_INTERNAL') || die(); /** - * User removed from a cohort + * User removed from a cohort event class. * * @package core * @copyright 2013 Dan Poltawski @@ -25,8 +34,15 @@ namespace core\event; */ class cohort_member_removed extends base { + + /** + * Init method. + * + * @return void + */ protected function init() { - $this->data['crud'] = 'c'; + $this->data['crud'] = 'd'; + // TODO MDL-41040. $this->data['level'] = 50; $this->data['objecttable'] = 'cohort'; } @@ -34,25 +50,24 @@ class cohort_member_removed extends base { /** * Returns localised general event name. * - * @return string|\lang_string + * @return string */ public static function get_name() { - //TODO: localise - return 'User removed from a cohort'; + return get_string('event_cohort_member_removed', 'core_cohort'); } /** - * Returns localised description of what happened. + * Returns description of what happened. * - * @return string|\lang_string + * @return string */ public function get_description() { - //TODO: localise - return 'User '.$this->relateduserid.' was removed from cohort '.$this->objectid.' by: '.$this->userid; + return 'User '.$this->relateduserid.' was removed from cohort '.$this->objectid.' by user '.$this->userid; } /** * Returns relevant URL. + * * @return \moodle_url */ public function get_url() { @@ -60,20 +75,20 @@ class cohort_member_removed extends base { } /** - * Does this event replace legacy event? + * Return legacy event name. * - * @return null|string legacy event name + * @return string legacy event name. */ - public function get_legacy_eventname() { + public static function get_legacy_eventname() { return 'cohort_member_removed'; } /** - * Legacy event data if get_legacy_eventname() is not empty. + * Return legacy event data. * - * @return mixed + * @return stdClass */ - public function get_legacy_eventdata() { + protected function get_legacy_eventdata() { $data = new \stdClass(); $data->cohortid = $this->objectid; $data->userid = $this->relateduserid; diff --git a/lib/classes/event/cohort_updated.php b/lib/classes/event/cohort_updated.php index cf334114729..b36bc451684 100644 --- a/lib/classes/event/cohort_updated.php +++ b/lib/classes/event/cohort_updated.php @@ -14,8 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -namespace core\event; - /** * Cohort updated event. * @@ -24,9 +22,26 @@ namespace core\event; * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace core\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * Cohort updated event class. + * + * @package core + * @copyright 2013 Dan Poltawski + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class cohort_updated extends base { + + /** + * Init method. + * + * @return void + */ protected function init() { $this->data['crud'] = 'u'; + // TODO MDL-41040. $this->data['level'] = 50; $this->data['objecttable'] = 'cohort'; } @@ -34,25 +49,24 @@ class cohort_updated extends base { /** * Returns localised general event name. * - * @return string|\lang_string + * @return string */ public static function get_name() { - //TODO: localise - return 'Cohort updated'; + return get_string('event_cohort_updated', 'core_cohort'); } /** - * Returns localised description of what happened. + * Returns description of what happened. * - * @return string|\lang_string + * @return string */ public function get_description() { - //TODO: localise return 'Cohort '.$this->objectid.' was updated by '.$this->userid.' at context '.$this->contextid; } /** * Returns relevant URL. + * * @return \moodle_url */ public function get_url() { @@ -60,20 +74,20 @@ class cohort_updated extends base { } /** - * Does this event replace legacy event? + * Return legacy event name. * - * @return null|string legacy event name + * @return string legacy event name. */ - public function get_legacy_eventname() { + public static function get_legacy_eventname() { return 'cohort_updated'; } /** - * Legacy event data if get_legacy_eventname() is not empty. + * Return legacy event data. * - * @return mixed + * @return stdClass */ - public function get_legacy_eventdata() { + protected function get_legacy_eventdata() { return $this->get_record_snapshot('cohort', $this->objectid); } }