/** * Returns ELIS course context instance. * * @static * @param int $instanceid The ELIS course id * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; * IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); * MUST_EXIST means we will throw an exception if no record or multiple records found. * @return \local_elisprogram\context\course|bool Context instance or false if instance was not found. */ public static function instance($instanceid, $strictness = MUST_EXIST) { global $DB; $contextlevel = \local_eliscore\context\helper::get_level_from_class_name(get_called_class()); if ($context = \local_eliscore\context\base::cache_get($contextlevel, $instanceid)) { return $context; } $record = $DB->get_record('context', array('contextlevel' => $contextlevel, 'instanceid' => $instanceid)); if (empty($record)) { $course = $DB->get_record(\course::TABLE, array('id' => $instanceid), 'id,idnumber', $strictness); if (!empty($course)) { $parentpath = '/' . SYSCONTEXTID; $record = \local_eliscore\context\base::insert_context_record($contextlevel, $course->id, $parentpath); } } if (!empty($record)) { $context = new \local_elisprogram\context\course($record); \local_eliscore\context\base::cache_add($context); return $context; } return false; }
/** * Returns ELIS User Set context instance. * * @static * @param int $instanceid The ELIS userset id * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; * IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); * MUST_EXIST means we will throw an exception if no record or multiple records found. * @return \local_elisprogram\context\userset|bool Context instance or false if instance was not found. */ public static function instance($instanceid, $strictness = MUST_EXIST) { global $DB; $contextlevel = \local_eliscore\context\helper::get_level_from_class_name(get_called_class()); if ($context = \local_eliscore\context\base::cache_get($contextlevel, $instanceid)) { return $context; } if (!($record = $DB->get_record('context', array('contextlevel' => $contextlevel, 'instanceid' => $instanceid)))) { if ($userset = $DB->get_record(\userset::TABLE, array('id' => $instanceid), 'id,parent', $strictness)) { if ($userset->parent) { $parentcontext = \local_elisprogram\context\userset::instance($userset->parent); $record = \local_eliscore\context\base::insert_context_record($contextlevel, $userset->id, $parentcontext->path); } else { $record = \local_eliscore\context\base::insert_context_record($contextlevel, $userset->id, '/' . SYSCONTEXTID, 0); } } } if ($record) { $context = new \local_elisprogram\context\userset($record); \local_eliscore\context\base::cache_add($context); return $context; } return false; }