Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Contains class core_h5p\output\libraries
  19   *
  20   * @package   core_h5p
  21   * @copyright 2020 Ferran Recio
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core_h5p\output;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  use renderable;
  30  use templatable;
  31  use renderer_base;
  32  use stdClass;
  33  use moodle_url;
  34  use action_menu;
  35  use action_menu_link;
  36  use pix_icon;
  37  
  38  /**
  39   * Class to help display H5P library management table.
  40   *
  41   * @copyright 2020 Ferran Recio
  42   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  43   */
  44  class libraries implements renderable, templatable {
  45  
  46      /** @var H5P factory */
  47      protected $factory;
  48  
  49      /** @var H5P library list */
  50      protected $libraries;
  51  
  52      /**
  53       * Constructor.
  54       *
  55       * @param factory $factory The H5P factory
  56       * @param array $libraries array of h5p libraries records
  57       */
  58      public function __construct(\core_h5p\factory $factory, array $libraries) {
  59          $this->factory = $factory;
  60          $this->libraries = $libraries;
  61      }
  62  
  63      /**
  64       * Export this data so it can be used as the context for a mustache template.
  65       *
  66       * @param renderer_base $output
  67       * @return stdClass
  68       */
  69      public function export_for_template(renderer_base $output) {
  70          $installed = [];
  71          $filestorage = $this->factory->get_core()->fs;
  72          foreach ($this->libraries as $libraryname => $versions) {
  73              foreach ($versions as $version) {
  74                  // Get the icon URL.
  75                  $version->icon = $filestorage->get_icon_url(
  76                      $version->id,
  77                      $version->machine_name,
  78                      $version->major_version,
  79                      $version->minor_version
  80                  );
  81                  // Get the action menu options.
  82                  $actionmenu = new action_menu();
  83                  $actionmenu->set_menu_trigger(get_string('actions', 'core_h5p'));
  84                  $actionmenu->set_alignment(action_menu::TL, action_menu::BL);
  85                  $actionmenu->prioritise = true;
  86                  $actionmenu->add_primary_action(new action_menu_link(
  87                      new moodle_url('/h5p/libraries.php', ['deletelibrary' => $version->id]),
  88                      new pix_icon('t/delete', get_string('deletelibraryversion', 'core_h5p')),
  89                      get_string('deletelibraryversion', 'core_h5p')
  90                  ));
  91                  $version->actionmenu = $actionmenu->export_for_template($output);
  92                  if ($version->enabled) {
  93                      $version->toggleenabledurl = new moodle_url('/h5p/libraries.php', [
  94                          'id' => $version->id,
  95                          'action' => 'disable',
  96                          'sesskey' => sesskey(),
  97                      ]);
  98                  } else {
  99                      $version->toggleenabledurl = new moodle_url('/h5p/libraries.php', [
 100                          'id' => $version->id,
 101                          'action' => 'enable',
 102                          'sesskey' => sesskey(),
 103                      ]);
 104                  }
 105                  $installed[] = $version;
 106              }
 107          }
 108          $r = new stdClass();
 109          $r->contenttypes = $installed;
 110          return $r;
 111      }
 112  }