95 private $platform =
null;
102 private $platformId =
null;
116 private $settings =
null;
123 private $settingsChanged =
false;
130 private $dataConnector =
null;
146 $this->settings = array();
147 $this->groupSets =
null;
148 $this->groups =
null;
149 $this->created =
null;
150 $this->updated =
null;
168 public function save()
172 $this->settingsChanged =
false;
183 public function delete()
198 Util::logDebug(
'Method ceLTIc\LTI\Context::getConsumer() has been deprecated; please use ceLTIc\LTI\Context::getPlatform() instead.',
213 Util::logDebug(
'Method ceLTIc\LTI\Context::setConsumerId() has been deprecated; please use ceLTIc\LTI\Context::setPlatformId() instead.',
225 if (is_null($this->platform)) {
229 return $this->platform;
239 $this->platform =
null;
240 $this->platformId = $platformId;
258 public function getId()
290 return $this->dataConnector;
301 public function getSetting($name, $default =
'')
303 if (array_key_exists($name, $this->settings)) {
304 $value = $this->settings[$name];
318 public function setSetting($name, $value =
null)
321 if ($value !== $old_value) {
322 if (!empty($value)) {
323 $this->settings[$name] = $value;
325 unset($this->settings[$name]);
327 $this->settingsChanged =
true;
338 return $this->settings;
348 $this->settings = $settings;
358 if ($this->settingsChanged) {
374 $has = !empty($this->
getSetting(
'custom_context_setting_url'));
376 $has = self::hasConfiguredApiHook(self::$TOOL_SETTINGS_SERVICE_HOOK, $this->
getPlatform()->getFamilyCode(), $this);
393 if (!empty($this->
getSetting(
'custom_context_setting_url'))) {
394 $url = $this->
getSetting(
'custom_context_setting_url');
396 $settings = $service->get($mode);
397 $this->lastServiceRequest = $service->getHttpMessage();
398 $ok = $settings !==
false;
400 if (!$ok && $this->hasConfiguredApiHook(self::$TOOL_SETTINGS_SERVICE_HOOK, $this->
getPlatform()->getFamilyCode(), $this)) {
401 $className = $this->getApiHook(self::$TOOL_SETTINGS_SERVICE_HOOK, $this->
getPlatform()->getFamilyCode());
402 $hook =
new $className($this);
403 $settings = $hook->getToolSettings($mode, $simple);
419 if (!empty($this->
getSetting(
'custom_context_setting_url'))) {
420 $url = $this->
getSetting(
'custom_context_setting_url');
422 $ok = $service->set($settings);
423 $this->lastServiceRequest = $service->getHttpMessage();
425 if (!$ok && $this->hasConfiguredApiHook(self::$TOOL_SETTINGS_SERVICE_HOOK, $this->
getPlatform()->getFamilyCode(), $this)) {
426 $className = $this->getApiHook(self::$TOOL_SETTINGS_SERVICE_HOOK, $this->
getPlatform()->getFamilyCode());
427 $hook =
new $className($this);
428 $ok = $hook->setToolSettings($settings);
441 $has = !empty($this->
getSetting(
'custom_context_groups_url'));
443 $has = self::hasConfiguredApiHook(self::$MEMBERSHIPS_SERVICE_HOOK, $this->
getPlatform()->getFamilyCode(), $this);
455 $groupsUrl = $this->
getSetting(
'custom_context_groups_url');
456 $groupsetsUrl = $this->
getSetting(
'custom_context_group_sets_url');
458 $ok = $service->get();
459 if (!empty($service->getHttpMessage())) {
460 $this->lastServiceRequest = $service->getHttpMessage();
462 if (!$ok && $this->hasConfiguredApiHook(self::$GROUPS_SERVICE_HOOK, $this->
getPlatform()->getFamilyCode(), $this)) {
463 $className = $this->getApiHook(self::$GROUPS_SERVICE_HOOK, $this->
getPlatform()->getFamilyCode());
464 $hook =
new $className($this);
465 $ok = $hook->getGroups();
481 Util::logDebug(
'Method ceLTIc\LTI\Context::hasMembershipService() has been deprecated; please use ceLTIc\LTI\Context::hasMembershipsService() instead.',
493 $has = !empty($this->
getSetting(
'custom_context_memberships_url')) || !empty($this->
getSetting(
'custom_context_memberships_v2_url'));
495 $has = self::hasConfiguredApiHook(self::$MEMBERSHIPS_SERVICE_HOOK, $this->
getPlatform()->getFamilyCode(), $this);
510 Util::logDebug(
'Method ceLTIc\LTI\Context::getMembership() has been deprecated; please use ceLTIc\LTI\Context::getMemberships() instead.',
525 $userResults = array();
526 $hasMembershipsService = !empty($this->
getSetting(
'custom_context_memberships_url'));
527 $hasNRPService = !empty($this->
getSetting(
'custom_context_memberships_v2_url'));
528 $hasGroupsService = !empty($this->
getSetting(
'custom_context_groups_url')) ||
529 $this->hasConfiguredApiHook(self::$GROUPS_SERVICE_HOOK, $this->
getPlatform()->getFamilyCode(), $this);
530 $hasApiHook = $this->hasConfiguredApiHook(self::$MEMBERSHIPS_SERVICE_HOOK, $this->
getPlatform()->getFamilyCode(), $this);
531 if (($hasMembershipsService || $hasNRPService) && (!$withGroups || ($hasNRPService && $hasGroupsService) || !$hasApiHook)) {
532 if ($hasNRPService) {
533 $url = $this->
getSetting(
'custom_context_memberships_v2_url');
534 $format = Service\Membership::MEDIA_TYPE_MEMBERSHIPS_NRPS;
536 $url = $this->
getSetting(
'custom_context_memberships_url');
537 $format = Service\Membership::MEDIA_TYPE_MEMBERSHIPS_V1;
540 if (!$withGroups || !$hasNRPService) {
541 $userResults = $service->get();
543 $userResults = $service->getWithGroups();
545 if (!empty($service->getHttpMessage())) {
546 $this->lastServiceRequest = $service->getHttpMessage();
548 $ok = $userResults !==
false;
550 if (!$ok && $hasApiHook) {
551 $className = $this->getApiHook(self::$MEMBERSHIPS_SERVICE_HOOK, $this->
getPlatform()->getFamilyCode());
552 $hook =
new $className($this);
553 $userResults = $hook->getMemberships($withGroups);
567 if (!empty($this->
getSetting(
'custom_ags_scopes'))) {
568 $scopes = explode(
',', $this->
getSetting(
'custom_ags_scopes'));
569 if (in_array(
Service\LineItem::$SCOPE, $scopes) || in_array(
Service\LineItem::$SCOPE_READONLY, $scopes)) {
570 $has = !empty($this->
getSetting(
'custom_lineitems_url'));
585 if (!empty($this->
getSetting(
'custom_ags_scopes'))) {
586 $scopes = explode(
',', $this->
getSetting(
'custom_ags_scopes'));
588 $has = !empty($this->
getSetting(
'custom_lineitems_url'));
603 if (!empty($this->
getSetting(
'custom_ags_scopes'))) {
604 $scopes = explode(
',', $this->
getSetting(
'custom_ags_scopes'));
606 $has = !empty($this->
getSetting(
'custom_lineitems_url'));
622 public function getLineItems($resourceId =
null, $tag =
null, $limit =
null)
625 $this->lastServiceRequest =
null;
626 $lineItemService = $this->getLineItemService();
627 if (!empty($lineItemService)) {
628 $lineItems = $lineItemService->getAll(
null, $resourceId, $tag);
629 $http = $lineItemService->getHttpMessage();
630 $this->lastServiceRequest = $http;
646 $lineItemService = $this->getLineItemService();
647 if (!empty($lineItemService)) {
648 $ok = $lineItemService->createLineItem($lineItem);
662 public static function fromRecordId($id, $dataConnector)
665 $context->dataConnector = $dataConnector;
698 $context->platform = $platform;
699 $context->dataConnector = $platform->getDataConnector();
719 private function load($id =
null)
731 private function getLineItemService()
733 $url = $this->
getSetting(
'custom_lineitems_url');
737 $lineItemService =
false;
740 return $lineItemService;
Trait to handle API hook registrations.
Class to represent a platform context.
$groups
User groups (null if the platform does not support the groups enhancement)
hasMembershipsService()
Check if a Membership service is available.
__construct()
Class constructor.
$ltiContextId
Context ID as supplied in the last connection request.
getMemberships($withGroups=false)
Get Memberships.
hasToolSettingsService()
Check if the Tool Settings service is available.
$lastServiceRequest
HttpMessage object for last service request.
hasScoreService()
Check if the Score service is available.
$updated
Timestamp for when the object was last updated.
getGroups()
Get course group sets and groups.
getMembership()
Get Membership.
setSetting($name, $value=null)
Set a setting value.
getDataConnector()
Get the data connector.
getConsumer()
Get tool consumer.
hasLineItemService()
Check if the Line-item service is available.
getToolSettings($mode=Service\ToolSettings::MODE_CURRENT_LEVEL, $simple=true)
Get Tool Settings.
setPlatformId($platformId)
Set platform ID.
hasMembershipService()
Check if the Membership service is supported.
setToolSettings($settings=array())
Set Tool Settings.
setConsumerId($consumerId)
Set tool consumer ID.
static fromPlatform($platform, $ltiContextId)
Class constructor from platform.
$groupSets
User group sets (null if the platform does not support the groups enhancement)
initialize()
Initialise the context.
saveSettings()
Save setting values.
$created
Timestamp for when the object was created.
hasResultService()
Check if the Result service is available.
setSettings($settings)
Set an array of all setting values.
static fromConsumer($consumer, $ltiContextId)
Class constructor from consumer.
hasGroupService()
Check if a Course Group service is available.
getPlatform()
Get platform.
getRecordId()
Get the context record ID.
getKey()
Get consumer key.
getSetting($name, $default='')
Get a setting value.
getLineItems($resourceId=null, $tag=null, $limit=null)
Get line-items.
setRecordId($id)
Sets the context record ID.
initialise()
Initialise the context.
getSettings()
Get an array of all setting values.
save()
Save the context to the database.
createLineItem($lineItem)
Create a new line-item.
static fromRecordId($id, $dataConnector)
Load the context from the database.
Class to represent an HTTP message request.
Class to represent a line-item.
Class to implement the Course Groups service.
Class to implement the Membership service.
static $SCOPE
Access scope.
static $SCOPE
Access scope.
Class to implement a service.
Class to implement utility methods.
static logDebug($message, $showSource=false)
Log a debug message.