Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
   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  namespace enrol_lti\local\ltiadvantage\viewobject;
  18  
  19  /**
  20   * The class published_resource, instances of which represent a specific VIEW of a published resource.
  21   *
  22   * This class performs no validation and is only meant to be used as a slice of the existing data for use in the
  23   * content selection flow.
  24   *
  25   * @package    enrol_lti
  26   * @copyright  2021 Jake Dallimore <jrhdallimore@gmail.com>
  27   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  28   */
  29  class published_resource {
  30      /** @var string the name of this resource. */
  31      private $name;
  32  
  33      /** @var string full name of the course to which this published resource belongs. */
  34      private $coursefullname;
  35  
  36      /** @var int id of the course to which this published resource belongs. */
  37      private $courseid;
  38  
  39      /** @var int the context id of the resource */
  40      private $contextid;
  41  
  42      /** @var int id of the enrol_lti_tools instance (i.e. the id of the 'published resource'). */
  43      private $id;
  44  
  45      /** @var string a v4 uuid identifier for this published resource. */
  46      private $uuid;
  47  
  48      /** @var bool whether or not this resource supports grades. */
  49      private $supportsgrades;
  50  
  51      /** @var float the max grade or null if not a graded resource. */
  52      private $grademax;
  53  
  54      /** @var bool whether or not this resource is itself a course. */
  55      private $iscourse;
  56  
  57      /**
  58       * The published_resource constructor.
  59       *
  60       * @param string $name the name of this resource.
  61       * @param string $coursefullname full name of the course to which this published resource belongs.
  62       * @param int $courseid id of the course to which this published resource belongs.
  63       * @param int $contextid id of the context.
  64       * @param int $id id of the enrol_lti_tools instance (i.e. the id of the 'published resource').
  65       * @param string $uuid a v4 uuid identifier for this published resource.
  66       * @param bool $supportsgrades whether or not this resource supports grades.
  67       * @param float|null $grademax the max grade or null if this is not a graded resource.
  68       * @param bool $iscourse whether or not this resource is itself a course.
  69       */
  70      public function __construct(string $name, string $coursefullname, int $courseid, int $contextid, int $id,
  71              string $uuid, bool $supportsgrades, ?float $grademax, bool $iscourse) {
  72  
  73          $this->name = $name;
  74          $this->coursefullname = $coursefullname;
  75          $this->courseid = $courseid;
  76          $this->contextid = $contextid;
  77          $this->id = $id;
  78          $this->uuid = $uuid;
  79          $this->supportsgrades = $supportsgrades;
  80          $this->grademax = $grademax;
  81          $this->iscourse = $iscourse;
  82      }
  83  
  84      /**
  85       * Get the name of this published resource.
  86       *
  87       * @return string the localised name.
  88       */
  89      public function get_name(): string {
  90          return $this->name;
  91      }
  92  
  93      /**
  94       * Get the full name of the course owning this published resource.
  95       *
  96       * @return string the localised course full name.
  97       */
  98      public function get_coursefullname(): string {
  99          return $this->coursefullname;
 100      }
 101  
 102      /**
 103       * Get the id of the course owning this published resource.
 104       *
 105       * @return int the course id.
 106       */
 107      public function get_courseid(): int {
 108          return $this->courseid;
 109      }
 110  
 111      /**
 112       * Get the id of the context for this published resource.
 113       *
 114       * @return int the context id.
 115       */
 116      public function get_contextid(): int {
 117          return $this->contextid;
 118      }
 119  
 120      /**
 121       * Get the id of this published resource.
 122       *
 123       * @return int the id.
 124       */
 125      public function get_id(): int {
 126          return $this->id;
 127      }
 128  
 129      /**
 130       * Get the uuid for this published resource.
 131       *
 132       * @return string v4 uuid.
 133       */
 134      public function get_uuid(): string {
 135          return $this->uuid;
 136      }
 137  
 138      /**
 139       * Check whether this resource supports grades or not.
 140       *
 141       * @return bool true if supported, false otherwise.
 142       */
 143      public function supports_grades(): bool {
 144          return $this->supportsgrades;
 145      }
 146  
 147      /**
 148       * Get the max grade for this published resource, if its a graded resource.
 149       *
 150       * @return float|null the grade max, if grades are supported, else null.
 151       */
 152      public function get_grademax(): ?float {
 153          return $this->grademax;
 154      }
 155  
 156      /**
 157       * Check whether this published resource is a course itself.
 158       *
 159       * @return bool true if it's a course, false otherwise.
 160       */
 161      public function is_course(): bool {
 162          return $this->iscourse;
 163      }
 164  }