MDL-44720 modinfo: make it easier to use cm_info instead of get_coursemodule_from_id

by adding function cm_info::get_course_module_record()
This commit is contained in:
Marina Glancy
2014-03-27 11:24:00 +08:00
parent 9b8555fbea
commit 92e2e85523
5 changed files with 164 additions and 5 deletions
+8
View File
@@ -664,9 +664,17 @@ abstract class base implements \IteratorAggregate {
throw new \coding_exception('It is not possible to add snapshots after triggering of events');
}
// Special case for course module, allow instance of cm_info to be passed instead of stdClass.
if ($tablename === 'course_modules' && $record instanceof \cm_info) {
$record = $record->get_course_module_record();
}
// NOTE: this might use some kind of MUC cache,
// hopefully we will not run out of memory here...
if ($CFG->debugdeveloper) {
if (!($record instanceof \stdClass)) {
debugging('Argument $record must be an instance of stdClass.', DEBUG_DEVELOPER);
}
if (!$DB->get_manager()->table_exists($tablename)) {
debugging("Invalid table name '$tablename' specified, database table does not exist.", DEBUG_DEVELOPER);
} else {