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   * Class for exporting the data needed to render a recent accessed item.
  18   *
  19   * @package    block_recentlyaccesseditems
  20   * @copyright  2018 Victor Deniz <victor@moodle.com>
  21   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   */
  23  namespace block_recentlyaccesseditems\external;
  24  defined('MOODLE_INTERNAL') || die();
  25  
  26  use renderer_base;
  27  use moodle_url;
  28  
  29  /**
  30   * Class for exporting the data needed to render a recent accessed item.
  31   *
  32   * @copyright  2018 Victor Deniz
  33   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34   */
  35  class recentlyaccesseditems_item_exporter extends \core\external\exporter {
  36      /**
  37       * Returns a list of objects that are related to this persistent.
  38       *
  39       */
  40      protected static function define_related() {
  41          // We cache the context so it does not need to be retrieved from the course.
  42          return array('context' => '\\context');
  43      }
  44  
  45      /**
  46       * Get the additional values to inject while exporting.
  47       *
  48       * @param renderer_base $output The renderer
  49       * @return array Additional properties with values
  50       */
  51      protected function get_other_values(renderer_base $output) {
  52          global $CFG;
  53          require_once($CFG->libdir.'/modinfolib.php');
  54  
  55          return array(
  56              'viewurl' => (new moodle_url('/mod/'.$this->data->modname.'/view.php',
  57                  array('id' => $this->data->cmid)))->out(false),
  58              'courseviewurl' => (new moodle_url('/course/view.php', array('id' => $this->data->courseid)))->out(false),
  59              'icon' => \html_writer::img(
  60                  get_fast_modinfo($this->data->courseid)->cms[$this->data->cmid]->get_icon_url(),
  61                  get_string('pluginname', $this->data->modname),
  62                  ['title' => get_string('pluginname', $this->data->modname), 'class' => 'icon']
  63              )
  64          );
  65      }
  66  
  67      /**
  68       * Return the list of properties.
  69       *
  70       * @return array Properties.
  71       */
  72      public static function define_properties() {
  73          return array(
  74              'id' => array(
  75                  'type' => PARAM_INT,
  76              ),
  77              'courseid' => array(
  78                  'type' => PARAM_INT,
  79              ),
  80              'cmid' => array(
  81                  'type' => PARAM_INT,
  82              ),
  83              'userid' => array(
  84                  'type' => PARAM_INT,
  85              ),
  86              'modname' => array(
  87                  'type' => PARAM_TEXT,
  88              ),
  89              'name' => array(
  90                      'type' => PARAM_TEXT,
  91              ),
  92              'coursename' => array(
  93                  'type' => PARAM_TEXT,
  94              ),
  95              'timeaccess' => array(
  96                  'type' => PARAM_INT,
  97              )
  98          );
  99      }
 100  
 101      /**
 102       * Return the list of additional properties.
 103       *
 104       * @return array Additional properties.
 105       */
 106      public static function define_other_properties() {
 107          return array(
 108              'viewurl' => array(
 109                  'type' => PARAM_TEXT,
 110              ),
 111              'courseviewurl' => array(
 112                      'type' => PARAM_URL,
 113              ),
 114              'icon' => array(
 115                  'type' => PARAM_RAW,
 116              )
 117          );
 118      }
 119  }