ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLTIPlatform.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ceLTIc\LTI\DataConnector\DataConnector;
22use ceLTIc\LTI\Enum\IdScope;
23use ceLTIc\LTI\Platform;
24use ceLTIc\LTI\Util;
25
32class ilLTIPlatform extends Platform
33{
37 protected int $ref_id = 0;
38
42 protected int $ext_consumer_id = 0;
43
47 protected string $title = '';
48
52 protected string $description = '';
53
57 protected string $prefix = '';
58
62 protected string $user_language = '';
63
67 protected int $role = 0;
68
72 protected bool $active = false;
73
79 private ?array $settings = null;
80
86 private ?int $id = null;
87
93 private ?string $key = null;
94
99 public function __construct(?ilLTIDataConnector $dataConnector = null)
100 {
101 $this->initialize();
102 if (empty($dataConnector)) {
103 $dataConnector = ilLTIDataConnector::getDataConnector();
104 }
105 $this->dataConnector = $dataConnector;
106 }
107
111 public function initialize(): void
112 {
113 $this->id = null;
114 $this->key = null;
115 $this->name = null;
116 $this->secret = null;
117 $this->signatureMethod = 'HMAC-SHA1';
118 $this->encryptionMethod = '';
119 $this->rsaKey = null;
120 $this->kid = null;
121 $this->jku = '';
122 $this->platformId = null;
123 $this->clientId = null;
124 $this->deploymentId = null;
125 $this->ltiVersion = null;
126 $this->consumerName = null;
127 $this->consumerVersion = null;
128 $this->consumerGuid = null;
129 $this->profile = null;
130 $this->toolProxy = null;
131 $this->settings = array();
132 $this->setSettings(array());
133 $this->protected = false;
134 $this->enabled = false;
135 $this->enableFrom = null;
136 $this->enableUntil = null;
137 $this->lastAccess = null;
138 $this->idScope = IdScope::IdOnly;
139 $this->defaultEmail = '';
140 $this->created = null;
141 $this->updated = null;
142 //added
143 $this->authorizationServerId = '';
144 $this->authenticationUrl = '';
145 $this->accessTokenUrl = '';
146 $this->debugMode = false;
147 }
148
149
150 public function setExtConsumerId(int $a_id): void
151 {
152 $this->ext_consumer_id = $a_id;
153 }
154
155 public function getExtConsumerId(): int
156 {
158 }
159
160 public function setRefId(int $a_ref_id): void
161 {
162 $this->ref_id = $a_ref_id;
163 }
164
165 public function getRefId(): int
166 {
167 return $this->ref_id;
168 }
169
170 // public function getId() : ?int
171 // {
172 // return $this->getRecordId();
173 // }
174
175 public function setTitle(string $title): void
176 {
177 $this->title = $title;
178 // $this->consumerName = $title;
179 }
180
181 public function getTitle(): string
182 {
183 return $this->title;
184 }
185
186 public function setDescription(string $description): void
187 {
188 $this->description = $description;
189 }
190
191 public function getDescription(): string
192 {
193 return $this->description;
194 }
195
196 public function setPrefix(string $prefix): void
197 {
198 $this->prefix = $prefix;
199 }
200
201 public function getPrefix(): string
202 {
203 return $this->prefix;
204 }
205
206 public function setSecret(string $secret): void
207 {
208 $this->secret = $secret;
209 }
210
211 public function getSecret(): ?string
212 {
213 return $this->secret;
214 }
215
219 public function createSecret(): void
220 {
221 $this->setSecret(Util::getRandomString(12));
222 }
223
227 public function setLanguage(string $lang): void
228 {
229 $this->user_language = $lang;
230 }
231
232 public function getLanguage(): string
233 {
235 }
236
237 public function setActive(bool $value): void
238 {
239 $this->active = $value;
240 }
241
242 public function getActive(): bool
243 {
244 return $this->active;
245 }
246
247 public function setRole(int $role_id): void
248 {
249 $this->role = $role_id;
250 }
251
252 public function getRole(): int
253 {
254 return $this->role;
255 }
256
257
258 public function setEnabled(bool $a_status): void
259 {
260 $this->enabled = $a_status;
261 }
262
263 public function getEnabled(): bool
264 {
265 return $this->enabled;
266 }
267
268 // local_role_always_member, default_skin
269
279 public static function fromPlatformId(string $platformId, ?string $clientId, ?string $deploymentId, ?DataConnector $dataConnector = null, bool $autoEnable = false): ilLTIPlatform
280 {
281 $platform = new ilLTIPlatform($dataConnector);
282 $platform->initialize();
283 $platform->platformId = $platformId;
284 $platform->clientId = $clientId;
285 $platform->deploymentId = $deploymentId;
286 $dataConnector->loadPlatform($platform);
287 $dataConnector->loadGlobalToolConsumerSettings($platform);
288 return $platform;
289 }
290
298 public static function fromConsumerKey(?string $key = null, $dataConnector = null, bool $autoEnable = false): ilLTIPlatform
299 {
300 $platform = new ilLTIPlatform($dataConnector);
301 $platform->initialize();
302 $platform->setKey($key);
303 ilLoggerFactory::getLogger('ltis')->debug('Loading with key: ' . $platform->getKey());
304 $dataConnector->loadPlatform($platform);
305 $dataConnector->loadGlobalToolConsumerSettings($platform);
306 return $platform;
307 }
308
315 public static function fromRecordId(int|string $id, DataConnector $dataConnector): ilLTIPlatform
316 {
317 // $platform = new static($dataConnector);
318 $platform = new ilLTIPlatform($dataConnector);
319 $platform->initialize();
320 $platform->setRecordId((int) $id);
321 ilLoggerFactory::getLogger('ltis')->info('Loading with record id: ' . $platform->getRecordId());
322 $dataConnector->loadPlatform($platform);
323 $dataConnector->loadGlobalToolConsumerSettings($platform);
324 return $platform;
325 }
326
332 public static function fromExternalConsumerId(int $id, ilLTIDataConnector $dataConnector): ilLTIPlatform
333 {
334 $platform = new ilLTIPlatform($dataConnector);
335 //$platform->setRecordId((int) $id);
336 //$dataConnector->loadPlatform($platform);
337 $platform->initialize();
338 $platform->setExtConsumerId($id);
339 if (!$dataConnector->loadGlobalToolConsumerSettings($platform)) {
340 $platform->initialize();
341 }
342 return $platform;
343 }
344
352 public static function fromGlobalSettingsAndRefId(int $a_ext_consumer_id, int $a_ref_id, ilLTIDataConnector $a_data_connector): ilLTIPlatform
353 {
354 $toolConsumer = new ilLTIPlatform(null, $a_data_connector);
355 $toolConsumer->initialize();
356 $toolConsumer->setExtConsumerId($a_ext_consumer_id);
357 $toolConsumer->setRefId($a_ref_id);
358
359 $consumer_pk = $a_data_connector->lookupRecordIdByGlobalSettingsAndRefId($toolConsumer);
360 if ($consumer_pk != null) {
361 $toolConsumer = self::fromRecordId($consumer_pk, $a_data_connector);
362 }
363 return $toolConsumer;
364 }
365
366
371 public function saveGlobalToolConsumerSettings(ilLTIDataConnector $dataConnector): void
372 {
373 $dataConnector->saveGlobalToolConsumerSettings($this);
374 }
375
380 public function deleteGlobalToolConsumerSettings(ilLTIDataConnector $dataConnector): void
381 {
382 $dataConnector->deleteGlobalToolConsumerSettings($this);
383 }
384
390 public function saveLTI(ilLTIDataConnector $dataConnector): bool
391 {
392 $ok = $dataConnector->saveToolConsumerILIAS($this);
393 return $ok;
394 }
395}
lookupRecordIdByGlobalSettingsAndRefId(ilLTIPlatform $platform)
Lookup record id for global settings and ref_id.
static getDataConnector(mixed $db=null, string $dbTableNamePrefix='', string $type='')
loadGlobalToolConsumerSettings(ilLTIPlatform $platform)
Load global tool consumer settings in consumer.
saveGlobalToolConsumerSettings(ilLTIPlatform $platform)
Save lti_ext_consumer.
deleteGlobalToolConsumerSettings(ilLTIPlatform $platform)
Delete global tool consumer settings.
saveToolConsumerILIAS(ilLTIPlatform $platform)
Save extended tool consumer object with ILIAS extensions.
LTI provider for LTI launch.
static fromExternalConsumerId(int $id, ilLTIDataConnector $dataConnector)
static fromGlobalSettingsAndRefId(int $a_ext_consumer_id, int $a_ref_id, ilLTIDataConnector $a_data_connector)
Load consumer from global settings and ref_id.
string $key
Consumer key/client ID value.
initialize()
Initialise the platform.
createSecret()
Create a secret.
static fromRecordId(int|string $id, DataConnector $dataConnector)
Load the platform from the database by its record ID.
setDescription(string $description)
static fromPlatformId(string $platformId, ?string $clientId, ?string $deploymentId, ?DataConnector $dataConnector=null, bool $autoEnable=false)
Load the platform from the database by its platform, client and deployment IDs.
static fromConsumerKey(?string $key=null, $dataConnector=null, bool $autoEnable=false)
Load the platform from the database by its consumer key.
saveGlobalToolConsumerSettings(ilLTIDataConnector $dataConnector)
Save global consumer settings.
setRefId(int $a_ref_id)
setTitle(string $title)
setActive(bool $value)
deleteGlobalToolConsumerSettings(ilLTIDataConnector $dataConnector)
Delete global tool consumer settings.
setEnabled(bool $a_status)
setSecret(string $secret)
__construct(?ilLTIDataConnector $dataConnector=null)
Class constructor.
setLanguage(string $lang)
setPrefix(string $prefix)
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
setExtConsumerId(int $a_id)
saveLTI(ilLTIDataConnector $dataConnector)
Save the tool consumer to the database with ILIAS extension.
setRole(int $role_id)
int $id
System ID value.
static getLogger(string $a_component_id)
Get component logger.
$clientId
Definition: ltiregend.php:26
$lang
Definition: xapiexit.php:25