aboutsummaryrefslogtreecommitdiff
path: root/lib/models/LtiDeployment.php
blob: 86f18a0520e9774ef8f5c58e4859630fc00508bc (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/**
 * LtiDeployment.php - A class that represents an LTI tool deployment.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * @author      Elmar Ludwig
 * @author      Moritz Strohm
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 *
 * @property int $id database column
 * @property int $tool_id database column
 * @property int $mkdate database column
 * @property int $chdate database column
 * @property SimpleORMapCollection<LtiGrade> $grades has_many LtiGrade
 * @property LtiTool $tool belongs_to LtiTool
 */

class LtiDeployment extends SimpleORMap
{
    /**
     * Configure the database mapping.
     */
    protected static function configure($config = [])
    {
        $config['db_table'] = 'lti_deployments';

        $config['belongs_to']['tool'] = [
            'class_name'  => LtiTool::class,
            'foreign_key' => 'tool_id'
        ];
        $config['has_many']['resource_links'] = [
            'class_name'        => LtiResourceLink::class,
            'assoc_foreign_key' => 'deployment_id',
            'on_delete'         => 'delete'
        ];
        $config['has_many']['grades'] = [
            'class_name'        => LtiGrade::class,
            'assoc_foreign_key' => 'link_id',
            'on_delete'         => 'delete'
        ];

        parent::configure($config);
    }

    public function getToolLtiVersion() : string
    {
        return $this->tool->lti_version ?? '';
    }


    /**
     * Get the launch_url of this entry.
     *
     * @deprecated
     */
    public function getLaunchURL()
    {
        if (empty($this->tool->allow_custom_url) && empty($this->tool->deep_linking) || empty($this->launch_url)) {
            return $this->tool->launch_url ?? '';
        }
        return $this->launch_url;
    }

    /**
     * Get the consumer_key of this entry.
     *
     * @deprecated
     */
    public function getConsumerKey()
    {
        return $this->tool->consumer_key ?? '';
    }

    /**
     * Get the consumer_secret of this entry.
     *
     * @deprecated
     */
    public function getConsumerSecret()
    {
        return $this->tool->consumer_secret ?? '';
    }

    /**
     * Get the oauth_signature_method of this entry.
     *
     * @deprecated
     */
    public function getOauthSignatureMethod()
    {
        return $this->tool->oauth_signature_method ?? 'sha1';
    }

    /**
     * Get the custom_parameters of this entry.
     *
     * @deprecated
     */
    public function getCustomParameters()
    {
        $parameters = '';
        if (!empty($this->tool->custom_parameters)) {
            $parameters .= $this->tool->custom_parameters . "\n";
        }
        $parameters .= $this->options['custom_parameters'] ?? '';
        return $parameters;
    }

    /**
     * Get the send_lis_person attribute of this entry.
     */
    public function getSendLisPerson()
    {
        return $this->tool->send_lis_person;
    }

    /**
     * Whether the LtiData instance uses its own (private) tool
     * or one of the globally defined LTI tools.
     *
     * @return bool True, if the LtiData instance uses its own tool, false otherwise.
     */
    public function hasOwnTool() : bool
    {
        return $this->tool && !$this->tool->is_global;
    }
}