aboutsummaryrefslogtreecommitdiff
path: root/lib/models/Courseware/BlockTypes/Lti.php
blob: 193bfb5722798322865450cdfa86c180594d4083 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php

namespace Courseware\BlockTypes;

/**
 * This class represents the content of a Courseware LTI block.
 *
 * @author  Dennis Benz <debenz@uos.de>
 * @license GPL2 or any later version
 *
 * @since   Stud.IP 5.3
 */
class Lti extends BlockType
{
    public static function getType(): string
    {
        return 'lti';
    }

    public static function getTitle(): string
    {
        return _('LTI');
    }

    public static function getDescription(): string
    {
        return _('Einbinden eines externen Tools.');
    }

    public function initialPayload(): array
    {
        return [
            'title' => '',
            'height' => '640',
            'tool_id' => '',
            'launch_url' => '',
            'consumer_key' => '',
            'consumer_secret' => '',
            'oauth_signature_method' => 'sha1',
            'send_lis_person' => false,
            'custom_parameters' => '',
        ];
    }

    public static function getJsonSchema(): string
    {
        $schemaFile = __DIR__.'/Lti.json';
        return file_get_contents($schemaFile);
    }

    public function getPayload()
    {
        $payload = $this->decodePayloadString($this->block['payload']);
        $user = \User::findCurrent();

        // Remove sensitive lti parameters if user has no edit permission
        if (!$this->block->getStructuralElement()->canEdit($user)) {
            unset($payload['launch_url']);
            unset($payload['consumer_key']);
            unset($payload['consumer_secret']);
            unset($payload['oauth_signature_method']);
            unset($payload['send_lis_person']);
            unset($payload['custom_parameters']);
        }

        return $payload;
    }

    public static function getCategories(): array
    {
        return ['external'];
    }

    public static function getContentTypes(): array
    {
        return ['rich'];
    }

    public static function getFileTypes(): array
    {
        return [];
    }
}