MDL-44403 events: added public method to get eventdata

This commit is contained in:
Marina Glancy 2014-02-28 16:11:15 +08:00
parent 76e4de31cc
commit 24c32bdf2f
10 changed files with 85 additions and 73 deletions

View file

@ -37,8 +37,8 @@ defined('MOODLE_INTERNAL') || die();
*/
class blog_entry_created extends \core\event\base {
/** @var \blog_entry A reference to the active blog_entry object. */
protected $customobject;
/** @var \blog_entry A reference to the active blog_entry object. */
protected $blogentry;
/**
* Set basic properties for the event.
@ -51,12 +51,24 @@ class blog_entry_created extends \core\event\base {
}
/**
* Set custom data of the event.
* Set blog_entry object to be used by observers.
*
* @param \blog_entry $data A reference to the active blog_entry object.
*/
public function set_custom_data(\blog_entry $data) {
$this->customobject = $data;
public function set_blog_entry(\blog_entry $blogentry) {
$this->blogentry = $blogentry;
}
/**
* Returns created blog_entry object for event observers.
*
* @return \blog_entry
*/
public function get_blog_entry() {
if ($this->is_restored()) {
throw new \coding_exception('Function get_blog_entry() can not be used on restored events.');
}
return $this->blogentry;
}
/**
@ -100,7 +112,7 @@ class blog_entry_created extends \core\event\base {
* @return \blog_entry
*/
protected function get_legacy_eventdata() {
return $this->customobject;
return $this->blogentry;
}
/**
@ -110,6 +122,6 @@ class blog_entry_created extends \core\event\base {
*/
protected function get_legacy_logdata() {
return array (SITEID, 'blog', 'add', 'index.php?userid=' . $this->relateduserid . '&entryid=' . $this->objectid,
$this->customobject->subject);
$this->blogentry->subject);
}
}

View file

@ -37,7 +37,7 @@ defined('MOODLE_INTERNAL') || die();
class blog_entry_deleted extends \core\event\base {
/** @var \blog_entry A reference to the active blog_entry object. */
protected $customobject;
protected $blogentry;
/**
* Set basic event properties.
@ -59,12 +59,24 @@ class blog_entry_deleted extends \core\event\base {
}
/**
* Set custom data of the event.
* Sets blog_entry object to be used by observers.
*
* @param \blog_entry $data A reference to the active blog_entry object.
*/
public function set_custom_data(\blog_entry $data) {
$this->customobject = $data;
public function set_blog_entry(\blog_entry $blogentry) {
$this->blogentry = $blogentry;
}
/**
* Returns deleted blog entry for event observers.
*
* @return \blog_entry
*/
public function get_blog_entry() {
if ($this->is_restored()) {
throw new \coding_exception('Function get_blog_entry() can not be used on restored events.');
}
return $this->blogentry;
}
/**
@ -91,7 +103,7 @@ class blog_entry_deleted extends \core\event\base {
* @return \blog_entry
*/
protected function get_legacy_eventdata() {
return $this->customobject;
return $this->blogentry;
}
/**

View file

@ -36,7 +36,7 @@ defined('MOODLE_INTERNAL') || die();
class blog_entry_updated extends base {
/** @var \blog_entry A reference to the active blog_entry object. */
protected $customobject;
protected $blogentry;
/**
* Set basic event properties.
@ -49,12 +49,24 @@ class blog_entry_updated extends base {
}
/**
* Set custom data of the event.
* Sets blog_entry object to be used by observers.
*
* @param \blog_entry $data A reference to the active blog_entry object.
*/
public function set_custom_data(\blog_entry $data) {
$this->customobject = $data;
public function set_blog_entry(\blog_entry $blogentry) {
$this->blogentry = $blogentry;
}
/**
* Returns updated blog entry for event observers.
*
* @return \blog_entry
*/
public function get_blog_entry() {
if ($this->is_restored()) {
throw new \coding_exception('Function get_blog_entry() can not be used on restored events.');
}
return $this->blogentry;
}
/**
@ -89,7 +101,7 @@ class blog_entry_updated extends base {
* @return \blog_entry
*/
protected function get_legacy_eventdata() {
return $this->customobject;
return $this->blogentry;
}
/**
@ -108,7 +120,7 @@ class blog_entry_updated extends base {
*/
protected function get_legacy_logdata() {
return array(SITEID, 'blog', 'update', 'index.php?userid=' . $this->relateduserid . '&entryid=' . $this->objectid,
$this->customobject->subject);
$this->blogentry->subject);
}
}

View file

@ -84,12 +84,24 @@ class course_category_deleted extends base {
}
/**
* Set the legacy event data.
* Set custom data of the event - deleted coursecat.
*
* @param coursecat $class instance of the coursecat class
* @param \coursecat $coursecat
*/
public function set_legacy_eventdata($class) {
$this->coursecat = $class;
public function set_coursecat(\coursecat $coursecat) {
$this->coursecat = $coursecat;
}
/**
* Returns deleted coursecat for event observers.
*
* @return \coursecat
*/
public function get_coursecat() {
if ($this->is_restored()) {
throw new \coding_exception('Function get_coursecat() can not be used on restored events.');
}
return $this->coursecat;
}
/**

View file

@ -34,13 +34,6 @@ defined('MOODLE_INTERNAL') || die();
*/
class grouping_created extends \core\event\base {
/**
* Legacy data.
*
* @var mixed
*/
protected $legacydata;
/**
* Returns description of what happened.
*
@ -56,7 +49,7 @@ class grouping_created extends \core\event\base {
* @return stdClass
*/
protected function get_legacy_eventdata() {
return $this->legacydata;
return $this->get_record_snapshot('groupings', $this->objectid);
}
/**
@ -97,14 +90,4 @@ class grouping_created extends \core\event\base {
$this->data['objecttable'] = 'groupings';
}
/**
* Set legacy data.
*
* @param mixed $legacydata.
* @return void
*/
public function set_legacy_eventdata($legacydata) {
$this->legacydata = $legacydata;
}
}

View file

@ -34,13 +34,6 @@ defined('MOODLE_INTERNAL') || die();
*/
class grouping_updated extends \core\event\base {
/**
* Legacy data.
*
* @var mixed
*/
protected $legacydata;
/**
* Returns description of what happened.
*
@ -56,7 +49,7 @@ class grouping_updated extends \core\event\base {
* @return stdClass
*/
protected function get_legacy_eventdata() {
return $this->legacydata;
return $this->get_record_snapshot('groupings', $this->objectid);
}
/**
@ -97,14 +90,4 @@ class grouping_updated extends \core\event\base {
$this->data['objecttable'] = 'groupings';
}
/**
* Set legacy data.
*
* @param mixed $legacydata.
* @return void
*/
public function set_legacy_eventdata($legacydata) {
$this->legacydata = $legacydata;
}
}