Esempio n. 1
0
 /**
  * Load resource link object.
  *
  * @param ResourceLink $resourcelink ResourceLink object
  * @return boolean True if the resource link object was successfully loaded
  */
 public function loadResourceLink($resourcelink)
 {
     global $DB;
     $resourceid = $resourcelink->getRecordId();
     if (!empty($resourceid)) {
         $params = ['id' => $resourceid];
         $row = $DB->get_record($this->resourcelinktable, $params);
     } else {
         if (!empty($resourcelink->getContext())) {
             $params = ['contextid' => $resourcelink->getContext()->getRecordId(), 'ltiresourcelinkkey' => $resourcelink->getId()];
             $row = $DB->get_record($this->resourcelinktable, $params);
         } else {
             $sql = "SELECT r.*\n                      FROM {{$this->resourcelinktable}} r\n           LEFT OUTER JOIN {{$this->contexttable}} c\n                        ON r.contextid = c.id\n                     WHERE (r.consumerid = ? OR c.consumerid = ?)\n                           AND ltiresourcelinkkey = ?";
             $params = [$resourcelink->getConsumer()->getRecordId(), $resourcelink->getConsumer()->getRecordId(), $resourcelink->getId()];
             $row = $DB->get_record_sql($sql, $params);
         }
     }
     if ($row) {
         $resourcelink->setRecordId($row->id);
         if (!is_null($row->contextid)) {
             $resourcelink->setContextId($row->contextid);
         } else {
             $resourcelink->setContextId(null);
         }
         if (!is_null($row->consumerid)) {
             $resourcelink->setConsumerId($row->consumerid);
         } else {
             $resourcelink->setConsumerId(null);
         }
         $resourcelink->ltiResourceLinkId = $row->ltiresourcelinkkey;
         $settings = unserialize($row->settings);
         if (!is_array($settings)) {
             $settings = array();
         }
         $resourcelink->setSettings($settings);
         if (!is_null($row->primaryresourcelinkid)) {
             $resourcelink->primaryResourceLinkId = $row->primaryresourcelinkid;
         } else {
             $resourcelink->primaryResourceLinkId = null;
         }
         $resourcelink->shareApproved = is_null($row->shareapproved) ? null : $row->shareapproved == 1;
         $resourcelink->created = $row->created;
         $resourcelink->updated = $row->updated;
         return true;
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Load resource link object.
  *
  * @param ResourceLink $resourceLink Resource_Link object
  *
  * @return boolean True if the resource link object was successfully loaded
  */
 public function loadResourceLink($resourceLink)
 {
     $ok = false;
     if (!empty($resourceLink->getRecordId())) {
         $sql = sprintf('SELECT resource_link_pk, context_pk, consumer_pk, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated ' . "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . 'WHERE (resource_link_pk = %d)', $resourceLink->getRecordId());
     } else {
         if (!empty($resourceLink->getContext())) {
             $sql = sprintf('SELECT resource_link_pk, context_pk, consumer_pk, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated ' . "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . 'WHERE (context_pk = %d) AND (lti_resource_link_id = %s)', $resourceLink->getContext()->getRecordId(), DataConnector::quoted($resourceLink->getId()));
         } else {
             $sql = sprintf('SELECT r.resource_link_pk, r.context_pk, r.consumer_pk, r.lti_resource_link_id, r.settings, r.primary_resource_link_pk, r.share_approved, r.created, r.updated ' . "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' r LEFT OUTER JOIN ' . $this->dbTableNamePrefix . DataConnector::CONTEXT_TABLE_NAME . ' c ON r.context_pk = c.context_pk ' . ' WHERE ((r.consumer_pk = %d) OR (c.consumer_pk = %d)) AND (lti_resource_link_id = %s)', $resourceLink->getConsumer()->getRecordId(), $resourceLink->getConsumer()->getRecordId(), DataConnector::quoted($resourceLink->getId()));
         }
     }
     $rsContext = mysql_query($sql);
     if ($rsContext) {
         $row = mysql_fetch_object($rsContext);
         if ($row) {
             $resourceLink->setRecordId(intval($row->resource_link_pk));
             if (!is_null($row->context_pk)) {
                 $resourceLink->setContextId(intval($row->context_pk));
             } else {
                 $resourceLink->setContextId(null);
             }
             if (!is_null($row->consumer_pk)) {
                 $resourceLink->setConsumerId(intval($row->consumer_pk));
             } else {
                 $resourceLink->setConsumerId(null);
             }
             $resourceLink->ltiResourceLinkId = $row->lti_resource_link_id;
             $settings = unserialize($row->settings);
             if (!is_array($settings)) {
                 $settings = array();
             }
             $resourceLink->setSettings($settings);
             if (!is_null($row->primary_resource_link_pk)) {
                 $resourceLink->primaryResourceLinkId = intval($row->primary_resource_link_pk);
             } else {
                 $resourceLink->primaryResourceLinkId = null;
             }
             $resourceLink->shareApproved = is_null($row->share_approved) ? null : intval($row->share_approved) === 1;
             $resourceLink->created = strtotime($row->created);
             $resourceLink->updated = strtotime($row->updated);
             $ok = true;
         }
     }
     return $ok;
 }
Esempio n. 3
0
 /**
  * Load resource link object.
  *
  * @param ResourceLink $resourceLink Resource_Link object
  *
  * @return boolean True if the resource link object was successfully loaded
  */
 public function loadResourceLink($resourceLink)
 {
     if (!empty($resourceLink->getRecordId())) {
         $sql = 'SELECT resource_link_pk, context_pk, consumer_pk, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated ' . "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . 'WHERE (resource_link_pk = :id)';
         $query = $this->db->prepare($sql);
         $query->bindValue('id', $resourceLink->getRecordId(), PDO::PARAM_INT);
     } else {
         if (!empty($resourceLink->getContext())) {
             $sql = 'SELECT resource_link_pk, context_pk, consumer_pk, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated ' . "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . 'WHERE (context_pk = :id) AND (lti_resource_link_id = :rlid)';
             $query = $this->db->prepare($sql);
             $query->bindValue('id', $resourceLink->getContext()->getRecordId(), PDO::PARAM_INT);
             $query->bindValue('rlid', $resourceLink->getId(), PDO::PARAM_STR);
         } else {
             $sql = 'SELECT r.resource_link_pk, r.context_pk, r.consumer_pk, r.lti_resource_link_id, r.settings, r.primary_resource_link_pk, r.share_approved, r.created, r.updated ' . "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' r LEFT OUTER JOIN ' . $this->dbTableNamePrefix . DataConnector::CONTEXT_TABLE_NAME . ' c ON r.context_pk = c.context_pk ' . ' WHERE ((r.consumer_pk = :id1) OR (c.consumer_pk = :id2)) AND (lti_resource_link_id = :rlid)';
             $query = $this->db->prepare($sql);
             $query->bindValue('id1', $resourceLink->getConsumer()->getRecordId(), PDO::PARAM_INT);
             $query->bindValue('id2', $resourceLink->getConsumer()->getRecordId(), PDO::PARAM_INT);
             $query->bindValue('rlid', $resourceLink->getId(), PDO::PARAM_STR);
         }
     }
     $ok = $query->execute();
     if ($ok) {
         $row = $query->fetch(PDO::FETCH_ASSOC);
         $ok = $row !== FALSE;
     }
     if ($ok) {
         $row = array_change_key_case($row);
         $resourceLink->setRecordId(intval($row['resource_link_pk']));
         if (!is_null($row['context_pk'])) {
             $resourceLink->setContextId(intval($row['context_pk']));
         } else {
             $resourceLink->setContextId(null);
         }
         if (!is_null($row['consumer_pk'])) {
             $resourceLink->setConsumerId(intval($row['consumer_pk']));
         } else {
             $resourceLink->setConsumerId(null);
         }
         $resourceLink->ltiResourceLinkId = $row['lti_resource_link_id'];
         $settings = unserialize($row['settings']);
         if (!is_array($settings)) {
             $settings = array();
         }
         $resourceLink->setSettings($settings);
         if (!is_null($row['primary_resource_link_pk'])) {
             $resourceLink->primaryResourceLinkId = intval($row['primary_resource_link_pk']);
         } else {
             $resourceLink->primaryResourceLinkId = null;
         }
         $resourceLink->shareApproved = is_null($row['share_approved']) ? null : intval($row['share_approved']) === 1;
         $resourceLink->created = strtotime($row['created']);
         $resourceLink->updated = strtotime($row['updated']);
     }
     return $ok;
 }