Skip to content

Commit

Permalink
MDL-66402 core_h5p: First version for player.php and embed.php
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona committed Sep 15, 2019
1 parent b3f0ecc commit bf532f8
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 0 deletions.
82 changes: 82 additions & 0 deletions h5p/classes/player.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* H5P player class.
*
* @package core
* @subpackage h5p
* @copyright 2019 Moodle
* @author Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace core_h5p;

defined('MOODLE_INTERNAL') || die();

class player {
protected $embedtype;
protected $settings;

/**
* Inits the H5P player for rendering the content.
*
* @param string $pluginfile Local URL of the H5P file to display.
*/
public function __construct(string $pluginfile) {
global $CFG;

}

/**
* Adds js assets to the current page.
*/
public function addassetstopage() {
global $PAGE, $CFG;

foreach ($this->jsrequires as $script) {
$PAGE->requires->js($script, true);
}

foreach ($this->cssrequires as $css) {
$PAGE->requires->css($css);
}

// Print JavaScript settings to page.
$PAGE->requires->data_for_js('H5PIntegration', $this->settings, true);
}

/**
* Outputs an H5P content.
*/
public function outputview() {
if ($this->embedtype === 'div') {
echo "<div class=\"h5p-content\" data-content-id=\"{$this->idnumber}\"></div>";
} else {
echo "<div class=\"h5p-iframe-wrapper\">" .
"<iframe id=\"h5p-iframe-{$this->idnumber}\"" .
" class=\"h5p-iframe\"" .
" data-content-id=\"{$this->idnumber}\"" .
" style=\"height:1px; min-width: 100%\"" .
" src=\"about:blank\"" .
" frameBorder=\"0\"" .
" scrolling=\"no\">" .
"</iframe>" .
"</div>";
}
}
}
56 changes: 56 additions & 0 deletions h5p/embed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Render H5P content from an H5P file.
*
* @package core_h5p
* @copyright 2019 Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once(__DIR__ . '/../config.php');

$pluginfile = required_param('pluginfile', PARAM_LOCALURL);

// TODO: Check if the user has access to the file.
require_login(null, false);

// Set up the H5P player class.
$h5pplayer = new \core_h5p\player($pluginfile);

// Configure page.
$context = context_system::instance();
// TODO: update the correct context.
$PAGE->set_context($context);
$PAGE->set_url(new moodle_url ('/h5p/embed.php', array('pluginfile' => $pluginfile)));
// TODO: set the title and the heading. They should be added to the h5p lang or taken from the metadata.
$PAGE->set_title('render h5p');
$PAGE->set_heading('h5p rendering');

// Embed specific page setup.
$PAGE->add_body_class('h5p-embed');
$PAGE->set_pagelayout('embedded');

// Add H5P assets to the page.
$h5pplayer->addassetstopage();

// Print page HTML.
echo $OUTPUT->header();

echo $h5pplayer->outputview();

echo $OUTPUT->footer();

0 comments on commit bf532f8

Please sign in to comment.