aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/LTI13a/RegistrationManager.php
blob: 922cb5876a78d3ccd88d74fa15e78756d39b05a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php

namespace Studip\LTI13a;

use OAT\Library\Lti1p3Core\Registration\RegistrationRepositoryInterface;
use OAT\Library\Lti1p3Core\Registration\RegistrationInterface;

class RegistrationManager implements RegistrationRepositoryInterface
{
    #[\Override]
    public function find(string $identifier): ?RegistrationInterface
    {
        //The identifier is the ID of a tool.
        $tool = \LtiTool::find($identifier);
        if (!$tool) {
            return null;
        }
        return new Registration($tool);
    }

    /**
     * @inheritDoc
     */
    #[\Override]
    public function findAll(): array
    {
        $tools = \LtiTool::findBySQL('TRUE');
        $registrations = [];
        foreach ($tools as $tool) {
            $registrations[] = new Registration($tool);
        }
        return $registrations;
    }

    #[\Override]
    public function findByClientId(string $clientId): ?RegistrationInterface
    {
        //Find a registration by its client-ID. The client-ID is equivalent to the tool-ID in Stud.IP.
        if (!$clientId) {
            //Nothing to search for.
            return null;
        }
        $tool = \LtiTool::find($clientId);
        if ($tool) {
            return new Registration($tool);
        }
        return null;
    }

    #[\Override]
    public function findByPlatformIssuer(string $issuer, string $clientId = null): ?RegistrationInterface
    {
        //Only handle requests for registrations of this Stud.IP:
        if ($issuer !== \Config::get()->STUDIP_INSTALLATION_ID) {
            //Invalid issuer.
            return null;
        }
        return $this->findByClientId($clientId);
    }

    #[\Override]
    public function findByToolIssuer(string $issuer, string $clientId = null): ?RegistrationInterface
    {
        //Tool registrations are not supported at this moment.
        return null;
    }
}