Skip to content

Commit

Permalink
Merge branch 'MDL-55825-master' of git://github.com/junpataleta/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Nov 2, 2016
2 parents 4d27d62 + 5a3f6ce commit cb2b9a9
Show file tree
Hide file tree
Showing 14 changed files with 1,058 additions and 188 deletions.
76 changes: 76 additions & 0 deletions enrol/lti/classes/data_connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ public function loadContext($context) {
$context->setRecordId($row->id);
$context->setConsumerId($row->consumerid);
$context->ltiContextId = $row->lticontextkey;
$context->type = $row->type;
$settings = unserialize($row->settings);
if (!is_array($settings)) {
$settings = array();
Expand Down Expand Up @@ -376,6 +377,7 @@ public function saveContext($context) {
$params = [
'consumerid' => $consumerpk,
'lticontextkey' => $context->ltiContextId,
'type' => $context->type,
'settings' => $settingsvalue,
'created' => $context->created,
'updated' => $context->updated,
Expand All @@ -390,6 +392,7 @@ public function saveContext($context) {
'id' => $id,
'contextid' => $consumerpk,
'lticontextkey' => $context->ltiContextId,
'type' => $context->type,
'settings' => $settingsvalue,
'updated' => $context->updated,
];
Expand Down Expand Up @@ -905,6 +908,79 @@ public function deleteUser($user) {
return true;
}

/**
* Fetches the list of Context objects that are linked to a ToolConsumer.
*
* @param ToolConsumer $consumer
* @return Context[]
*/
public function get_contexts_from_consumer(ToolConsumer $consumer) {
global $DB;

$contexts = [];
$contextrecords = $DB->get_records($this->contexttable, ['consumerid' => $consumer->getRecordId()], '', 'lticontextkey');
foreach ($contextrecords as $record) {
$context = Context::fromConsumer($consumer, $record->lticontextkey);
$contexts[] = $context;
}

return $contexts;
}

/**
* Fetches a resource link record that is associated with a ToolConsumer.
*
* @param ToolConsumer $consumer
* @return ResourceLink
*/
public function get_resourcelink_from_consumer(ToolConsumer $consumer) {
global $DB;

$resourcelink = null;
if ($resourcelinkrecord = $DB->get_record($this->resourcelinktable, ['consumerid' => $consumer->getRecordId()],
'ltiresourcelinkkey')) {
$resourcelink = ResourceLink::fromConsumer($consumer, $resourcelinkrecord->ltiresourcelinkkey);
}

return $resourcelink;
}

/**
* Fetches a resource link record that is associated with a Context object.
*
* @param Context $context
* @return ResourceLink
*/
public function get_resourcelink_from_context(Context $context) {
global $DB;

$resourcelink = null;
if ($resourcelinkrecord = $DB->get_record($this->resourcelinktable, ['contextid' => $context->getRecordId()],
'ltiresourcelinkkey')) {
$resourcelink = ResourceLink::fromContext($context, $resourcelinkrecord->ltiresourcelinkkey);
}

return $resourcelink;
}


/**
* Fetches the list of ToolConsumer objects that are linked to a tool.
*
* @param int $toolid
* @return ToolConsumer[]
*/
public function get_consumers_mapped_to_tool($toolid) {
global $DB;

$consumers = [];
$consumerrecords = $DB->get_records('enrol_lti_tool_consumer_map', ['toolid' => $toolid], '', 'consumerid');
foreach ($consumerrecords as $record) {
$consumers[] = ToolConsumer::fromRecordId($record->consumerid, $this);
}
return $consumers;
}

/**
* Builds a ToolConsumer object from a record object from the DB.
*
Expand Down
Loading

0 comments on commit cb2b9a9

Please sign in to comment.