Link and Content service - celtic-project/LTI-PHP GitHub Wiki
The Link and Content service allows a tool to manage the links and content-items which have been created for it with a platform.
The Link and Content service class offers the following methods:
- for context-level endpoints:
getAll- gets all the links and content-items for the tool in the context, and allows the following optional parameter:$ltiResourceLinkId- limit the information to ones which are associated with the specified resource link$limit- used to limit the number of group sets or groups are requested to be included in each response
createContentItem- create a new link or content-item in the context
- for item-level endpoints:
get- get the itemsaveContentItem- update the itemdeleteContentItem- delete the item
Examples
Obtain all the items for a context
$limit = null; // An optional limit on each response can be set
$items = $context->getContentItems($limit);
The default limit for the size of response pages from the platform can be overridden by changing the value of the Service\LinkContent::$defaultLimit property. The limit only affects the number of requests made to the platform; all of
the items will always be returned.
Obtain the item for a resource link
$contentItem = $resourceLink->getContentItem();
The value of $item will be false if the request was not successful.
Obtain the item from its endpoint (id)
use ceLTIc\LTI\ContentItem\ContentItem;
$contentItem = ContentItem::fromEndpoint($platform, $endpoint);
The value of $item will be false if the request was not successful.
Create a new item in a context
use ceLTIc\LTI\Content\Item;
use ceLTIc\LTI\ContentItem\ContentItem;
$contentItem = ContentItem::fromType(Item::TYPE_LTI_LINK); // Sample content-item to be created
$item = $contentItem->getItem();
$item->setTitle('A new LTI link');
$item->setText('This link was created automatically by the tool.');
$item->setUrl('');
$item->addCustom('username', '$User.username');
$ok = $context->createContentItem($contentItem);
Update an item
$ok = $contentItem->save($platform);
Delete an item
For the content-item represented by a resource link object:
$ok = $resourceLink->deleteContentItem();
For a content-item known by its id (endpoint):
$ok = $contentItem->delete($platform);