Skip to content
This repository was archived by the owner on Jun 27, 2018. It is now read-only.

Set context setting 'context_type' if parameter was submitted through POST #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/ToolProvider/Context.php
Original file line number Diff line number Diff line change
@@ -35,6 +35,12 @@ class Context
* @var array $settings
*/
public $settings = null;
/**
* Context type.
*
* @var string $type
*/
public $type = null;
/**
* Date/time when the object was created.
*
16 changes: 10 additions & 6 deletions src/ToolProvider/DataConnector/DataConnector_mysql.php
Original file line number Diff line number Diff line change
@@ -390,12 +390,12 @@ public function loadContext($context)

$ok = false;
if (!empty($context->getRecordId())) {
$sql = sprintf('SELECT context_pk, consumer_pk, lti_context_id, settings, created, updated ' .
$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, settings, created, updated ' .
$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));
@@ -407,6 +407,7 @@ public function loadContext($context)
$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();
@@ -439,17 +440,20 @@ public function saveContext($context)
$consumer_pk = $context->getConsumer()->getRecordId();
if (empty($id)) {
$sql = sprintf("INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' (consumer_pk, lti_context_id, ' .
'settings, created, updated) ' .
'VALUES (%d, %s, %s, %s, %s)',
'type, settings, created, updated) ' .
'VALUES (%d, %s, %s, %s, %s, %s)',
$consumer_pk, DataConnector::quoted($context->ltiContextId),
DataConnector::quoted($context->type),
DataConnector::quoted($settingsValue),
DataConnector::quoted($now), DataConnector::quoted($now));
} else {
$sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' SET ' .
'lti_context_id = %s, settings = %s, '.
'lti_context_id = %s, type = %s, settings = %s, '.
'updated = %s' .
'WHERE (consumer_pk = %d) AND (context_pk = %d)',
DataConnector::quoted($context->ltiContextId), DataConnector::quoted($settingsValue),
DataConnector::quoted($context->ltiContextId),
DataConnector::quoted($context->type),
DataConnector::quoted($settingsValue),
DataConnector::quoted($now), $consumer_pk, $id);
}
$ok = mysql_query($sql);
13 changes: 8 additions & 5 deletions src/ToolProvider/DataConnector/DataConnector_pdo.php
Original file line number Diff line number Diff line change
@@ -452,13 +452,13 @@ public function loadContext($context)

$ok = false;
if (!empty($context->getRecordId())) {
$sql = 'SELECT context_pk, consumer_pk, lti_context_id, settings, created, updated ' .
$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, settings, created, updated ' .
$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);
@@ -475,6 +475,7 @@ public function loadContext($context)
$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();
@@ -505,21 +506,23 @@ public function saveContext($context)
$consumer_pk = $context->getConsumer()->getRecordId();
if (empty($id)) {
$sql = "INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' (consumer_pk, lti_context_id, ' .
'settings, created, updated) ' .
'VALUES (:cid, :ctx, :settings, :created, :updated)';
'type, settings, created, updated) ' .
'VALUES (:cid, :ctx, :type, :settings, :created, :updated)';
$query = $this->db->prepare($sql);
$query->bindValue('cid', $consumer_pk, PDO::PARAM_INT);
$query->bindValue('ctx', $context->ltiContextId, PDO::PARAM_STR);
$query->bindValue('type', $context->type, PDO::PARAM_STR);
$query->bindValue('settings', $settingsValue, PDO::PARAM_STR);
$query->bindValue('created', $now, PDO::PARAM_STR);
$query->bindValue('updated', $now, PDO::PARAM_STR);
} else {
$sql = "UPDATE {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' SET ' .
'lti_context_id = :ctx, settings = :settings, '.
'lti_context_id = :ctx, type = :type, settings = :settings, '.
'updated = :updated ' .
'WHERE (consumer_pk = :cid) AND (context_pk = :ctxid)';
$query = $this->db->prepare($sql);
$query->bindValue('ctx', $context->ltiContextId, PDO::PARAM_STR);
$query->bindValue('type', $context->type, PDO::PARAM_STR);
$query->bindValue('settings', $settingsValue, PDO::PARAM_STR);
$query->bindValue('updated', $now, PDO::PARAM_STR);
$query->bindValue('cid', $consumer_pk, PDO::PARAM_INT);
3 changes: 3 additions & 0 deletions src/ToolProvider/ToolProvider.php
Original file line number Diff line number Diff line change
@@ -983,6 +983,9 @@ private function authenticate()
if (empty($title)) {
$title = "Course {$this->context->getId()}";
}
if (isset($_POST['context_type'])) {
$this->context->type = trim($_POST['context_type']);
}
$this->context->title = $title;
}