mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 04:22:07 +02:00
MDL-55825 core_lib: LTI tool provider library fixes
* Define consumer profile member variable for ToolConsumer class * Added context type property for Context class * Set context type if 'context_type' parameter was submitted through POST This commit can be dropped once the pull requests for these changes have been integrated upstream.
This commit is contained in:
parent
577bd70d38
commit
a78d184c05
@ -1,8 +1,15 @@
|
||||
LTI Tool Provider Library PHP
|
||||
=============================
|
||||
|
||||
No changes from the upstream version have been made, it is recommended by upstream
|
||||
to install these depdencies via composer - but the composer installation is bundled
|
||||
Some changes from the upstream version have been made:
|
||||
* Define consumer profile member variable for ToolConsumer class
|
||||
* Added context type property for Context class
|
||||
* Set context type if 'context_type' parameter was submitted through POST
|
||||
These changes can be reverted once the following pull requests have been integrated upstream:
|
||||
* https://github.com/IMSGlobal/LTI-Tool-Provider-Library-PHP/pull/10/commits/a9a1641f1a593eba4638133245c21d9ad47d8680
|
||||
* https://github.com/IMSGlobal/LTI-Tool-Provider-Library-PHP/pull/11/commits/0bae60389bd020a02be5554516b86336e651e237
|
||||
|
||||
It is recommended by upstream to install depdencies via composer - but the composer installation is bundled
|
||||
with an autoloader so it's better to do it manually.
|
||||
|
||||
Information
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -390,12 +390,12 @@ class DataConnector_mysql extends DataConnector
|
||||
|
||||
$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 @@ class DataConnector_mysql extends DataConnector
|
||||
$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 @@ class DataConnector_mysql extends DataConnector
|
||||
$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);
|
||||
|
@ -452,13 +452,13 @@ class DataConnector_pdo extends DataConnector
|
||||
|
||||
$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 @@ class DataConnector_pdo extends DataConnector
|
||||
$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 @@ class DataConnector_pdo extends DataConnector
|
||||
$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);
|
||||
|
@ -6,6 +6,7 @@ use IMSGlobal\LTI\ToolProvider\DataConnector\DataConnector;
|
||||
use IMSGlobal\LTI\ToolProvider\Service;
|
||||
use IMSGlobal\LTI\HTTPMessage;
|
||||
use IMSGlobal\LTI\OAuth;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Class to represent a tool consumer
|
||||
@ -121,6 +122,12 @@ class ToolConsumer
|
||||
* @var int $updated
|
||||
*/
|
||||
public $updated = null;
|
||||
/**
|
||||
* The consumer profile data.
|
||||
*
|
||||
* @var stdClass
|
||||
*/
|
||||
public $profile = null;
|
||||
|
||||
/**
|
||||
* Consumer ID value.
|
||||
|
@ -983,6 +983,9 @@ EOD;
|
||||
if (empty($title)) {
|
||||
$title = "Course {$this->context->getId()}";
|
||||
}
|
||||
if (isset($_POST['context_type'])) {
|
||||
$this->context->type = trim($_POST['context_type']);
|
||||
}
|
||||
$this->context->title = $title;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user