oat-sa / lib-lti1p3-core

PHP library for LTI 1.3 Core implementations as platforms and / or as tools.
GNU General Public License v2.0
33 stars 17 forks source link

problem with adding multiple resourceCollection #175

Closed abanghendri closed 11 months ago

abanghendri commented 11 months ago

Hi Team, I try to add multiple ResourceCollection, but it doesn't work, here is what I've tried so far:

$resources = [];
foreach ($payload->courses as $uuid) {
   $course = Course::whereUuid($uuid)->first();
   $resources[] = new LtiResourceLink('ltiResourceLinkIdentifier', [
       'url' => getLtiDomain().'/launch',
       'title' => $course->name,
       'text'  => $course->settings['about'],
       'custom'    => [
          'course' => $uuid
       ],
    ]);
}
// agregate courses to resources collection
$resourceCollection = new ResourceCollection($resources); 

I also try this method

$resourceCollection = new ResourceCollection(); 
foreach ($payload->courses as $uuid) {
   $course = Course::whereUuid($uuid)->first();
   $resource = new LtiResourceLink('ltiResourceLinkIdentifier', [
       'url' => getLtiDomain().'/launch',
       'title' => $course->name,
       'text'  => $course->settings['about'],
       'custom'    => [
          'course' => $uuid
       ],
    ]);
$resourceCollection->add($resource);
}

both of those codes do not work, So how to add multiple items to resource collection properly?

wazelin commented 11 months ago

Hi, @abanghendri, Thank you for your interest in the library.

I can see that you are using the same identifier for all of your resource links in the collection. Each resource link object must have a distinct identity offer value to be added to the collection. In your case, they just overwrite one another.

wazelin commented 11 months ago

Basically, you can replace 'ltiResourceLinkIdentifier' with $uuid in either of your code snippets, and you should be good-to-go.

abanghendri commented 11 months ago

thank @wazelin, I lost my focus, it works fine when I change ltiResourceLinkIdentifier with my course's uuid