Example #1
0
 /**
  * Load context object.
  *
  * @param Context $context Context object
  * @return boolean True if the context object was successfully loaded
  */
 public function loadContext($context)
 {
     global $DB;
     if (!empty($context->getRecordId())) {
         $params = ['id' => $context->getRecordId()];
     } else {
         $params = ['consumerid' => $context->getConsumer()->getRecordId(), 'lticontextkey' => $context->ltiContextId];
     }
     if ($row = $DB->get_record($this->contexttable, $params)) {
         $context->setRecordId($row->id);
         $context->setConsumerId($row->consumerid);
         $context->ltiContextId = $row->lticontextkey;
         $settings = unserialize($row->settings);
         if (!is_array($settings)) {
             $settings = array();
         }
         $context->setSettings($settings);
         $context->created = $row->created;
         $context->updated = $row->updated;
         return true;
     }
     return false;
 }
 /**
  * Load context object.
  *
  * @param Context $context Context object
  *
  * @return boolean True if the context object was successfully loaded
  */
 public function loadContext($context)
 {
     $ok = false;
     if (!empty($context->getRecordId())) {
         $sql = sprintf('SELECT context_pk, consumer_pk, lti_context_id, type, settings, created, updated ' . "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' ' . 'WHERE (context_pk = %d)', $context->getRecordId());
     } else {
         $sql = sprintf('SELECT context_pk, consumer_pk, lti_context_id, type, settings, created, updated ' . "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' ' . 'WHERE (consumer_pk = %d) AND (lti_context_id = %s)', $context->getConsumer()->getRecordId(), DataConnector::quoted($context->ltiContextId));
     }
     $rs_context = mysql_query($sql);
     if ($rs_context) {
         $row = mysql_fetch_object($rs_context);
         if ($row) {
             $context->setRecordId(intval($row->context_pk));
             $context->setConsumerId(intval($row->consumer_pk));
             $context->ltiContextId = $row->lti_context_id;
             $context->type = $row->type;
             $settings = unserialize($row->settings);
             if (!is_array($settings)) {
                 $settings = array();
             }
             $context->setSettings($settings);
             $context->created = strtotime($row->created);
             $context->updated = strtotime($row->updated);
             $ok = true;
         }
     }
     return $ok;
 }
Example #3
0
 /**
  * Load context object.
  *
  * @param Context $context Context object
  *
  * @return boolean True if the context object was successfully loaded
  */
 public function loadContext($context)
 {
     $ok = false;
     if (!empty($context->getRecordId())) {
         $sql = 'SELECT context_pk, consumer_pk, lti_context_id, type, settings, created, updated ' . "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' ' . 'WHERE (context_pk = :id)';
         $query = $this->db->prepare($sql);
         $query->bindValue('id', $context->getRecordId(), PDO::PARAM_INT);
     } else {
         $sql = 'SELECT context_pk, consumer_pk, lti_context_id, type, settings, created, updated ' . "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' ' . 'WHERE (consumer_pk = :cid) AND (lti_context_id = :ctx)';
         $query = $this->db->prepare($sql);
         $query->bindValue('cid', $context->getConsumer()->getRecordId(), PDO::PARAM_INT);
         $query->bindValue('ctx', $context->ltiContextId, 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);
         $context->setRecordId(intval($row['context_pk']));
         $context->setConsumerId(intval($row['consumer_pk']));
         $context->ltiContextId = $row['lti_context_id'];
         $context->type = $row['type'];
         $settings = unserialize($row['settings']);
         if (!is_array($settings)) {
             $settings = array();
         }
         $context->setSettings($settings);
         $context->created = strtotime($row['created']);
         $context->updated = strtotime($row['updated']);
     }
     return $ok;
 }