Esempio 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)
 {
     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;
 }
Esempio 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)
 {
     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;
 }
Esempio n. 3
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;
 }