Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
<?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/>.

/**
 * Contains class core_h5p\output\libraries
 *
 * @package   core_h5p
 * @copyright 2020 Ferran Recio
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

namespace core_h5p\output;

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

use renderable;
use templatable;
use renderer_base;
use stdClass;
use moodle_url;
use action_menu;
use action_menu_link;
use pix_icon;

/**
 * Class to help display H5P library management table.
 *
 * @copyright 2020 Ferran Recio
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
class libraries implements renderable, templatable {

    /** @var H5P factory */
    protected $factory;

    /** @var H5P library list */
    protected $libraries;

    /**
     * Constructor.
     *
     * @param factory $factory The H5P factory
     * @param array $libraries array of h5p libraries records
     */
    public function __construct(\core_h5p\factory $factory, array $libraries) {
        $this->factory = $factory;
        $this->libraries = $libraries;
    }

    /**
     * Export this data so it can be used as the context for a mustache template.
     *
     * @param renderer_base $output
     * @return stdClass
     */
    public function export_for_template(renderer_base $output) {
        $installed = [];
        $filestorage = $this->factory->get_core()->fs;
        foreach ($this->libraries as $libraryname => $versions) {
            foreach ($versions as $version) {
                // Get the icon URL.
                $version->icon = $filestorage->get_icon_url(
                    $version->id,
                    $version->machine_name,
                    $version->major_version,
                    $version->minor_version
                );
                // Get the action menu options.
                $actionmenu = new action_menu();
                $actionmenu->set_menu_trigger(get_string('actions', 'core_h5p'));
                $actionmenu->set_alignment(action_menu::TL, action_menu::BL);
                $actionmenu->prioritise = true;
                $actionmenu->add_primary_action(new action_menu_link(
                    new moodle_url('/h5p/libraries.php', ['deletelibrary' => $version->id]),
                    new pix_icon('t/delete', get_string('deletelibraryversion', 'core_h5p')),
                    get_string('deletelibraryversion', 'core_h5p')
                ));
                $version->actionmenu = $actionmenu->export_for_template($output);
> if ($version->enabled) { $installed[] = $version; > $version->toggleenabledurl = new moodle_url('/h5p/libraries.php', [ } > 'id' => $version->id, } > 'action' => 'disable', $r = new stdClass(); > 'sesskey' => sesskey(), $r->contenttypes = $installed; > ]); return $r; > } else { } > $version->toggleenabledurl = new moodle_url('/h5p/libraries.php', [ } > 'id' => $version->id, > 'action' => 'enable', > 'sesskey' => sesskey(), > ]); > }