Exemplo n.º 1
0
 /**
  * Save resource link object.
  *
  * @param ResourceLink $resourceLink Resource_Link object
  *
  * @return boolean True if the resource link object was successfully saved
  */
 public function saveResourceLink($resourceLink)
 {
     if (is_null($resourceLink->shareApproved)) {
         $approved = 'NULL';
     } else {
         if ($resourceLink->shareApproved) {
             $approved = '1';
         } else {
             $approved = '0';
         }
     }
     if (empty($resourceLink->primaryResourceLinkId)) {
         $primaryResourceLinkId = 'NULL';
     } else {
         $primaryResourceLinkId = strval($resourceLink->primaryResourceLinkId);
     }
     $time = time();
     $now = date("{$this->dateFormat} {$this->timeFormat}", $time);
     $settingsValue = serialize($resourceLink->getSettings());
     if (!empty($resourceLink->getContext())) {
         $consumerId = 'NULL';
         $contextId = strval($resourceLink->getContext()->getRecordId());
     } else {
         if (!empty($resourceLink->getContextId())) {
             $consumerId = 'NULL';
             $contextId = strval($resourceLink->getContextId());
         } else {
             $consumerId = strval($resourceLink->getConsumer()->getRecordId());
             $contextId = 'NULL';
         }
     }
     $id = $resourceLink->getRecordId();
     if (empty($id)) {
         $sql = sprintf("INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' (consumer_pk, context_pk, ' . 'lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated) ' . 'VALUES (%s, %s, %s, %s, %s, %s, %s, %s)', $consumerId, $contextId, DataConnector::quoted($resourceLink->getId()), DataConnector::quoted($settingsValue), $primaryResourceLinkId, $approved, DataConnector::quoted($now), DataConnector::quoted($now));
     } else {
         if ($contextId !== 'NULL') {
             $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' SET ' . 'consumer_pk = %s, lti_resource_link_id = %s, settings = %s, ' . 'primary_resource_link_pk = %s, share_approved = %s, updated = %s ' . 'WHERE (context_pk = %s) AND (resource_link_pk = %d)', $consumerId, DataConnector::quoted($resourceLink->getId()), DataConnector::quoted($settingsValue), $primaryResourceLinkId, $approved, DataConnector::quoted($now), $contextId, $id);
         } else {
             $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' SET ' . 'context_pk = %s, lti_resource_link_id = %s, settings = %s, ' . 'primary_resource_link_pk = %s, share_approved = %s, updated = %s ' . 'WHERE (consumer_pk = %s) AND (resource_link_pk = %d)', $contextId, DataConnector::quoted($resourceLink->getId()), DataConnector::quoted($settingsValue), $primaryResourceLinkId, $approved, DataConnector::quoted($now), $consumerId, $id);
         }
     }
     $ok = mysql_query($sql);
     if ($ok) {
         if (empty($id)) {
             $resourceLink->setRecordId(mysql_insert_id());
             $resourceLink->created = $time;
         }
         $resourceLink->updated = $time;
     }
     return $ok;
 }
Exemplo n.º 2
0
 /**
  * Save resource link object.
  *
  * @param ResourceLink $resourcelink Resource_Link object
  * @return boolean True if the resource link object was successfully saved
  */
 public function saveResourceLink($resourcelink)
 {
     global $DB;
     if (is_null($resourcelink->shareApproved)) {
         $approved = null;
     } else {
         if ($resourcelink->shareApproved) {
             $approved = 1;
         } else {
             $approved = 0;
         }
     }
     if (empty($resourcelink->primaryResourceLinkId)) {
         $primaryresourcelinkid = null;
     } else {
         $primaryresourcelinkid = $resourcelink->primaryResourceLinkId;
     }
     $now = time();
     $resourcelink->updated = $now;
     $settingsvalue = serialize($resourcelink->getSettings());
     if (!empty($resourcelink->getContext())) {
         $consumerid = null;
         $contextid = $resourcelink->getContext()->getRecordId();
     } else {
         if (!empty($resourcelink->getContextId())) {
             $consumerid = null;
             $contextid = $resourcelink->getContextId();
         } else {
             $consumerid = $resourcelink->getConsumer()->getRecordId();
             $contextid = null;
         }
     }
     $id = $resourcelink->getRecordId();
     $data = ['consumerid' => $consumerid, 'contextid' => $contextid, 'ltiresourcelinkkey' => $resourcelink->getId(), 'settings' => $settingsvalue, 'primaryresourcelinkid' => $primaryresourcelinkid, 'shareapproved' => $approved, 'updated' => $resourcelink->updated];
     $returnid = null;
     if (empty($id)) {
         $resourcelink->created = $now;
         $data['created'] = $resourcelink->created;
         $id = $DB->insert_record($this->resourcelinktable, (object) $data);
         if ($id) {
             $resourcelink->setRecordId($id);
             return true;
         }
     } else {
         $data['id'] = $id;
         return $DB->update_record($this->resourcelinktable, (object) $data);
     }
     return false;
 }
Exemplo n.º 3
0
 /**
  * Check if a share arrangement is in place.
  *
  * @return boolean True if no error is reported
  */
 private function checkForShare()
 {
     $ok = true;
     $doSaveResourceLink = true;
     $id = $this->resourceLink->primaryResourceLinkId;
     $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
             $shareKey = new ResourceLinkShareKey($this->resourceLink, $_POST['custom_share_key']);
             if (!is_null($shareKey->primaryConsumerKey) && !is_null($shareKey->primaryResourceLinkId)) {
                 // Update resource link with sharing primary resource link details
                 $key = $shareKey->primaryConsumerKey;
                 $id = $shareKey->primaryResourceLinkId;
                 $ok = $key !== $this->consumer->getKey() || $id != $this->resourceLink->getId();
                 if ($ok) {
                     $this->resourceLink->primaryConsumerKey = $key;
                     $this->resourceLink->primaryResourceLinkId = $id;
                     $this->resourceLink->shareApproved = $shareKey->autoApprove;
                     $ok = $this->resourceLink->save();
                     if ($ok) {
                         $doSaveResourceLink = false;
                         $this->user->getResourceLink()->primaryConsumerKey = $key;
                         $this->user->getResourceLink()->primaryResourceLinkId = $id;
                         $this->user->getResourceLink()->shareApproved = $shareKey->autoApprove;
                         $this->user->getResourceLink()->updated = time();
                         // Remove share key
                         $shareKey->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()->shareApproved) && $this->user->getResourceLink()->shareApproved;
                     if (!$ok) {
                         $this->reason = 'Your share request is waiting to be approved.';
                     }
                 }
             }
         }
     } else {
         // Check no share is in place
         $ok = is_null($id);
         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($id)) {
         $consumer = new ToolConsumer($key, $this->dataConnector);
         $ok = !is_null($consumer->created);
         if ($ok) {
             $resourceLink = ResourceLink::fromConsumer($consumer, $id);
             $ok = !is_null($resourceLink->created);
         }
         if ($ok) {
             if ($doSaveResourceLink) {
                 $this->resourceLink->save();
             }
             $this->resourceLink = $resourceLink;
         } else {
             $this->reason = 'Unable to load resource link being shared.';
         }
     }
     return $ok;
 }
Exemplo n.º 4
0
 /**
  * Save resource link object.
  *
  * @param ResourceLink $resourceLink Resource_Link object
  *
  * @return boolean True if the resource link object was successfully saved
  */
 public function saveResourceLink($resourceLink)
 {
     $time = time();
     $now = date("{$this->dateFormat} {$this->timeFormat}", $time);
     $settingsValue = serialize($resourceLink->getSettings());
     if (!empty($resourceLink->getContext())) {
         $consumerId = null;
         $contextId = strval($resourceLink->getContext()->getRecordId());
     } else {
         if (!empty($resourceLink->getContextId())) {
             $consumerId = null;
             $contextId = strval($resourceLink->getContextId());
         } else {
             $consumerId = strval($resourceLink->getConsumer()->getRecordId());
             $contextId = null;
         }
     }
     if (empty($resourceLink->primaryResourceLinkId)) {
         $primaryResourceLinkId = null;
     } else {
         $primaryResourceLinkId = $resourceLink->primaryResourceLinkId;
     }
     $id = $resourceLink->getRecordId();
     if (empty($id)) {
         $sql = "INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' (consumer_pk, context_pk, ' . 'lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated) ' . 'VALUES (:cid, :ctx, :rlid, :settings, :prlid, :share_approved, :created, :updated)';
         $query = $this->db->prepare($sql);
         $query->bindValue('cid', $consumerId, PDO::PARAM_INT);
         $query->bindValue('ctx', $contextId, PDO::PARAM_INT);
         $query->bindValue('rlid', $resourceLink->getId(), PDO::PARAM_STR);
         $query->bindValue('settings', $settingsValue, PDO::PARAM_STR);
         $query->bindValue('prlid', $primaryResourceLinkId, PDO::PARAM_INT);
         $query->bindValue('share_approved', $resourceLink->shareApproved, PDO::PARAM_INT);
         $query->bindValue('created', $now, PDO::PARAM_STR);
         $query->bindValue('updated', $now, PDO::PARAM_STR);
     } else {
         if (!is_null($contextId)) {
             $sql = "UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' SET ' . 'consumer_pk = NULL, context_pk = :ctx, lti_resource_link_id = :rlid, settings = :settings, ' . 'primary_resource_link_pk = :prlid, share_approved = :share_approved, updated = :updated ' . 'WHERE (resource_link_pk = :id)';
             $query = $this->db->prepare($sql);
             $query->bindValue('ctx', $contextId, PDO::PARAM_INT);
             $query->bindValue('rlid', $resourceLink->getId(), PDO::PARAM_STR);
             $query->bindValue('settings', $settingsValue, PDO::PARAM_STR);
             $query->bindValue('prlid', $primaryResourceLinkId, PDO::PARAM_INT);
             $query->bindValue('share_approved', $resourceLink->shareApproved, PDO::PARAM_INT);
             $query->bindValue('updated', $now, PDO::PARAM_STR);
             $query->bindValue('id', $id, PDO::PARAM_INT);
         } else {
             $sql = "UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' SET ' . 'context_pk = :ctx, lti_resource_link_id = :rlid, settings = :settings, ' . 'primary_resource_link_pk = :prlid, share_approved = :share_approved, updated = :updated ' . 'WHERE (consumer_pk = :cid) AND (resource_link_pk = :id)';
             $query = $this->db->prepare($sql);
             $query->bindValue('ctx', $contextId, PDO::PARAM_INT);
             $query->bindValue('rlid', $resourceLink->getId(), PDO::PARAM_STR);
             $query->bindValue('settings', $settingsValue, PDO::PARAM_STR);
             $query->bindValue('prlid', $primaryResourceLinkId, PDO::PARAM_INT);
             $query->bindValue('share_approved', $resourceLink->shareApproved, PDO::PARAM_INT);
             $query->bindValue('updated', $now, PDO::PARAM_STR);
             $query->bindValue('cid', $consumerId, PDO::PARAM_INT);
             $query->bindValue('id', $id, PDO::PARAM_INT);
         }
     }
     $ok = $query->execute();
     if ($ok) {
         if (empty($id)) {
             $resourceLink->setRecordId(intval($this->db->lastInsertId()));
             $resourceLink->created = $time;
         }
         $resourceLink->updated = $time;
     }
     return $ok;
 }