packbackbooks / lti-1-3-php-library

A library used for building IMS-certified LTI 1.3 tool providers in PHP.
Apache License 2.0
39 stars 25 forks source link

use grades service without launch_id vs with older launch_id #87

Closed phaazebroek closed 1 year ago

phaazebroek commented 1 year ago

we are looking for a way to set a grade a while after the user logged in. We are not sure whether the launch_id is still valid at that point in time.

Is it possible to use the grades service without a launch_id? or do we always need to store the launch_id and retrieve the original launch from cache, and use that launch for the grades service? is a relatively recent launch (say 2 hours ago) always present in the cache? and how do we keep the cache from growing extensively?

dbhynds commented 1 year ago

You don't need a launch_id to instantiate the LtiAssignmentsGradesService as long as you're saving the relevant data from a launch into the database. Here's some psuedocode of what we do to sync a grade:

    public function getGradeService($endpointData, $issuer): LtiAssignmentsGradesService
    {
        return new LtiAssignmentsGradesService(
            app(ILtiServiceConnector::class),
            $this->ltiRepository->findRegistrationByIssuer($issuer->issuer, $issuer->client_id),
            $endpointData);
    }

    // And to get the $endpointData

    private function buildEndpointData(Grade $grade): array
    {
        return [
            'scope' => [
                LtiConstants::AGS_SCOPE_LINEITEM,
                LtiConstants::AGS_SCOPE_LINEITEM_READONLY,
                LtiConstants::AGS_SCOPE_SCORE,
                LtiConstants::AGS_SCOPE_RESULT_READONLY,
            ],
            'lineitem' =>  $grade->lineitem_url,
            'lineitems' => $grade->resource_link->lineitems_url,
            'validation_context' => null,
            'errors' => [
                'errors' => [],
            ],
        ];
    }
phaazebroek commented 10 months ago

Great, thanks a lot for all your effort!!