ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
IMSGlobal\LTI\ToolProvider\Context Class Reference

Class to represent a tool consumer context. More...

+ Collaboration diagram for IMSGlobal\LTI\ToolProvider\Context:

Public Member Functions

 __construct ()
 Class constructor. More...
 
 initialize ()
 Initialise the context. More...
 
 initialise ()
 Initialise the context. More...
 
 save ()
 Save the context to the database. More...
 
 delete ()
 Delete the context from the database. More...
 
 getConsumer ()
 Get tool consumer. More...
 
 setConsumerId ($consumerId)
 Set tool consumer ID. More...
 
 getKey ()
 Get tool consumer key. More...
 
 getId ()
 Get context ID. More...
 
 getRecordId ()
 Get the context record ID. More...
 
 setRecordId ($id)
 Sets the context record ID. More...
 
 getDataConnector ()
 Get the data connector. More...
 
 getSetting ($name, $default='')
 Get a setting value. More...
 
 setSetting ($name, $value=null)
 Set a setting value. More...
 
 getSettings ()
 Get an array of all setting values. More...
 
 setSettings ($settings)
 Set an array of all setting values. More...
 
 saveSettings ()
 Save setting values. More...
 
 hasToolSettingsService ()
 Check if the Tool Settings service is supported. More...
 
 getToolSettings ($mode=Service\ToolSettings::MODE_CURRENT_LEVEL, $simple=true)
 Get Tool Settings. More...
 
 setToolSettings ($settings=array())
 Perform a Tool Settings service request. More...
 
 hasMembershipService ()
 Check if the Membership service is supported. More...
 
 getMembership ()
 Get Memberships. More...
 

Static Public Member Functions

static fromRecordId ($id, $dataConnector)
 Load the context from the database. More...
 
static fromConsumer ($consumer, $ltiContextId)
 Class constructor from consumer. More...
 

Data Fields

 $ltiContextId = null
 Context ID as supplied in the last connection request. More...
 
 $title = null
 Context title. More...
 
 $settings = null
 Setting values (LTI parameters, custom parameters and local parameters). More...
 
 $created = null
 Date/time when the object was created. More...
 
 $updated = null
 Date/time when the object was last updated. More...
 

Private Member Functions

 load ($id=null)
 Load the context from the database. More...
 

Private Attributes

 $consumer = null
 Tool Consumer for this context. More...
 
 $consumerId = null
 Tool Consumer ID for this context. More...
 
 $id = null
 ID for this context. More...
 
 $settingsChanged = false
 Whether the settings value have changed since last saved. More...
 
 $dataConnector = null
 Data connector object or string. More...
 

Detailed Description

Class to represent a tool consumer context.

Author
Stephen P Vickers svick.nosp@m.ers@.nosp@m.imsgl.nosp@m.obal.nosp@m..org
Date
2016
Version
3.0.2 @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0

Definition at line 17 of file Context.php.

Constructor & Destructor Documentation

◆ __construct()

IMSGlobal\LTI\ToolProvider\Context::__construct ( )

Class constructor.

Definition at line 85 of file Context.php.

86 {
87
88 $this->initialize();
89
90 }
initialize()
Initialise the context.
Definition: Context.php:95

References IMSGlobal\LTI\ToolProvider\Context\initialize().

+ Here is the call graph for this function:

Member Function Documentation

◆ delete()

IMSGlobal\LTI\ToolProvider\Context::delete ( )

Delete the context from the database.

Returns
boolean True if the context was successfully deleted.

Definition at line 139 of file Context.php.

140 {
141
142 return $this->getDataConnector()->deleteContext($this);
143
144 }
getDataConnector()
Get the data connector.
Definition: Context.php:227

References IMSGlobal\LTI\ToolProvider\Context\getDataConnector().

+ Here is the call graph for this function:

◆ fromConsumer()

static IMSGlobal\LTI\ToolProvider\Context::fromConsumer (   $consumer,
  $ltiContextId 
)
static

Class constructor from consumer.

Parameters
ToolConsumer$consumerConsumer instance
string$ltiContextIdLTI Context ID value
Returns
Context

Definition at line 425 of file Context.php.

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 }
$ltiContextId
Context ID as supplied in the last connection request.
Definition: Context.php:25
$consumer
Tool Consumer for this context.
Definition: Context.php:56

References IMSGlobal\LTI\ToolProvider\Context\$consumer, and IMSGlobal\LTI\ToolProvider\Context\$ltiContextId.

Referenced by IMSGlobal\LTI\ToolProvider\ToolProvider\authenticate().

+ Here is the caller graph for this function:

◆ fromRecordId()

static IMSGlobal\LTI\ToolProvider\Context::fromRecordId (   $id,
  $dataConnector 
)
static

Load the context from the database.

Parameters
int$idRecord ID of context
DataConnector$dataConnectorDatabase connection object
Returns
Context Context object

Definition at line 407 of file Context.php.

408 {
409
410 $context = new Context();
411 $context->dataConnector = $dataConnector;
412 $context->load($id);
413
414 return $context;
415
416 }
$id
ID for this context.
Definition: Context.php:68
$dataConnector
Data connector object or string.
Definition: Context.php:80

References IMSGlobal\LTI\ToolProvider\Context\$dataConnector, and IMSGlobal\LTI\ToolProvider\Context\$id.

Referenced by IMSGlobal\LTI\ToolProvider\ResourceLink\getContext().

+ Here is the caller graph for this function:

◆ getConsumer()

IMSGlobal\LTI\ToolProvider\Context::getConsumer ( )

Get tool consumer.

Returns
ToolConsumer Tool consumer object for this context.

Definition at line 151 of file Context.php.

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 }
static fromRecordId($id, $dataConnector)
Load the tool consumer from the database by its record ID.

References IMSGlobal\LTI\ToolProvider\Context\$consumer, IMSGlobal\LTI\ToolProvider\ToolConsumer\fromRecordId(), and IMSGlobal\LTI\ToolProvider\Context\getDataConnector().

Referenced by IMSGlobal\LTI\ToolProvider\Context\getKey().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDataConnector()

IMSGlobal\LTI\ToolProvider\Context::getDataConnector ( )

Get the data connector.

Returns
mixed Data connector object or string

Definition at line 227 of file Context.php.

228 {
229
231
232 }

References IMSGlobal\LTI\ToolProvider\Context\$dataConnector.

Referenced by IMSGlobal\LTI\ToolProvider\Context\delete(), IMSGlobal\LTI\ToolProvider\Context\getConsumer(), IMSGlobal\LTI\ToolProvider\Context\load(), and IMSGlobal\LTI\ToolProvider\Context\save().

+ Here is the caller graph for this function:

◆ getId()

IMSGlobal\LTI\ToolProvider\Context::getId ( )

Get context ID.

Returns
string ID for this context.

Definition at line 191 of file Context.php.

192 {
193
194 return $this->ltiContextId;
195
196 }

References IMSGlobal\LTI\ToolProvider\Context\$ltiContextId.

◆ getKey()

IMSGlobal\LTI\ToolProvider\Context::getKey ( )

Get tool consumer key.

Returns
string Consumer key value for this context.

Definition at line 179 of file Context.php.

180 {
181
182 return $this->getConsumer()->getKey();
183
184 }
getConsumer()
Get tool consumer.
Definition: Context.php:151

References IMSGlobal\LTI\ToolProvider\Context\getConsumer().

+ Here is the call graph for this function:

◆ getMembership()

IMSGlobal\LTI\ToolProvider\Context::getMembership ( )

Get Memberships.

Returns
mixed The array of User objects if successful, otherwise false

Definition at line 388 of file Context.php.

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 }
getSetting($name, $default='')
Get a setting value.
Definition: Context.php:242
$service
Definition: login.php:15
$url
$response

References $response, $service, $url, and IMSGlobal\LTI\ToolProvider\Context\getSetting().

+ Here is the call graph for this function:

◆ getRecordId()

IMSGlobal\LTI\ToolProvider\Context::getRecordId ( )

Get the context record ID.

Returns
int Context record ID value

Definition at line 203 of file Context.php.

204 {
205
206 return $this->id;
207
208 }

References IMSGlobal\LTI\ToolProvider\Context\$id.

◆ getSetting()

IMSGlobal\LTI\ToolProvider\Context::getSetting (   $name,
  $default = '' 
)

Get a setting value.

Parameters
string$nameName of setting
string$defaultValue to return if the setting does not exist (optional, default is an empty string)
Returns
string Setting value

Definition at line 242 of file Context.php.

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 }
if($format !==null) $name
Definition: metadata.php:146
settings()
Definition: settings.php:2

References $name, and settings().

Referenced by IMSGlobal\LTI\ToolProvider\Context\getMembership(), IMSGlobal\LTI\ToolProvider\Context\getToolSettings(), IMSGlobal\LTI\ToolProvider\Context\hasMembershipService(), IMSGlobal\LTI\ToolProvider\Context\hasToolSettingsService(), IMSGlobal\LTI\ToolProvider\Context\setSetting(), and IMSGlobal\LTI\ToolProvider\Context\setToolSettings().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSettings()

IMSGlobal\LTI\ToolProvider\Context::getSettings ( )

Get an array of all setting values.

Returns
array Associative array of setting values

Definition at line 281 of file Context.php.

282 {
283
284 return $this->settings;
285
286 }
$settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: Context.php:37

References IMSGlobal\LTI\ToolProvider\Context\$settings.

◆ getToolSettings()

IMSGlobal\LTI\ToolProvider\Context::getToolSettings (   $mode = Service\ToolSettings::MODE_CURRENT_LEVEL,
  $simple = true 
)

Get Tool Settings.

Parameters
int$modeMode for request (optional, default is current level only)
boolean$simpleTrue if all the simple media type is to be used (optional, default is true)
Returns
mixed The array of settings if successful, otherwise false

Definition at line 340 of file Context.php.

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 }

References $response, $service, $url, and IMSGlobal\LTI\ToolProvider\Context\getSetting().

+ Here is the call graph for this function:

◆ hasMembershipService()

IMSGlobal\LTI\ToolProvider\Context::hasMembershipService ( )

Check if the Membership service is supported.

Returns
boolean True if this context supports the Membership service

Definition at line 374 of file Context.php.

375 {
376
377 $url = $this->getSetting('custom_context_memberships_url');
378
379 return !empty($url);
380
381 }

References $url, and IMSGlobal\LTI\ToolProvider\Context\getSetting().

+ Here is the call graph for this function:

◆ hasToolSettingsService()

IMSGlobal\LTI\ToolProvider\Context::hasToolSettingsService ( )

Check if the Tool Settings service is supported.

Returns
boolean True if this context supports the Tool Settings service

Definition at line 323 of file Context.php.

324 {
325
326 $url = $this->getSetting('custom_context_setting_url');
327
328 return !empty($url);
329
330 }

References $url, and IMSGlobal\LTI\ToolProvider\Context\getSetting().

+ Here is the call graph for this function:

◆ initialise()

IMSGlobal\LTI\ToolProvider\Context::initialise ( )

Initialise the context.

Pseudonym for initialize().

Definition at line 110 of file Context.php.

111 {
112
113 $this->initialize();
114
115 }

References IMSGlobal\LTI\ToolProvider\Context\initialize().

+ Here is the call graph for this function:

◆ initialize()

IMSGlobal\LTI\ToolProvider\Context::initialize ( )

Initialise the context.

Definition at line 95 of file Context.php.

96 {
97
98 $this->title = '';
99 $this->settings = array();
100 $this->created = null;
101 $this->updated = null;
102
103 }

References settings().

Referenced by IMSGlobal\LTI\ToolProvider\Context\__construct(), IMSGlobal\LTI\ToolProvider\Context\initialise(), and IMSGlobal\LTI\ToolProvider\Context\load().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load()

IMSGlobal\LTI\ToolProvider\Context::load (   $id = null)
private

Load the context from the database.

Parameters
int$idRecord ID of context (optional, default is null)
Returns
boolean True if context was successfully loaded

Definition at line 451 of file Context.php.

452 {
453
454 $this->initialize();
455 $this->id = $id;
456 return $this->getDataConnector()->loadContext($this);
457
458 }

References IMSGlobal\LTI\ToolProvider\Context\$id, IMSGlobal\LTI\ToolProvider\Context\getDataConnector(), and IMSGlobal\LTI\ToolProvider\Context\initialize().

+ Here is the call graph for this function:

◆ save()

IMSGlobal\LTI\ToolProvider\Context::save ( )

Save the context to the database.

Returns
boolean True if the context was successfully saved.

Definition at line 122 of file Context.php.

123 {
124
125 $ok = $this->getDataConnector()->saveContext($this);
126 if ($ok) {
127 $this->settingsChanged = false;
128 }
129
130 return $ok;
131
132 }

References $ok, and IMSGlobal\LTI\ToolProvider\Context\getDataConnector().

Referenced by IMSGlobal\LTI\ToolProvider\Context\saveSettings().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveSettings()

IMSGlobal\LTI\ToolProvider\Context::saveSettings ( )

Save setting values.

Returns
boolean True if the settings were successfully saved

Definition at line 305 of file Context.php.

306 {
307
308 if ($this->settingsChanged) {
309 $ok = $this->save();
310 } else {
311 $ok = true;
312 }
313
314 return $ok;
315
316 }
save()
Save the context to the database.
Definition: Context.php:122

References $ok, and IMSGlobal\LTI\ToolProvider\Context\save().

+ Here is the call graph for this function:

◆ setConsumerId()

IMSGlobal\LTI\ToolProvider\Context::setConsumerId (   $consumerId)

Set tool consumer ID.

Parameters
int$consumerIdTool Consumer ID for this resource link.

Definition at line 166 of file Context.php.

167 {
168
169 $this->consumer = null;
170 $this->consumerId = $consumerId;
171
172 }
$consumerId
Tool Consumer ID for this context.
Definition: Context.php:62

References IMSGlobal\LTI\ToolProvider\Context\$consumerId.

◆ setRecordId()

IMSGlobal\LTI\ToolProvider\Context::setRecordId (   $id)

Sets the context record ID.

Returns
int $id Context record ID value

Definition at line 215 of file Context.php.

216 {
217
218 $this->id = $id;
219
220 }

References IMSGlobal\LTI\ToolProvider\Context\$id.

◆ setSetting()

IMSGlobal\LTI\ToolProvider\Context::setSetting (   $name,
  $value = null 
)

Set a setting value.

Parameters
string$nameName of setting
string$valueValue to set, use an empty value to delete a setting (optional, default is null)

Definition at line 261 of file Context.php.

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 }

References $name, IMSGlobal\LTI\ToolProvider\Context\getSetting(), and settings().

+ Here is the call graph for this function:

◆ setSettings()

IMSGlobal\LTI\ToolProvider\Context::setSettings (   $settings)

Set an array of all setting values.

Parameters
array$settingsAssociative array of setting values

Definition at line 293 of file Context.php.

294 {
295
296 $this->settings = $settings;
297
298 }

References IMSGlobal\LTI\ToolProvider\Context\$settings, and settings().

+ Here is the call graph for this function:

◆ setToolSettings()

IMSGlobal\LTI\ToolProvider\Context::setToolSettings (   $settings = array())

Perform a Tool Settings service request.

Parameters
array$settingsAn associative array of settings (optional, default is none)
Returns
boolean True if action was successful, otherwise false

Definition at line 358 of file Context.php.

359 {
360
361 $url = $this->getSetting('custom_context_setting_url');
362 $service = new Service\ToolSettings($this, $url);
364
365 return $response;
366
367 }

References $response, $service, IMSGlobal\LTI\ToolProvider\Context\$settings, $url, and IMSGlobal\LTI\ToolProvider\Context\getSetting().

+ Here is the call graph for this function:

Field Documentation

◆ $consumer

ToolConsumer Context::$consumer = null
private

Tool Consumer for this context.

Definition at line 56 of file Context.php.

Referenced by IMSGlobal\LTI\ToolProvider\Context\fromConsumer(), and IMSGlobal\LTI\ToolProvider\Context\getConsumer().

◆ $consumerId

int Context::$consumerId = null
private

Tool Consumer ID for this context.

Definition at line 62 of file Context.php.

Referenced by IMSGlobal\LTI\ToolProvider\Context\setConsumerId().

◆ $created

int Context::$created = null

Date/time when the object was created.

Definition at line 43 of file Context.php.

◆ $dataConnector

mixed Context::$dataConnector = null
private

Data connector object or string.

Definition at line 80 of file Context.php.

Referenced by IMSGlobal\LTI\ToolProvider\Context\fromRecordId(), and IMSGlobal\LTI\ToolProvider\Context\getDataConnector().

◆ $id

◆ $ltiContextId

string Context::$ltiContextId = null

Context ID as supplied in the last connection request.

Definition at line 25 of file Context.php.

Referenced by IMSGlobal\LTI\ToolProvider\Context\fromConsumer(), and IMSGlobal\LTI\ToolProvider\Context\getId().

◆ $settings

array Context::$settings = null

Setting values (LTI parameters, custom parameters and local parameters).

Definition at line 37 of file Context.php.

Referenced by IMSGlobal\LTI\ToolProvider\Context\getSettings(), IMSGlobal\LTI\ToolProvider\Context\setSettings(), and IMSGlobal\LTI\ToolProvider\Context\setToolSettings().

◆ $settingsChanged

boolean Context::$settingsChanged = false
private

Whether the settings value have changed since last saved.

Definition at line 74 of file Context.php.

◆ $title

string Context::$title = null

Context title.

Definition at line 31 of file Context.php.

◆ $updated

int Context::$updated = null

Date/time when the object was last updated.

Definition at line 49 of file Context.php.


The documentation for this class was generated from the following file: