MDL-41040 event: Level property uses defined event constants
This commit is contained in:
@@ -49,7 +49,7 @@ abstract class assessable_submitted extends \core\event\base {
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'u';
|
||||
$this->data['level'] = 50; // TODO MDL-37658.
|
||||
$this->data['level'] = self::LEVEL_PARTICIPATING;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,7 +49,7 @@ abstract class assessable_uploaded extends \core\event\base {
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['level'] = 50; // TODO MDL-37658.
|
||||
$this->data['level'] = self::LEVEL_PARTICIPATING;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,6 +50,27 @@ namespace core\event;
|
||||
* @property-read int $timecreated
|
||||
*/
|
||||
abstract class base implements \IteratorAggregate {
|
||||
|
||||
/**
|
||||
* Other level.
|
||||
*/
|
||||
const LEVEL_OTHER = 0;
|
||||
|
||||
/**
|
||||
* Teaching level.
|
||||
*
|
||||
* Any event that is performed by someone (typically a teacher) and has a teaching value,
|
||||
* anything that is affecting the learning experience/environment of the students.
|
||||
*/
|
||||
const LEVEL_TEACHING = 1;
|
||||
|
||||
/**
|
||||
* Participating level.
|
||||
*
|
||||
* Any event that is performed by a user, and is related (or could be related) to his learning experience.
|
||||
*/
|
||||
const LEVEL_PARTICIPATING = 2;
|
||||
|
||||
/** @var array event data */
|
||||
protected $data;
|
||||
|
||||
@@ -208,8 +229,8 @@ abstract class base implements \IteratorAggregate {
|
||||
* Override in subclass.
|
||||
*
|
||||
* Set all required data properties:
|
||||
* 1/ crud - letter [crud] TODO: MDL-37658
|
||||
* 2/ level - number 1...100 TODO: MDL-37658
|
||||
* 1/ crud - letter [crud]
|
||||
* 2/ level - using a constant self::LEVEL_*.
|
||||
* 3/ objecttable - name of database table if objectid specified
|
||||
*
|
||||
* Optionally it can set:
|
||||
@@ -346,7 +367,7 @@ abstract class base implements \IteratorAggregate {
|
||||
/**
|
||||
* Return auxiliary data that was stored in logs.
|
||||
*
|
||||
* TODO: MDL-37658
|
||||
* TODO MDL-41331: Properly define this method once logging is finalised.
|
||||
*
|
||||
* @return array the format is standardised by logging API
|
||||
*/
|
||||
@@ -400,7 +421,7 @@ abstract class base implements \IteratorAggregate {
|
||||
if (empty($this->data['crud'])) {
|
||||
throw new \coding_exception('crud must be specified in init() method of each method');
|
||||
}
|
||||
if (empty($this->data['level'])) {
|
||||
if (!isset($this->data['level'])) {
|
||||
throw new \coding_exception('level must be specified in init() method of each method');
|
||||
}
|
||||
if (!empty($this->data['objectid']) and empty($this->data['objecttable'])) {
|
||||
@@ -414,8 +435,9 @@ abstract class base implements \IteratorAggregate {
|
||||
if (!in_array($this->data['crud'], array('c', 'r', 'u', 'd'), true)) {
|
||||
debugging("Invalid event crud value specified.", DEBUG_DEVELOPER);
|
||||
}
|
||||
if (!is_number($this->data['level'])) {
|
||||
debugging('Event property level must be a number', DEBUG_DEVELOPER);
|
||||
if (!in_array($this->data['level'], array(self::LEVEL_OTHER, self::LEVEL_TEACHING, self::LEVEL_PARTICIPATING))) {
|
||||
// Bitwise combination of levels is not allowed at this stage.
|
||||
debugging('Event property level must a constant value, see event_base::LEVEL_*', DEBUG_DEVELOPER);
|
||||
}
|
||||
if (self::$fields !== array_keys($this->data)) {
|
||||
debugging('Number of event data fields must not be changed in event classes', DEBUG_DEVELOPER);
|
||||
|
||||
@@ -45,8 +45,7 @@ class blog_entry_created extends \core\event\base {
|
||||
$this->context = \context_system::instance();
|
||||
$this->data['objecttable'] = 'post';
|
||||
$this->data['crud'] = 'c';
|
||||
// TODO: MDL-37658 set level.
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_PARTICIPATING;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -44,8 +44,7 @@ class blog_entry_deleted extends \core\event\base {
|
||||
$this->context = \context_system::instance();
|
||||
$this->data['objecttable'] = 'post';
|
||||
$this->data['crud'] = 'd';
|
||||
// TODO: MDL-37658 set level.
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_PARTICIPATING;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,8 +41,7 @@ class cohort_created extends base {
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'c';
|
||||
// TODO MDL-41040.
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->data['objecttable'] = 'cohort';
|
||||
}
|
||||
|
||||
|
||||
@@ -41,8 +41,7 @@ class cohort_deleted extends base {
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'd';
|
||||
// TODO MDL-41040.
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->data['objecttable'] = 'cohort';
|
||||
}
|
||||
|
||||
|
||||
@@ -41,8 +41,7 @@ class cohort_member_added extends base {
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'c';
|
||||
// TODO MDL-41040.
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->data['objecttable'] = 'cohort';
|
||||
}
|
||||
|
||||
|
||||
@@ -42,8 +42,7 @@ class cohort_member_removed extends base {
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'd';
|
||||
// TODO MDL-41040.
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->data['objecttable'] = 'cohort';
|
||||
}
|
||||
|
||||
|
||||
@@ -41,8 +41,7 @@ class cohort_updated extends base {
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'u';
|
||||
// TODO MDL-41040.
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->data['objecttable'] = 'cohort';
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class course_category_deleted extends base {
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = 'course_categories';
|
||||
$this->data['crud'] = 'd';
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,8 +31,7 @@ class course_completed extends base {
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = 'course_completions';
|
||||
$this->data['crud'] = 'u';
|
||||
// TODO: MDL-37658 set level.
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_PARTICIPATING;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,8 +40,7 @@ class course_completion_updated extends base {
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'u';
|
||||
// TODO: MDL-37658 set level.
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_PARTICIPATING;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,7 +31,7 @@ class course_content_deleted extends base {
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = 'course';
|
||||
$this->data['crud'] = 'd';
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_TEACHING;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,7 +31,7 @@ class course_created extends base {
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = 'course';
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_TEACHING;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,7 +31,7 @@ class course_deleted extends base {
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = 'course';
|
||||
$this->data['crud'] = 'd';
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_TEACHING;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,8 +31,7 @@ class course_module_completion_updated extends base {
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = 'course_modules_completion';
|
||||
$this->data['crud'] = 'u';
|
||||
// TODO: MDL-37658 set level.
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_PARTICIPATING;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,7 +31,7 @@ class course_restored extends base {
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = 'course';
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_TEACHING;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,8 +43,7 @@ class course_section_updated extends base {
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = 'course_sections';
|
||||
$this->data['crud'] = 'u';
|
||||
// TODO MDL-41040 set level.
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_TEACHING;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,7 +34,7 @@ class course_updated extends base {
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = 'course';
|
||||
$this->data['crud'] = 'u';
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_TEACHING;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,8 +30,7 @@ class role_allow_assign_updated extends base {
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'u';
|
||||
// TODO: MDL-41040 set level.
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,8 +30,7 @@ class role_allow_override_updated extends base {
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'u';
|
||||
// TODO: MDL-41040 set level.
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,8 +30,7 @@ class role_allow_switch_updated extends base {
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'u';
|
||||
// TODO: MDL-41040 set level.
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,8 +28,7 @@ class role_assigned extends base {
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = 'role';
|
||||
$this->data['crud'] = 'c';
|
||||
// TODO: MDL-37658 set level
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,8 +34,7 @@ class role_capabilities_updated extends base {
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = 'role';
|
||||
$this->data['crud'] = 'u';
|
||||
// TODO: MDL-41040 set level.
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,8 +31,7 @@ class role_deleted extends base {
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = 'role';
|
||||
$this->data['crud'] = 'd';
|
||||
// TODO: MDL-41040 set level.
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,8 +28,7 @@ class role_unassigned extends base {
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = 'role';
|
||||
$this->data['crud'] = 'd';
|
||||
// TODO: MDL-37658 set level
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -89,7 +89,7 @@ class user_loggedin extends \core\event\base {
|
||||
protected function init() {
|
||||
$this->context = \context_system::instance();
|
||||
$this->data['crud'] = 'r';
|
||||
$this->data['level'] = 50; // TODO MDL-37658.
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->data['objecttable'] = 'user';
|
||||
}
|
||||
|
||||
|
||||
@@ -42,8 +42,7 @@ class user_loggedinas extends base {
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'r';
|
||||
// TODO MDL-41040 set level.
|
||||
$this->data['level'] = 50;
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->data['objecttable'] = 'user';
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ class core_event_testcase extends advanced_testcase {
|
||||
$this->assertSame('unittest', $event->target);
|
||||
$this->assertSame(5, $event->objectid);
|
||||
$this->assertSame('u', $event->crud);
|
||||
$this->assertSame(10, $event->level);
|
||||
$this->assertSame(\core\event\base::LEVEL_PARTICIPATING, $event->level);
|
||||
|
||||
$this->assertEquals($system, $event->get_context());
|
||||
$this->assertSame($system->id, $event->contextid);
|
||||
@@ -602,6 +602,10 @@ class core_event_testcase extends advanced_testcase {
|
||||
$this->assertInstanceOf('\coding_exception', $e);
|
||||
}
|
||||
|
||||
$event = \core_tests\event\bad_event2b::create(array('context'=>\context_system::instance()));
|
||||
@$event->trigger();
|
||||
$this->assertDebuggingCalled();
|
||||
|
||||
$event = \core_tests\event\bad_event3::create(array('context'=>\context_system::instance()));
|
||||
@$event->trigger();
|
||||
$this->assertDebuggingCalled();
|
||||
|
||||
+19
-11
@@ -41,7 +41,7 @@ class unittest_executed extends \core\event\base {
|
||||
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'u';
|
||||
$this->data['level'] = 10;
|
||||
$this->data['level'] = self::LEVEL_PARTICIPATING;
|
||||
}
|
||||
|
||||
public function get_url() {
|
||||
@@ -116,7 +116,7 @@ class unittest_observer {
|
||||
class bad_event1 extends \core\event\base {
|
||||
protected function init() {
|
||||
//$this->data['crud'] = 'u';
|
||||
$this->data['level'] = 10;
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,10 +127,18 @@ class bad_event2 extends \core\event\base {
|
||||
}
|
||||
}
|
||||
|
||||
class bad_event2b extends \core\event\base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'u';
|
||||
// Invalid level value.
|
||||
$this->data['level'] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
class bad_event3 extends \core\event\base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'u';
|
||||
$this->data['level'] = 10;
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
unset($this->data['courseid']);
|
||||
}
|
||||
}
|
||||
@@ -138,7 +146,7 @@ class bad_event3 extends \core\event\base {
|
||||
class bad_event4 extends \core\event\base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'u';
|
||||
$this->data['level'] = 10;
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->data['xxx'] = 1;
|
||||
}
|
||||
}
|
||||
@@ -146,14 +154,14 @@ class bad_event4 extends \core\event\base {
|
||||
class bad_event5 extends \core\event\base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'x';
|
||||
$this->data['level'] = 10;
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
}
|
||||
}
|
||||
|
||||
class bad_event6 extends \core\event\base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['level'] = 10;
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->data['objecttable'] = 'xxx_xxx_xx';
|
||||
}
|
||||
}
|
||||
@@ -161,7 +169,7 @@ class bad_event6 extends \core\event\base {
|
||||
class bad_event7 extends \core\event\base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['level'] = 10;
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->data['objecttable'] = null;
|
||||
}
|
||||
}
|
||||
@@ -169,14 +177,14 @@ class bad_event7 extends \core\event\base {
|
||||
class problematic_event1 extends \core\event\base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'u';
|
||||
$this->data['level'] = 10;
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
}
|
||||
}
|
||||
|
||||
class problematic_event2 extends \core\event\base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['level'] = 10;
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->context = \context_system::instance();
|
||||
}
|
||||
}
|
||||
@@ -184,7 +192,7 @@ class problematic_event2 extends \core\event\base {
|
||||
class problematic_event3 extends \core\event\base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['level'] = 10;
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->context = \context_system::instance();
|
||||
}
|
||||
|
||||
@@ -199,7 +207,7 @@ class noname_event extends \core\event\base {
|
||||
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['level'] = 10;
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->context = \context_system::instance();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user