Merge branch 'MDL-67076-master' of git://github.com/sarjona/moodle
This commit is contained in:
+10
-3
@@ -85,17 +85,24 @@ class player {
|
||||
*/
|
||||
private $messages;
|
||||
|
||||
/**
|
||||
* @var bool Set to true in scripts that can not redirect (CLI, RSS feeds, etc.), throws exceptions.
|
||||
*/
|
||||
private $preventredirect;
|
||||
|
||||
/**
|
||||
* Inits the H5P player for rendering the content.
|
||||
*
|
||||
* @param string $url Local URL of the H5P file to display.
|
||||
* @param stdClass $config Configuration for H5P buttons.
|
||||
* @param bool $preventredirect Set to true in scripts that can not redirect (CLI, RSS feeds, etc.), throws exceptions
|
||||
*/
|
||||
public function __construct(string $url, \stdClass $config) {
|
||||
public function __construct(string $url, \stdClass $config, bool $preventredirect = true) {
|
||||
if (empty($url)) {
|
||||
throw new \moodle_exception('h5pinvalidurl', 'core_h5p');
|
||||
}
|
||||
$this->url = new \moodle_url($url);
|
||||
$this->preventredirect = $preventredirect;
|
||||
|
||||
$this->factory = new \core_h5p\factory();
|
||||
|
||||
@@ -397,7 +404,7 @@ class player {
|
||||
if ($this->context->contextlevel == CONTEXT_MODULE ||
|
||||
$this->context->contextlevel == CONTEXT_COURSE) {
|
||||
// Require login to the course first (without login to the module).
|
||||
require_course_login($course, true, null, false, true);
|
||||
require_course_login($course, true, null, !$this->preventredirect, $this->preventredirect);
|
||||
|
||||
// Now check if module is available OR it is restricted but the intro is shown on the course page.
|
||||
if ($this->context->contextlevel == CONTEXT_MODULE) {
|
||||
@@ -405,7 +412,7 @@ class player {
|
||||
if (!$cminfo->uservisible) {
|
||||
if (!$cm->showdescription || !$cminfo->is_visible_on_course_page()) {
|
||||
// Module intro is not visible on the course page and module is not available, show access error.
|
||||
require_course_login($course, true, $cminfo, false, true);
|
||||
require_course_login($course, true, $cminfo, !$this->preventredirect, $this->preventredirect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -34,9 +34,11 @@ $config->export = optional_param('export', 0, PARAM_INT);
|
||||
$config->embed = optional_param('embed', 0, PARAM_INT);
|
||||
$config->copyright = optional_param('copyright', 0, PARAM_INT);
|
||||
|
||||
$preventredirect = optional_param('preventredirect', true, PARAM_BOOL);
|
||||
|
||||
$PAGE->set_url(new \moodle_url('/h5p/embed.php', array('url' => $url)));
|
||||
try {
|
||||
$h5pplayer = new \core_h5p\player($url, $config);
|
||||
$h5pplayer = new \core_h5p\player($url, $config, $preventredirect);
|
||||
$messages = $h5pplayer->get_messages();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
Reference in New Issue
Block a user