Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
Update references to deprecated classes
Sign content-item return mesage using tool object
Fix settiing of LTI version in session
  • Loading branch information
spvickers committed Sep 26, 2020
1 parent 807b509 commit 79b1a29
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "celtic/rating",
"version": "4.0.1",
"version": "4.0.2",
"type": "project",
"license": "GPL-3.0-or-later",
"authors": [
Expand All @@ -13,6 +13,6 @@
"docs": "http://www.spvsoftwareproducts.com/php/rating/"
},
"require": {
"celtic/lti": "^4.0.2"
"celtic/lti": "^4.1.0"
}
}
55 changes: 29 additions & 26 deletions src/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use ceLTIc\LTI;
use ceLTIc\LTI\DataConnector;
use ceLTIc\LTI\ResourceLink;
use ceLTIc\LTI\Content;

/**
* This page displays a list of items for a resource link. Students are able to rate
Expand Down Expand Up @@ -48,7 +49,7 @@
$dataConnector = DataConnector\DataConnector::getDataConnector($db, DB_TABLENAME_PREFIX);
$platform = LTI\Platform::fromRecordId($_SESSION['consumer_pk'], $dataConnector);
if (is_null($_SESSION['resource_pk'])) {
$resourceLink = LTI\ResourceLink::fromConsumer($platform, $_SESSION['resource_id']);
$resourceLink = LTI\ResourceLink::fromPlatform($platform, $_SESSION['resource_id']);
$ok = $resourceLink->save();
} else {
$resourceLink = LTI\ResourceLink::fromRecordId($_SESSION['resource_pk'], $dataConnector);
Expand Down Expand Up @@ -111,22 +112,22 @@
$documentTarget = 'frame';
}
if (!empty($documentTarget)) {
$placement = new LTI\ContentItemPlacement(null, null, $documentTarget, null);
$placement = new Content\Placement($documentTarget);
}
$item = new LTI\ContentItem('LtiLink', $placement);
$item->setMediaType(LTI\ContentItem::LTI_LINK_MEDIA_TYPE);
$item = new Content\LtiLinkItem($placement);
$item->setMediaType(Content\Item::LTI_LINK_MEDIA_TYPE);
$item->setTitle($_SESSION['title']);
$item->setText($_SESSION['text']);
$item->icon = new LTI\ContentItemImage(getAppUrl() . 'images/icon50.png', 50, 50);
$item->custom = array('content_item_id' => $_SESSION['resource_id']);
$formParams['content_items'] = LTI\ContentItem::toJson($item);
$item->setIcon(new Content\Image(getAppUrl() . 'images/icon50.png', 50, 50));
$item->addCustom('content_item_id', $_SESSION['resource_id']);
$formParams['content_items'] = Content\Item::toJson($item);
if (!is_null($_SESSION['data'])) {
$formParams['data'] = $_SESSION['data'];
}
$dataConnector = DataConnector\DataConnector::getDataConnector($db, DB_TABLENAME_PREFIX);
$platform = LTI\Platform::fromRecordId($_SESSION['consumer_pk'], $dataConnector);
$formParams = $platform->signParameters($_SESSION['return_url'], 'ContentItemSelection', $_SESSION['lti_version'],
$formParams);
LTI\Tool::$defaultTool->platform = LTI\Platform::fromRecordId($_SESSION['consumer_pk'], $dataConnector);
$formParams = LTI\Tool::$defaultTool->signParameters($_SESSION['return_url'], 'ContentItemSelection',
$_SESSION['lti_version'], $formParams);
$page = LTI\Util::sendForm($_SESSION['return_url'], $formParams);
echo $page;
exit;
Expand All @@ -141,9 +142,9 @@
$formParams['data'] = $_SESSION['data'];
}
$dataConnector = DataConnector\DataConnector::getDataConnector($db, DB_TABLENAME_PREFIX);
$platform = LTI\Platrform::fromRecordId($_SESSION['consumer_pk'], $dataConnector);
$formParams = $platform->signParameters($_SESSION['return_url'], 'ContentItemSelection', $_SESSION['lti_version'],
$formParams);
LTI\Tool::$defaultTool->platform = LTI\Platform::fromRecordId($_SESSION['consumer_pk'], $dataConnector);
$formParams = LTI\Tool::$defaultTool->signParameters($_SESSION['return_url'], 'ContentItemSelection',
$_SESSION['lti_version'], $formParams);
$page = LTI\Util::sendForm($_SESSION['return_url'], $formParams);
echo $page;
exit;
Expand Down Expand Up @@ -546,19 +547,20 @@ function doOnLoad() {
EOD;
$users = array();
foreach ($members as $member) {
$users["{$member->lastname}, {$member->firstname}"] = $member;
}
ksort($users);
foreach ($users as $name => $user) {
if ($user->isLearner()) {
$img = 'tick.gif';
$ratings = count(getUserRated($db, $_SESSION['resource_pk'], $user->getRecordId()));
} else {
$img = 'cross.gif';
$ratings = 'NA';
if (!empty($members)) {
foreach ($members as $member) {
$users["{$member->lastname}, {$member->firstname}"] = $member;
}
$page .= <<< EOD
ksort($users);
foreach ($users as $name => $user) {
if ($user->isLearner()) {
$img = 'tick.gif';
$ratings = count(getUserRated($db, $_SESSION['resource_pk'], $user->getRecordId()));
} else {
$img = 'cross.gif';
$ratings = 'NA';
}
$page .= <<< EOD
<tr>
<td>{$user->ltiUserId}</td>
<td>{$name}</td>
Expand All @@ -567,6 +569,7 @@ function doOnLoad() {
</tr>
EOD;
}
}
$page .= <<< EOD
</tbody>
Expand Down Expand Up @@ -632,7 +635,7 @@ function doOnLoad() {
EOD;
}
} else {
} else if (!$_SESSION['isContentItem']) {
$page .= <<< EOD
Your course does not appear to offer the ability to access a list of users.
Expand Down
6 changes: 3 additions & 3 deletions src/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,11 @@ function updateGradebook($db, $userResourcePk = null, $userUserPk = null, $item
}
$ltiOutcome = new LTI\Outcome($count, $num);
if ($count === 1) {
$item = 'item';
$itemDesc = 'item';
} else {
$item = 'items';
$itemDesc = 'items';
}
$ltiOutcome->comment = "{$count} {$item} rated out of {$num}.";
$ltiOutcome->comment = "{$count} {$itemDesc} rated out of {$num}.";
$resourceLink->doOutcomesService(LTI\ResourceLink::EXT_WRITE, $ltiOutcome, $user);
} else {
$ltiOutcome = new LTI\Outcome();
Expand Down
2 changes: 1 addition & 1 deletion src/rating_tp.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function onContentItem()
$_SESSION['user_pk'] = null;
$_SESSION['isStudent'] = false;
$_SESSION['isContentItem'] = true;
$_SESSION['lti_version'] = $_POST['lti_version'];
$_SESSION['lti_version'] = $this->platform->ltiVersion;
$_SESSION['return_url'] = $this->returnUrl;
$_SESSION['title'] = postValue('title', 'Rating item');
$_SESSION['text'] = postValue('text');
Expand Down

0 comments on commit 79b1a29

Please sign in to comment.