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 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

   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 a content view.
  19   *
  20   * @package    core_contentbank
  21   * @copyright  2020 Victor Deniz <victor@moodle.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core_contentbank\output;
  26  
  27  use core_contentbank\content;
  28  use core_contentbank\contenttype;
  29  use moodle_url;
  30  use renderable;
  31  use renderer_base;
  32  use stdClass;
  33  use templatable;
  34  
  35  /**
  36   * Class containing data for the content view.
  37   *
  38   * @copyright  2020 Victor Deniz <victor@moodle.com>
  39   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  40   */
  41  class viewcontent implements renderable, templatable {
  42      /**
  43       * @var contenttype Content bank content type.
  44       */
  45      private $contenttype;
  46  
  47      /**
  48       * @var stdClass Record of the contentbank_content table.
  49       */
  50      private $content;
  51  
  52      /**
  53       * Construct this renderable.
  54       *
  55       * @param contenttype $contenttype Content bank content type.
  56       * @param content $content Record of the contentbank_content table.
  57       */
  58      public function __construct(contenttype $contenttype, content $content) {
  59          $this->contenttype = $contenttype;
  60          $this->content = $content;
  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       *
  68       * @return stdClass
  69       */
  70      public function export_for_template(renderer_base $output): stdClass {
  71          $data = new stdClass();
  72  
  73          // Get the content type html.
  74          $contenthtml = $this->contenttype->get_view_content($this->content);
  75          $data->contenthtml = $contenthtml;
  76  
  77          // Check if the user can edit this content type.
  78          if ($this->contenttype->can_edit($this->content)) {
  79              $data->usercanedit = true;
  80              $urlparams = [
  81                  'contextid' => $this->content->get_contextid(),
  82                  'plugin' => $this->contenttype->get_plugin_name(),
  83                  'id' => $this->content->get_id()
  84              ];
  85              $editcontenturl = new moodle_url('/contentbank/edit.php', $urlparams);
  86              $data->editcontenturl = $editcontenturl->out(false);
  87          }
  88  
  89          $closeurl = new moodle_url('/contentbank/index.php', ['contextid' => $this->content->get_contextid()]);
  90          $data->closeurl = $closeurl->out(false);
  91  
  92          return $data;
  93      }
  94  }