LTI Integration Library 4.10.3
PHP class library for building LTI integrations
 
Loading...
Searching...
No Matches
ResourceLinkShareKey.php
1<?php
2
3namespace ceLTIc\LTI;
4
6
15{
16
20 const MAX_SHARE_KEY_LIFE = 168; // in hours (1 week)
21
25 const DEFAULT_SHARE_KEY_LIFE = 24; // in hours
26
31
36
42 public $resourceLinkId = null;
43
49 public $length = null;
50
56 public $life = null; // in hours
57
63 public $autoApprove = false;
64
70 public $expires = null;
71
77 private $id = null;
78
84 private $dataConnector = null;
85
92 public function __construct($resourceLink, $id = null)
93 {
94 $this->initialize();
95 $this->dataConnector = $resourceLink->getDataConnector();
96 $this->id = $id;
97 if (!empty($id)) {
98 $this->load();
99 } else {
100 $this->resourceLinkId = $resourceLink->getRecordId();
101 }
102 }
103
107 public function initialize()
108 {
109 $this->length = null;
110 $this->life = null;
111 $this->autoApprove = false;
112 $this->expires = null;
113 }
114
120 public function initialise()
121 {
122 $this->initialize();
123 }
124
130 public function save()
131 {
132 if (empty($this->life)) {
133 $this->life = self::DEFAULT_SHARE_KEY_LIFE;
134 } else {
135 $this->life = max(min($this->life, self::MAX_SHARE_KEY_LIFE), 0);
136 }
137 $this->expires = time() + ($this->life * 60 * 60);
138 if (empty($this->id)) {
139 if (empty($this->length) || !is_numeric($this->length)) {
140 $this->length = self::MAX_SHARE_KEY_LENGTH;
141 } else {
142 $this->length = max(min($this->length, self::MAX_SHARE_KEY_LENGTH), self::MIN_SHARE_KEY_LENGTH);
143 }
144 $this->id = Util::getRandomString($this->length);
145 }
146
147 return $this->dataConnector->saveResourceLinkShareKey($this);
148 }
149
155 public function delete()
156 {
157 return $this->dataConnector->deleteResourceLinkShareKey($this);
158 }
159
165 public function getId()
166 {
167 return $this->id;
168 }
169
170###
171### PRIVATE METHOD
172###
173
177 private function load()
178 {
179 $this->initialize();
180 $this->dataConnector->loadResourceLinkShareKey($this);
181 if (!is_null($this->id)) {
182 $this->length = strlen(strval($this->id));
183 }
184 if (!is_null($this->expires)) {
185 $this->life = ($this->expires - time()) / 60 / 60;
186 }
187 }
188
189}
Class to provide a connection to a persistent store for LTI objects.
Class to represent a platform resource link share key.
$resourceLinkId
ID for resource link being shared.
const MAX_SHARE_KEY_LENGTH
Maximum length for a share key value.
const MIN_SHARE_KEY_LENGTH
Minimum length for a share key value.
$expires
Timestamp for when the share key expires.
__construct($resourceLink, $id=null)
Class constructor.
$autoApprove
Whether the sharing arrangement should be automatically approved when first used.
initialize()
Initialise the resource link share key.
const DEFAULT_SHARE_KEY_LIFE
Default life for a share key value.
const MAX_SHARE_KEY_LIFE
Maximum permitted life for a share key value.
initialise()
Initialise the resource link share key.
save()
Save the resource link share key to the database.
static getRandomString($length=8)
Generate a random string.
Definition Util.php:523