mirror of
https://github.com/moodle/moodle.git
synced 2025-06-02 14:15:11 +02:00
MDL-39956 cohort: Convert to new events
* \core\event\cohort_created * \core\event\cohort_updated * \core\event\cohort_deleted * \core\event\cohort_member_added * \core\event\cohort_member_removed
This commit is contained in:
parent
50ff861263
commit
04aee04a25
@ -57,7 +57,12 @@ function cohort_add_cohort($cohort) {
|
||||
|
||||
$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;
|
||||
}
|
||||
@ -76,7 +81,11 @@ function cohort_update_cohort($cohort) {
|
||||
$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();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -94,7 +103,12 @@ function cohort_delete_cohort($cohort) {
|
||||
$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();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -141,7 +155,15 @@ function cohort_add_member($cohortid, $userid) {
|
||||
$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();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,7 +176,15 @@ function cohort_remove_member($cohortid, $userid) {
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
79
lib/classes/event/cohort_created.php
Normal file
79
lib/classes/event/cohort_created.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
79
lib/classes/event/cohort_deleted.php
Normal file
79
lib/classes/event/cohort_deleted.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
82
lib/classes/event/cohort_member_added.php
Normal file
82
lib/classes/event/cohort_member_added.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
82
lib/classes/event/cohort_member_removed.php
Normal file
82
lib/classes/event/cohort_member_removed.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
79
lib/classes/event/cohort_updated.php
Normal file
79
lib/classes/event/cohort_updated.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user