ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Context.php
Go to the documentation of this file.
1<?php
2
4
7
18{
19
25 public $ltiContextId = null;
31 public $title = null;
37 public $settings = null;
43 public $created = null;
49 public $updated = null;
50
56 private $consumer = null;
62 private $consumerId = null;
68 private $id = null;
74 private $settingsChanged = false;
80 private $dataConnector = null;
81
85 public function __construct()
86 {
87
88 $this->initialize();
89
90 }
91
95 public function initialize()
96 {
97
98 $this->title = '';
99 $this->settings = array();
100 $this->created = null;
101 $this->updated = null;
102
103 }
104
110 public function initialise()
111 {
112
113 $this->initialize();
114
115 }
116
122 public function save()
123 {
124
125 $ok = $this->getDataConnector()->saveContext($this);
126 if ($ok) {
127 $this->settingsChanged = false;
128 }
129
130 return $ok;
131
132 }
133
139 public function delete()
140 {
141
142 return $this->getDataConnector()->deleteContext($this);
143
144 }
145
151 public function getConsumer()
152 {
153
154 if (is_null($this->consumer)) {
155 $this->consumer = ToolConsumer::fromRecordId($this->consumerId, $this->getDataConnector());
156 }
157
158 return $this->consumer;
159
160 }
166 public function setConsumerId($consumerId)
167 {
168
169 $this->consumer = null;
170 $this->consumerId = $consumerId;
171
172 }
173
179 public function getKey()
180 {
181
182 return $this->getConsumer()->getKey();
183
184 }
185
191 public function getId()
192 {
193
194 return $this->ltiContextId;
195
196 }
197
203 public function getRecordId()
204 {
205
206 return $this->id;
207
208 }
209
215 public function setRecordId($id)
216 {
217
218 $this->id = $id;
219
220 }
221
227 public function getDataConnector()
228 {
229
231
232 }
233
242 public function getSetting($name, $default = '')
243 {
244
245 if (array_key_exists($name, $this->settings)) {
246 $value = $this->settings[$name];
247 } else {
248 $value = $default;
249 }
250
251 return $value;
252
253 }
254
261 public function setSetting($name, $value = null)
262 {
263
264 $old_value = $this->getSetting($name);
265 if ($value !== $old_value) {
266 if (!empty($value)) {
267 $this->settings[$name] = $value;
268 } else {
269 unset($this->settings[$name]);
270 }
271 $this->settingsChanged = true;
272 }
273
274 }
275
281 public function getSettings()
282 {
283
284 return $this->settings;
285
286 }
287
293 public function setSettings($settings)
294 {
295
296 $this->settings = $settings;
297
298 }
299
305 public function saveSettings()
306 {
307
308 if ($this->settingsChanged) {
309 $ok = $this->save();
310 } else {
311 $ok = true;
312 }
313
314 return $ok;
315
316 }
317
323 public function hasToolSettingsService()
324 {
325
326 $url = $this->getSetting('custom_context_setting_url');
327
328 return !empty($url);
329
330 }
331
340 public function getToolSettings($mode = Service\ToolSettings::MODE_CURRENT_LEVEL, $simple = true)
341 {
342
343 $url = $this->getSetting('custom_context_setting_url');
344 $service = new Service\ToolSettings($this, $url, $simple);
345 $response = $service->get($mode);
346
347 return $response;
348
349 }
350
358 public function setToolSettings($settings = array())
359 {
360
361 $url = $this->getSetting('custom_context_setting_url');
362 $service = new Service\ToolSettings($this, $url);
363 $response = $service->set($settings);
364
365 return $response;
366
367 }
368
374 public function hasMembershipService()
375 {
376
377 $url = $this->getSetting('custom_context_memberships_url');
378
379 return !empty($url);
380
381 }
382
388 public function getMembership()
389 {
390
391 $url = $this->getSetting('custom_context_memberships_url');
392 $service = new Service\Membership($this, $url);
393 $response = $service->get();
394
395 return $response;
396
397 }
398
407 public static function fromRecordId($id, $dataConnector)
408 {
409
410 $context = new Context();
411 $context->dataConnector = $dataConnector;
412 $context->load($id);
413
414 return $context;
415
416 }
417
425 public static function fromConsumer($consumer, $ltiContextId)
426 {
427
428 $context = new Context();
429 $context->consumer = $consumer;
430 $context->dataConnector = $consumer->getDataConnector();
431 $context->ltiContextId = $ltiContextId;
432 if (!empty($ltiContextId)) {
433 $context->load();
434 }
435
436 return $context;
437
438 }
439
440###
441### PRIVATE METHODS
442###
443
451 private function load($id = null)
452 {
453
454 $this->initialize();
455 $this->id = $id;
456 return $this->getDataConnector()->loadContext($this);
457
458 }
459
460}
$default
Definition: build.php:20
An exception for terminatinating execution or to throw for unit testing.
Class to represent a tool consumer context.
Definition: Context.php:18
$id
ID for this context.
Definition: Context.php:68
$ltiContextId
Context ID as supplied in the last connection request.
Definition: Context.php:25
getDataConnector()
Get the data connector.
Definition: Context.php:227
$consumerId
Tool Consumer ID for this context.
Definition: Context.php:62
getMembership()
Get Memberships.
Definition: Context.php:388
hasToolSettingsService()
Check if the Tool Settings service is supported.
Definition: Context.php:323
getKey()
Get tool consumer key.
Definition: Context.php:179
saveSettings()
Save setting values.
Definition: Context.php:305
$settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: Context.php:37
static fromConsumer($consumer, $ltiContextId)
Class constructor from consumer.
Definition: Context.php:425
getRecordId()
Get the context record ID.
Definition: Context.php:203
getSettings()
Get an array of all setting values.
Definition: Context.php:281
initialise()
Initialise the context.
Definition: Context.php:110
__construct()
Class constructor.
Definition: Context.php:85
static fromRecordId($id, $dataConnector)
Load the context from the database.
Definition: Context.php:407
save()
Save the context to the database.
Definition: Context.php:122
$consumer
Tool Consumer for this context.
Definition: Context.php:56
initialize()
Initialise the context.
Definition: Context.php:95
$created
Date/time when the object was created.
Definition: Context.php:43
$updated
Date/time when the object was last updated.
Definition: Context.php:49
setConsumerId($consumerId)
Set tool consumer ID.
Definition: Context.php:166
getConsumer()
Get tool consumer.
Definition: Context.php:151
getSetting($name, $default='')
Get a setting value.
Definition: Context.php:242
setToolSettings($settings=array())
Perform a Tool Settings service request.
Definition: Context.php:358
setRecordId($id)
Sets the context record ID.
Definition: Context.php:215
load($id=null)
Load the context from the database.
Definition: Context.php:451
$settingsChanged
Whether the settings value have changed since last saved.
Definition: Context.php:74
setSetting($name, $value=null)
Set a setting value.
Definition: Context.php:261
setSettings($settings)
Set an array of all setting values.
Definition: Context.php:293
getToolSettings($mode=Service\ToolSettings::MODE_CURRENT_LEVEL, $simple=true)
Get Tool Settings.
Definition: Context.php:340
$dataConnector
Data connector object or string.
Definition: Context.php:80
hasMembershipService()
Check if the Membership service is supported.
Definition: Context.php:374
Class to provide a connection to a persistent store for LTI objects.
Class to implement the Membership service.
Definition: Membership.php:17
Class to implement a service.
Definition: Service.php:18
Class to implement the Tool Settings service.
const MODE_CURRENT_LEVEL
Settings at current level mode.
static fromRecordId($id, $dataConnector)
Load the tool consumer from the database by its record ID.
$url
$response
settings()
Definition: settings.php:2
$context
Definition: webdav.php:25