Merge branch 'wip-MDL-45218-master' of git://github.com/abgreeve/moodle

This commit is contained in:
Marina Glancy 2014-04-23 14:33:12 +08:00
commit cae96c6217
4 changed files with 229 additions and 7 deletions

View file

@ -478,6 +478,69 @@ abstract class base implements \IteratorAggregate {
return $event;
}
/**
* Get static information about an event.
* This is used in reports and is not for general use.
*
* @return array Static information about the event.
*/
public static final function get_static_info() {
/** Var \core\event\base $event. */
$event = new static();
// Set static event data specific for child class.
$event->init();
return array(
'eventname' => $event->data['eventname'],
'component' => $event->data['component'],
'target' => $event->data['target'],
'action' => $event->data['action'],
'crud' => $event->data['crud'],
'edulevel' => $event->data['edulevel'],
'objecttable' => $event->data['objecttable'],
);
}
/**
* Get an explanation of what the class does.
* By default returns the phpdocs from the child event class. Ideally this should
* be overridden to return a translatable get_string style markdown.
* e.g. return new lang_string('eventyourspecialevent', 'plugin_type');
*
* @return string An explanation of the event formatted in markdown style.
*/
public static function get_explanation() {
$ref = new \ReflectionClass(get_called_class());
$docblock = $ref->getDocComment();
// Check that there is something to work on.
if (empty($docblock)) {
return null;
}
$docblocklines = explode("\n", $docblock);
// Remove the bulk of the comment characters.
$pattern = "/(^\s*\/\*\*|^\s+\*\s|^\s+\*)/";
$cleanline = array();
foreach ($docblocklines as $line) {
$templine = preg_replace($pattern, '', $line);
// If there is nothing on the line then don't add it to the array.
if (!empty($templine)) {
$cleanline[] = rtrim($templine);
}
// If we get to a line starting with an @ symbol then we don't want the rest.
if (preg_match("/^@|\//", $templine)) {
// Get rid of the last entry (it contains an @ symbol).
array_pop($cleanline);
// Break out of this foreach loop.
break;
}
}
// Add a line break to the sanitised lines.
$explanation = implode("\n", $cleanline);
return $explanation;
}
/**
* Returns event context.
* @return \context

View file

@ -215,15 +215,16 @@ class manager {
self::$allobservers = array();
$plugintypes = \core_component::get_plugin_types();
$plugintypes = array_merge(array('core' => 'not used'), $plugintypes);
$systemdone = false;
foreach ($plugintypes as $plugintype => $ignored) {
$plugins = \core_component::get_plugin_list($plugintype);
if (!$systemdone) {
$plugins[] = "$CFG->dirroot/lib";
$systemdone = true;
if ($plugintype === 'core') {
$plugins['core'] = "$CFG->dirroot/lib";
} else {
$plugins = \core_component::get_plugin_list($plugintype);
}
foreach ($plugins as $fulldir) {
foreach ($plugins as $plugin => $fulldir) {
if (!file_exists("$fulldir/db/events.php")) {
continue;
}
@ -232,7 +233,7 @@ class manager {
if (!is_array($observers)) {
continue;
}
self::add_observers($observers, "$fulldir/db/events.php");
self::add_observers($observers, "$fulldir/db/events.php", $plugintype, $plugin);
}
}
@ -248,8 +249,10 @@ class manager {
* Add observers.
* @param array $observers
* @param string $file
* @param string $plugintype Plugin type of the observer.
* @param string $plugin Plugin of the observer.
*/
protected static function add_observers(array $observers, $file) {
protected static function add_observers(array $observers, $file, $plugintype = null, $plugin = null) {
global $CFG;
foreach ($observers as $observer) {
@ -292,6 +295,8 @@ class manager {
}
$o->includefile = $observer['includefile'];
}
$o->plugintype = $plugintype;
$o->plugin = $plugin;
self::$allobservers[$observer['eventname']][] = $o;
}
}
@ -306,6 +311,17 @@ class manager {
}
}
/**
* Returns all observers in the system. This is only for use for reporting on the list of observers in the system.
*
* @access private
* @return array An array of stdClass with all core observer details.
*/
public static function get_all_observers() {
self::init_all_observers();
return self::$allobservers;
}
/**
* Replace all standard observers.
* @param array $observers