$cohort->id = $DB->insert_record('cohort', $cohort);
- events_trigger('cohort_added', $cohort);
+ $event = \core\event\cohort_created::create(array(
+ 'context' => context::instance_by_id($cohort->contextid),
+ 'objectid' => $cohort->id,
+ ));
+ $event->add_record_snapshot('cohort', $cohort);
+ $event->trigger();
return $cohort->id;
}
$cohort->timemodified = time();
$DB->update_record('cohort', $cohort);
- events_trigger('cohort_updated', $cohort);
+ $event = \core\event\cohort_updated::create(array(
+ 'context' => context::instance_by_id($cohort->contextid),
+ 'objectid' => $cohort->id,
+ ));
+ $event->trigger();
}
/**
$DB->delete_records('cohort_members', array('cohortid'=>$cohort->id));
$DB->delete_records('cohort', array('id'=>$cohort->id));
- events_trigger('cohort_deleted', $cohort);
+ $event = \core\event\cohort_deleted::create(array(
+ 'context' => context::instance_by_id($cohort->contextid),
+ 'objectid' => $cohort->id,
+ ));
+ $event->add_record_snapshot('cohort', $cohort);
+ $event->trigger();
}
/**
$record->timeadded = time();
$DB->insert_record('cohort_members', $record);
- events_trigger('cohort_member_added', (object)array('cohortid'=>$cohortid, 'userid'=>$userid));
+ $cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
+
+ $event = \core\event\cohort_member_added::create(array(
+ 'context' => context::instance_by_id($cohort->contextid),
+ 'objectid' => $cohortid,
+ 'relateduserid' => $userid,
+ ));
+ $event->add_record_snapshot('cohort', $cohort);
+ $event->trigger();
}
/**
global $DB;
$DB->delete_records('cohort_members', array('cohortid'=>$cohortid, 'userid'=>$userid));
- events_trigger('cohort_member_removed', (object)array('cohortid'=>$cohortid, 'userid'=>$userid));
+ $cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
+
+ $event = \core\event\cohort_member_removed::create(array(
+ 'context' => context::instance_by_id($cohort->contextid),
+ 'objectid' => $cohortid,
+ 'relateduserid' => $userid,
+ ));
+ $event->add_record_snapshot('cohort', $cohort);
+ $event->trigger();
}
/**
--- /dev/null
+<?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/>.
+
+namespace core\event;
+
+/**
+ * Cohort created event.
+ *
+ * @package core
+ * @copyright 2013 Dan Poltawski <dan@moodle.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+class cohort_created extends base {
+ protected function init() {
+ $this->data['crud'] = 'c';
+ $this->data['level'] = 50;
+ $this->data['objecttable'] = 'cohort';
+ }
+
+ /**
+ * Returns localised general event name.
+ *
+ * @return string|\lang_string
+ */
+ public static function get_name() {
+ //TODO: localise
+ return 'Cohort created';
+ }
+
+ /**
+ * Returns localised description of what happened.
+ *
+ * @return string|\lang_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() {
+ return new \moodle_url('/cohort/index.php', array('contextid' => $this->contextid));
+ }
+
+ /**
+ * Does this event replace legacy event?
+ *
+ * @return null|string legacy event name
+ */
+ public function get_legacy_eventname() {
+ return 'cohort_added';
+ }
+
+ /**
+ * Legacy event data if get_legacy_eventname() is not empty.
+ *
+ * @return mixed
+ */
+ public function get_legacy_eventdata() {
+ return $this->get_record_snapshot('cohort', $this->objectid);
+ }
+}
--- /dev/null
+<?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/>.
+
+namespace core\event;
+
+/**
+ * Cohort deleted event.
+ *
+ * @package core
+ * @copyright 2013 Dan Poltawski <dan@moodle.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+class cohort_deleted extends base {
+ protected function init() {
+ $this->data['crud'] = 'd';
+ $this->data['level'] = 50;
+ $this->data['objecttable'] = 'cohort';
+ }
+
+ /**
+ * Returns localised general event name.
+ *
+ * @return string|\lang_string
+ */
+ public static function get_name() {
+ //TODO: localise
+ return 'Cohort deleted';
+ }
+
+ /**
+ * Returns localised description of what happened.
+ *
+ * @return string|\lang_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() {
+ return new \moodle_url('/cohort/index.php', array('contextid' => $this->contextid));
+ }
+
+ /**
+ * Does this event replace legacy event?
+ *
+ * @return null|string legacy event name
+ */
+ public function get_legacy_eventname() {
+ return 'cohort_deleted';
+ }
+
+ /**
+ * Legacy event data if get_legacy_eventname() is not empty.
+ *
+ * @return mixed
+ */
+ public function get_legacy_eventdata() {
+ return $this->get_record_snapshot('cohort', $this->objectid);
+ }
+}
--- /dev/null
+<?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/>.
+
+namespace core\event;
+
+/**
+ * User added to a cohort
+ *
+ * @package core
+ * @copyright 2013 Dan Poltawski <dan@moodle.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+class cohort_member_added extends base {
+ protected function init() {
+ $this->data['crud'] = 'c';
+ $this->data['level'] = 50;
+ $this->data['objecttable'] = 'cohort';
+ }
+
+ /**
+ * Returns localised general event name.
+ *
+ * @return string|\lang_string
+ */
+ public static function get_name() {
+ //TODO: localise
+ return 'User added to a cohort';
+ }
+
+ /**
+ * Returns localised description of what happened.
+ *
+ * @return string|\lang_string
+ */
+ public function get_description() {
+ //TODO: localise
+ return 'User '.$this->relateduserid.' was added to cohort '.$this->objectid.' by:'.$this->userid;
+ }
+
+ /**
+ * Returns relevant URL.
+ * @return \moodle_url
+ */
+ public function get_url() {
+ return new \moodle_url('/cohort/assign.php', array('id' => $this->objectid));
+ }
+
+ /**
+ * Does this event replace legacy event?
+ *
+ * @return null|string legacy event name
+ */
+ public function get_legacy_eventname() {
+ return 'cohort_member_added';
+ }
+
+ /**
+ * Legacy event data if get_legacy_eventname() is not empty.
+ *
+ * @return mixed
+ */
+ public function get_legacy_eventdata() {
+ $data = new \stdClass();
+ $data->cohortid = $this->objectid;
+ $data->userid = $this->relateduserid;
+ return $data;
+ }
+}
--- /dev/null
+<?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/>.
+
+namespace core\event;
+
+/**
+ * User removed from a cohort
+ *
+ * @package core
+ * @copyright 2013 Dan Poltawski <dan@moodle.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+class cohort_member_removed extends base {
+ protected function init() {
+ $this->data['crud'] = 'c';
+ $this->data['level'] = 50;
+ $this->data['objecttable'] = 'cohort';
+ }
+
+ /**
+ * Returns localised general event name.
+ *
+ * @return string|\lang_string
+ */
+ public static function get_name() {
+ //TODO: localise
+ return 'User removed from a cohort';
+ }
+
+ /**
+ * Returns localised description of what happened.
+ *
+ * @return string|\lang_string
+ */
+ public function get_description() {
+ //TODO: localise
+ return 'User '.$this->relateduserid.' was removed from cohort '.$this->objectid.' by: '.$this->userid;
+ }
+
+ /**
+ * Returns relevant URL.
+ * @return \moodle_url
+ */
+ public function get_url() {
+ return new \moodle_url('/cohort/assign.php', array('id' => $this->objectid));
+ }
+
+ /**
+ * Does this event replace legacy event?
+ *
+ * @return null|string legacy event name
+ */
+ public function get_legacy_eventname() {
+ return 'cohort_member_removed';
+ }
+
+ /**
+ * Legacy event data if get_legacy_eventname() is not empty.
+ *
+ * @return mixed
+ */
+ public function get_legacy_eventdata() {
+ $data = new \stdClass();
+ $data->cohortid = $this->objectid;
+ $data->userid = $this->relateduserid;
+ return $data;
+ }
+}
--- /dev/null
+<?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/>.
+
+namespace core\event;
+
+/**
+ * Cohort updated event.
+ *
+ * @package core
+ * @copyright 2013 Dan Poltawski <dan@moodle.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+class cohort_updated extends base {
+ protected function init() {
+ $this->data['crud'] = 'u';
+ $this->data['level'] = 50;
+ $this->data['objecttable'] = 'cohort';
+ }
+
+ /**
+ * Returns localised general event name.
+ *
+ * @return string|\lang_string
+ */
+ public static function get_name() {
+ //TODO: localise
+ return 'Cohort updated';
+ }
+
+ /**
+ * Returns localised description of what happened.
+ *
+ * @return string|\lang_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() {
+ return new \moodle_url('/cohort/edit.php', array('id' => $this->objectid));
+ }
+
+ /**
+ * Does this event replace legacy event?
+ *
+ * @return null|string legacy event name
+ */
+ public function get_legacy_eventname() {
+ return 'cohort_updated';
+ }
+
+ /**
+ * Legacy event data if get_legacy_eventname() is not empty.
+ *
+ * @return mixed
+ */
+ public function get_legacy_eventdata() {
+ return $this->get_record_snapshot('cohort', $this->objectid);
+ }
+}