Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   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   * Class containing data for managelearningplans page
  19   *
  20   * @package    tool_lp
  21   * @copyright  2015 Damyon Wiese
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace tool_lp\output;
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  use context;
  28  use renderable;
  29  use templatable;
  30  use renderer_base;
  31  use single_button;
  32  use stdClass;
  33  use moodle_url;
  34  use context_system;
  35  use core_competency\api;
  36  use core_competency\template;
  37  use core_competency\external\template_exporter;
  38  
  39  /**
  40   * Class containing data for managecompetencyframeworks page
  41   *
  42   * @copyright  2015 Damyon Wiese
  43   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  44   */
  45  class manage_templates_page implements renderable, templatable {
  46  
  47      /** @var context The context in which everything is happening. */
  48      protected $pagecontext;
  49  
  50      /** @var array $navigation List of links to display on the page. Each link contains a url and a title. */
  51      protected $navigation = array();
  52  
  53      /** @var array $templates List of learning plan templates. */
  54      protected $templates = array();
  55  
  56      /**
  57       * Construct this renderable.
  58       * @param context $pagecontext
  59       */
  60      public function __construct(context $pagecontext) {
  61          $this->pagecontext = $pagecontext;
  62  
  63          if (template::can_manage_context($this->pagecontext)) {
  64              $addpage = new single_button(
  65                 new moodle_url('/admin/tool/lp/edittemplate.php', array('pagecontextid' => $this->pagecontext->id)),
  66                 get_string('addnewtemplate', 'tool_lp'),
  67                 'get'
  68              );
  69              $this->navigation[] = $addpage;
  70          }
  71  
  72          $this->templates = api::list_templates('shortname', 'ASC', 0, 0, $this->pagecontext);
  73      }
  74  
  75      /**
  76       * Export this data so it can be used as the context for a mustache template.
  77       *
  78       * @param renderer_base $output Renderer base.
  79       * @return stdClass
  80       */
  81      public function export_for_template(renderer_base $output) {
  82          $data = new stdClass();
  83          $data->pagecontextid = $this->pagecontext->id;
  84          $data->templates = array();
  85          foreach ($this->templates as $template) {
  86              $exporter = new template_exporter($template);
  87              $data->templates[] = $exporter->export($output);
  88          }
  89          $data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
  90          $data->navigation = array();
  91          foreach ($this->navigation as $button) {
  92              $data->navigation[] = $output->render($button);
  93          }
  94          $data->canmanage = template::can_manage_context($this->pagecontext);
  95  
  96          return $data;
  97      }
  98  }