Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 400 and 403] [Versions 401 and 403] [Versions 402 and 403]

   1  <?php
   2  
   3  namespace Packback\Lti1p3;
   4  
   5  class LtiDeepLinkResource
   6  {
   7      private $type = LtiConstants::DL_RESOURCE_LINK_TYPE;
   8      private $title;
   9      private $text;
  10      private $url;
  11      private $line_item;
  12      private $icon;
  13      private $thumbnail;
  14      private $custom_params = [];
  15      private $target = 'iframe';
  16      private $iframe;
  17      private $window;
  18      private $availability_interval;
  19      private $submission_interval;
  20  
  21      public static function new(): LtiDeepLinkResource
  22      {
  23          return new LtiDeepLinkResource();
  24      }
  25  
  26      public function getType(): string
  27      {
  28          return $this->type;
  29      }
  30  
  31      public function setType(string $value): LtiDeepLinkResource
  32      {
  33          $this->type = $value;
  34  
  35          return $this;
  36      }
  37  
  38      public function getTitle(): ?string
  39      {
  40          return $this->title;
  41      }
  42  
  43      public function setTitle(?string $value): LtiDeepLinkResource
  44      {
  45          $this->title = $value;
  46  
  47          return $this;
  48      }
  49  
  50      public function getText(): ?string
  51      {
  52          return $this->text;
  53      }
  54  
  55      public function setText(?string $value): LtiDeepLinkResource
  56      {
  57          $this->text = $value;
  58  
  59          return $this;
  60      }
  61  
  62      public function getUrl(): ?string
  63      {
  64          return $this->url;
  65      }
  66  
  67      public function setUrl(?string $value): LtiDeepLinkResource
  68      {
  69          $this->url = $value;
  70  
  71          return $this;
  72      }
  73  
  74      public function getLineItem(): ?LtiLineitem
  75      {
  76          return $this->line_item;
  77      }
  78  
  79      public function setLineItem(?LtiLineitem $value): LtiDeepLinkResource
  80      {
  81          $this->line_item = $value;
  82  
  83          return $this;
  84      }
  85  
  86      public function setIcon(?LtiDeepLinkResourceIcon $icon): LtiDeepLinkResource
  87      {
  88          $this->icon = $icon;
  89  
  90          return $this;
  91      }
  92  
  93      public function getIcon(): ?LtiDeepLinkResourceIcon
  94      {
  95          return $this->icon;
  96      }
  97  
  98      public function setThumbnail(?LtiDeepLinkResourceIcon $thumbnail): LtiDeepLinkResource
  99      {
 100          $this->thumbnail = $thumbnail;
 101  
 102          return $this;
 103      }
 104  
 105      public function getThumbnail(): ?LtiDeepLinkResourceIcon
 106      {
 107          return $this->thumbnail;
 108      }
 109  
 110      public function getCustomParams(): array
 111      {
 112          return $this->custom_params;
 113      }
 114  
 115      public function setCustomParams(array $value): LtiDeepLinkResource
 116      {
 117          $this->custom_params = $value;
 118  
 119          return $this;
 120      }
 121  
 122      /**
 123       * @deprecated This field maps the "presentation" resource property, which is non-standard.
 124       * Consider using "iframe" and/or "window" instead.
 125       */
 126      public function getTarget(): string
 127      {
 128          return $this->target;
 129      }
 130  
 131      /**
 132       * @deprecated This field maps the "presentation" resource property, which is non-standard.
 133       * Consider using "iframe" and/or "window" instead.
 134       */
 135      public function setTarget(string $value): LtiDeepLinkResource
 136      {
 137          $this->target = $value;
 138  
 139          return $this;
 140      }
 141  
 142      public function getIframe(): ?LtiDeepLinkResourceIframe
 143      {
 144          return $this->iframe;
 145      }
 146  
 147      public function setIframe(?LtiDeepLinkResourceIframe $iframe): LtiDeepLinkResource
 148      {
 149          $this->iframe = $iframe;
 150  
 151          return $this;
 152      }
 153  
 154      public function getWindow(): ?LtiDeepLinkResourceWindow
 155      {
 156          return $this->window;
 157      }
 158  
 159      public function setWindow(?LtiDeepLinkResourceWindow $window): LtiDeepLinkResource
 160      {
 161          $this->window = $window;
 162  
 163          return $this;
 164      }
 165  
 166      public function getAvailabilityInterval(): ?LtiDeepLinkDateTimeInterval
 167      {
 168          return $this->availability_interval;
 169      }
 170  
 171      public function setAvailabilityInterval(?LtiDeepLinkDateTimeInterval $availabilityInterval): LtiDeepLinkResource
 172      {
 173          $this->availability_interval = $availabilityInterval;
 174  
 175          return $this;
 176      }
 177  
 178      public function getSubmissionInterval(): ?LtiDeepLinkDateTimeInterval
 179      {
 180          return $this->submission_interval;
 181      }
 182  
 183      public function setSubmissionInterval(?LtiDeepLinkDateTimeInterval $submissionInterval): LtiDeepLinkResource
 184      {
 185          $this->submission_interval = $submissionInterval;
 186  
 187          return $this;
 188      }
 189  
 190      public function toArray(): array
 191      {
 192          $resource = [
 193              'type' => $this->type,
 194          ];
 195  
 196          if (isset($this->title)) {
 197              $resource['title'] = $this->title;
 198          }
 199          if (isset($this->text)) {
 200              $resource['text'] = $this->text;
 201          }
 202          if (isset($this->url)) {
 203              $resource['url'] = $this->url;
 204          }
 205          if (!empty($this->custom_params)) {
 206              $resource['custom'] = $this->custom_params;
 207          }
 208          if (isset($this->icon)) {
 209              $resource['icon'] = $this->icon->toArray();
 210          }
 211          if (isset($this->thumbnail)) {
 212              $resource['thumbnail'] = $this->thumbnail->toArray();
 213          }
 214          if ($this->line_item !== null) {
 215              $resource['lineItem'] = [
 216                  'scoreMaximum' => $this->line_item->getScoreMaximum(),
 217                  'label' => $this->line_item->getLabel(),
 218              ];
 219          }
 220  
 221          // Kept for backwards compatibility
 222          if (!isset($this->iframe) && !isset($this->window)) {
 223              $resource['presentation'] = [
 224                  'documentTarget' => $this->target,
 225              ];
 226          }
 227  
 228          if (isset($this->iframe)) {
 229              $resource['iframe'] = $this->iframe->toArray();
 230          }
 231          if (isset($this->window)) {
 232              $resource['window'] = $this->window->toArray();
 233          }
 234          if (isset($this->availability_interval)) {
 235              $resource['available'] = $this->availability_interval->toArray();
 236          }
 237          if (isset($this->submission_interval)) {
 238              $resource['submission'] = $this->submission_interval->toArray();
 239          }
 240  
 241          return $resource;
 242      }
 243  }