82 private $consumer =
null;
89 private $consumerId =
null;
103 private $settings =
null;
110 private $settingsChanged =
false;
117 private $dataConnector =
null;
133 $this->settings = array();
134 $this->groupSets =
null;
135 $this->groups =
null;
136 $this->created =
null;
137 $this->updated =
null;
155 public function save()
159 $this->settingsChanged =
false;
170 public function delete()
182 if (is_null($this->consumer)) {
186 return $this->consumer;
196 $this->consumer =
null;
197 $this->consumerId = $consumerId;
215 public function getId()
247 return $this->dataConnector;
258 public function getSetting($name, $default =
'')
260 if (array_key_exists($name, $this->settings)) {
261 $value = $this->settings[$name];
275 public function setSetting($name, $value =
null)
278 if ($value !== $old_value) {
279 if (!empty($value)) {
280 $this->settings[$name] = $value;
282 unset($this->settings[$name]);
284 $this->settingsChanged =
true;
295 return $this->settings;
305 $this->settings = $settings;
315 if ($this->settingsChanged) {
331 $has = !empty($this->
getSetting(
'custom_context_setting_url'));
333 $has = self::hasApiHook(self::$TOOL_SETTINGS_SERVICE_HOOK, $this->
getConsumer()->getFamilyCode());
350 if (!empty($this->
getSetting(
'custom_context_setting_url'))) {
351 $url = $this->
getSetting(
'custom_context_setting_url');
353 $settings = $service->get($mode);
354 $this->lastServiceRequest = $service->getHTTPMessage();
355 $ok = $settings !==
false;
357 if (!$ok && $this->hasApiHook(self::$TOOL_SETTINGS_SERVICE_HOOK, $this->
getConsumer()->getFamilyCode())) {
358 $className = $this->getApiHook(self::$TOOL_SETTINGS_SERVICE_HOOK, $this->
getConsumer()->getFamilyCode());
359 $hook =
new $className($this);
360 $settings = $hook->getToolSettings($mode, $simple);
376 if (!empty($this->
getSetting(
'custom_context_setting_url'))) {
377 $url = $this->
getSetting(
'custom_context_setting_url');
379 $ok = $service->set($settings);
380 $this->lastServiceRequest = $service->getHTTPMessage();
382 if (!$ok && $this->hasApiHook(self::$TOOL_SETTINGS_SERVICE_HOOK, $this->
getConsumer()->getFamilyCode())) {
383 $className = $this->getApiHook(self::$TOOL_SETTINGS_SERVICE_HOOK, $this->
getConsumer()->getFamilyCode());
384 $hook =
new $className($this);
385 $ok = $hook->setToolSettings($settings);
411 $has = !empty($this->
getSetting(
'custom_context_memberships_url'));
413 $has = self::hasApiHook(self::$MEMBERSHIPS_SERVICE_HOOK, $this->
getConsumer()->getFamilyCode());
441 $userResults = array();
442 $hasLtiService = !empty($this->
getSetting(
'custom_context_memberships_url'));
443 $hasApiHook = $this->hasApiHook(self::$MEMBERSHIPS_SERVICE_HOOK, $this->
getConsumer()->getFamilyCode());
444 if ($hasLtiService && (!$withGroups || !$hasApiHook)) {
445 $url = $this->
getSetting(
'custom_context_memberships_url');
447 $userResults = $service->get();
448 $this->lastServiceRequest = $service->getHTTPMessage();
449 $ok = $userResults !==
false;
451 if (!$ok && $hasApiHook) {
452 $className = $this->getApiHook(self::$MEMBERSHIPS_SERVICE_HOOK, $this->
getConsumer()->getFamilyCode());
453 $hook =
new $className($this);
454 $userResults = $hook->getMemberships($withGroups);
468 public static function fromRecordId($id, $dataConnector)
471 $context->dataConnector = $dataConnector;
488 $context->consumer = $consumer;
489 $context->dataConnector = $consumer->getDataConnector();
509 private function load($id =
null)
getKey()
Get tool consumer key.
save()
Save the context to the database.
Class to implement a service.
$groupSets
UserResult group sets (null if the consumer does not support the groups enhancement)
getMembership()
Get Membership.
initialise()
Initialise the context.
$ltiContextId
Context ID as supplied in the last connection request.
Class to represent a tool consumer context.
static fromRecordId($id, $dataConnector)
Load the context from the database.
getConsumer()
Get tool consumer.
getMemberships($withGroups=false)
Get Memberships.
$groups
UserResult groups (null if the consumer does not support the groups enhancement)
getSettings()
Get an array of all setting values.
setSettings($settings)
Set an array of all setting values.
getDataConnector()
Get the data connector.
setRecordId($id)
Sets the context record ID.
getRecordId()
Get the context record ID.
hasMembershipService()
Check if the Membership service is supported.
Class to implement the Membership service.
__construct()
Class constructor.
Class to represent an HTTP message request.
$created
Timestamp for when the object was created.
hasMembershipsService()
Check if a Membership service is available.
setConsumerId($consumerId)
Set tool consumer ID.
setSetting($name, $value=null)
Set a setting value.
$updated
Timestamp for when the object was last updated.
getSetting($name, $default='')
Get a setting value.
saveSettings()
Save setting values.
Trait to handle API hook registrations.
setToolSettings($settings=array())
Perform a Tool Settings service request.
hasToolSettingsService()
Check if the Tool Settings service is available.
initialize()
Initialise the context.
static fromConsumer($consumer, $ltiContextId)
Class constructor from consumer.
getToolSettings($mode=Service\ToolSettings::MODE_CURRENT_LEVEL, $simple=true)
Get Tool Settings.
$lastServiceRequest
HTTPMessage object for last service request.