/** * Check if a share arrangement is in place. * * @return boolean True if no error is reported */ private function checkForShare() { $ok = TRUE; $doSaveResourceLink = TRUE; $key = $this->resource_link->primary_consumer_key; $id = $this->resource_link->primary_resource_link_id; $shareRequest = isset($_POST['custom_share_key']) && !empty($_POST['custom_share_key']); if ($shareRequest) { if (!$this->allowSharing) { $ok = FALSE; $this->reason = 'Your sharing request has been refused because sharing is not being permitted.'; } else { // Check if this is a new share key $share_key = new LTI_Resource_Link_Share_Key($this->resource_link, $_POST['custom_share_key']); if (!is_null($share_key->primary_consumer_key) && !is_null($share_key->primary_resource_link_id)) { // Update resource link with sharing primary resource link details $key = $share_key->primary_consumer_key; $id = $share_key->primary_resource_link_id; $ok = $key != $this->consumer->getKey() || $id != $this->resource_link->getId(); if ($ok) { $this->resource_link->primary_consumer_key = $key; $this->resource_link->primary_resource_link_id = $id; $this->resource_link->share_approved = $share_key->auto_approve; $ok = $this->resource_link->save(); if ($ok) { $doSaveResourceLink = FALSE; $this->user->getResourceLink()->primary_consumer_key = $key; $this->user->getResourceLink()->primary_resource_link_id = $id; $this->user->getResourceLink()->share_approved = $share_key->auto_approve; $this->user->getResourceLink()->updated = time(); // Remove share key $share_key->delete(); } else { $this->reason = 'An error occurred initialising your share arrangement.'; } } else { $this->reason = 'It is not possible to share your resource link with yourself.'; } } if ($ok) { $ok = !is_null($key); if (!$ok) { $this->reason = 'You have requested to share a resource link but none is available.'; } else { $ok = !is_null($this->user->getResourceLink()->share_approved) && $this->user->getResourceLink()->share_approved; if (!$ok) { $this->reason = 'Your share request is waiting to be approved.'; } } } } } else { // Check no share is in place $ok = is_null($key); if (!$ok) { $this->reason = 'You have not requested to share a resource link but an arrangement is currently in place.'; } } // Look up primary resource link if ($ok && !is_null($key)) { $consumer = new LTI_Tool_Consumer($key, $this->data_connector); $ok = !is_null($consumer->created); if ($ok) { $resource_link = new LTI_Resource_Link($consumer, $id); $ok = !is_null($resource_link->created); } if ($ok) { if ($doSaveResourceLink) { $this->resource_link->save(); } $this->resource_link = $resource_link; } else { $this->reason = 'Unable to load resource link being shared.'; } } return $ok; }
/** * Class constructor. * * @param LTI_Resource_Link $resource_link Resource_Link object * @param string $id Value of share key (optional, default is null) */ public function __construct($resource_link, $id = NULL) { parent::__construct($resource_link, $id); $this->primary_context_id =& $this->primary_resource_link_id; }