Skip to content

Commit 141d96f

Browse files
committed
Update Link and Content service
1 parent 17fd38e commit 141d96f

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

src/ContentItem/ContentItem.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,29 @@ public function getItem(): Item
4444
return $this->item;
4545
}
4646

47+
/**
48+
* Save a content-item.
49+
*
50+
* @param Platform $platform Platform object
51+
*
52+
* @return bool True if successful
53+
*/
54+
public function save(Platform $platform): bool
55+
{
56+
$ok = false;
57+
if (!empty($this->item)) {
58+
$id = $this->item->getId();
59+
if (!empty($id)) {
60+
$linkContentService = new Service\LinkContent($platform, $id);
61+
if (!empty($linkContentService)) {
62+
$ok = $linkContentService->saveContentItem($this);
63+
}
64+
}
65+
}
66+
67+
return $ok;
68+
}
69+
4770
/**
4871
* Delete a content-item.
4972
*

src/ContentItem/LtiLinkContentItem.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ class LtiLinkContentItem extends ContentItem
3131
*/
3232
public ?array $lineItemIds = null;
3333

34+
/**
35+
* Has the link been published?
36+
*
37+
* @var bool|null $published
38+
*/
39+
public ?bool $published = null;
40+
3441
/**
3542
* Class constructor.
3643
*
@@ -61,6 +68,9 @@ public function toJsonObject(): object
6168
if (!is_null($this->lineItemIds)) {
6269
$item->lineItemIds = $this->lineItemIds;
6370
}
71+
if (!is_null($this->published)) {
72+
$item->published = $this->published;
73+
}
6474

6575
return $item;
6676
}
@@ -103,6 +113,14 @@ protected function fromJsonObject(object $obj): bool
103113
$ok = false;
104114
}
105115
break;
116+
case 'published':
117+
$published = Util::checkBoolean($obj, 'published', false);
118+
if (!is_null($published)) {
119+
$this->published = $published;
120+
} else {
121+
$ok = false;
122+
}
123+
break;
106124
case 'available':
107125
if (is_object($obj->available)) {
108126
$this->item->setAvailable(TimePeriod::fromJsonObject($obj->available));

src/Service/LinkContent.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ public function __construct(Platform $platform, string $endpoint, ?int $limit =
101101
*/
102102
public function getAll(?string $ltiResourceLinkId = null, ?int $limit = null): array|bool
103103
{
104+
$this->scope = self::$SCOPE_READ;
105+
$this->mediaType = self::MEDIA_TYPE_CONTENT_ITEMS;
104106
$params = [];
105107
if (!empty($ltiResourceLinkId)) {
106108
$params['resource_link_id'] = $ltiResourceLinkId;
@@ -157,6 +159,7 @@ public function getAll(?string $ltiResourceLinkId = null, ?int $limit = null): a
157159
*/
158160
public function createContentItem(ContentItem &$contentItem): bool
159161
{
162+
$this->scope = self::$SCOPE_CREATE;
160163
$this->mediaType = self::MEDIA_TYPE_CONTENT_ITEM;
161164
$http = $this->send('POST', null, $contentItem->toJson());
162165
$ok = $http->ok && !empty($http->responseJson);
@@ -177,8 +180,9 @@ public function createContentItem(ContentItem &$contentItem): bool
177180
*
178181
* @return bool True if successful
179182
*/
180-
public function saveContentItem(ContentItem $contentItem): bool
183+
public function saveContentItem(ContentItem &$contentItem): bool
181184
{
185+
$this->scope = self::$SCOPE_UPDATE;
182186
$this->mediaType = self::MEDIA_TYPE_CONTENT_ITEM;
183187
$http = $this->send('PUT', null, $contentItem->toJson());
184188
$ok = $http->ok;
@@ -201,6 +205,7 @@ public function saveContentItem(ContentItem $contentItem): bool
201205
*/
202206
public function deleteContentItem(): bool
203207
{
208+
$this->scope = self::$SCOPE_DELETE;
204209
$this->mediaType = self::MEDIA_TYPE_CONTENT_ITEM;
205210
$http = $this->send('DELETE');
206211

0 commit comments

Comments
 (0)