Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
namespace Packback\Lti1p3\DeepLinkResources;
4
 
5
use Packback\Lti1p3\Concerns\Arrayable;
6
use Packback\Lti1p3\LtiConstants;
7
use Packback\Lti1p3\LtiLineitem;
8
 
9
class Resource
10
{
11
    use Arrayable;
12
    private string $type = LtiConstants::DL_RESOURCE_LINK_TYPE;
13
    private ?string $title = null;
14
    private ?string $text = null;
15
    private ?string $url = null;
16
    private ?LtiLineitem $line_item = null;
17
    private ?Icon $icon = null;
18
    private ?Icon $thumbnail = null;
19
    private array $custom_params = [];
20
    private string $target = 'iframe';
21
    private ?Iframe $iframe = null;
22
    private ?Window $window = null;
23
    private ?DateTimeInterval $availability_interval = null;
24
    private ?DateTimeInterval $submission_interval = null;
25
 
26
    public static function new(): self
27
    {
28
        return new Resource();
29
    }
30
 
31
    public function getArray(): array
32
    {
33
        $resource = [
34
            'type' => $this->type,
35
            'title' => $this->title,
36
            'text' => $this->text,
37
            'url' => $this->url,
38
            'icon' => $this->icon?->toArray(),
39
            'thumbnail' => $this->thumbnail?->toArray(),
40
            'iframe' => $this->iframe?->toArray(),
41
            'window' => $this->window?->toArray(),
42
            'available' => $this->availability_interval?->toArray(),
43
            'submission' => $this->submission_interval?->toArray(),
44
        ];
45
 
46
        if (!empty($this->custom_params)) {
47
            $resource['custom'] = $this->custom_params;
48
        }
49
 
50
        if (isset($this->line_item)) {
51
            $resource['lineItem'] = [
52
                'scoreMaximum' => $this->line_item->getScoreMaximum(),
53
                'label' => $this->line_item->getLabel(),
54
            ];
55
        }
56
 
57
        // Kept for backwards compatibility
58
        if (!isset($this->iframe) && !isset($this->window)) {
59
            $resource['presentation'] = [
60
                'documentTarget' => $this->target,
61
            ];
62
        }
63
 
64
        return $resource;
65
    }
66
 
67
    public function getType(): string
68
    {
69
        return $this->type;
70
    }
71
 
72
    public function setType(string $value): self
73
    {
74
        $this->type = $value;
75
 
76
        return $this;
77
    }
78
 
79
    public function getTitle(): ?string
80
    {
81
        return $this->title;
82
    }
83
 
84
    public function setTitle(?string $value): self
85
    {
86
        $this->title = $value;
87
 
88
        return $this;
89
    }
90
 
91
    public function getText(): ?string
92
    {
93
        return $this->text;
94
    }
95
 
96
    public function setText(?string $value): self
97
    {
98
        $this->text = $value;
99
 
100
        return $this;
101
    }
102
 
103
    public function getUrl(): ?string
104
    {
105
        return $this->url;
106
    }
107
 
108
    public function setUrl(?string $value): self
109
    {
110
        $this->url = $value;
111
 
112
        return $this;
113
    }
114
 
115
    public function getLineItem(): ?LtiLineitem
116
    {
117
        return $this->line_item;
118
    }
119
 
120
    public function setLineItem(?LtiLineitem $value): self
121
    {
122
        $this->line_item = $value;
123
 
124
        return $this;
125
    }
126
 
127
    public function setIcon(?Icon $icon): self
128
    {
129
        $this->icon = $icon;
130
 
131
        return $this;
132
    }
133
 
134
    public function getIcon(): ?Icon
135
    {
136
        return $this->icon;
137
    }
138
 
139
    public function setThumbnail(?Icon $thumbnail): self
140
    {
141
        $this->thumbnail = $thumbnail;
142
 
143
        return $this;
144
    }
145
 
146
    public function getThumbnail(): ?Icon
147
    {
148
        return $this->thumbnail;
149
    }
150
 
151
    public function getCustomParams(): array
152
    {
153
        return $this->custom_params;
154
    }
155
 
156
    public function setCustomParams(array $value): self
157
    {
158
        $this->custom_params = $value;
159
 
160
        return $this;
161
    }
162
 
163
    public function getIframe(): ?Iframe
164
    {
165
        return $this->iframe;
166
    }
167
 
168
    public function setIframe(?Iframe $iframe): self
169
    {
170
        $this->iframe = $iframe;
171
 
172
        return $this;
173
    }
174
 
175
    public function getWindow(): ?Window
176
    {
177
        return $this->window;
178
    }
179
 
180
    public function setWindow(?Window $window): self
181
    {
182
        $this->window = $window;
183
 
184
        return $this;
185
    }
186
 
187
    public function getAvailabilityInterval(): ?DateTimeInterval
188
    {
189
        return $this->availability_interval;
190
    }
191
 
192
    public function setAvailabilityInterval(?DateTimeInterval $availabilityInterval): self
193
    {
194
        $this->availability_interval = $availabilityInterval;
195
 
196
        return $this;
197
    }
198
 
199
    public function getSubmissionInterval(): ?DateTimeInterval
200
    {
201
        return $this->submission_interval;
202
    }
203
 
204
    public function setSubmissionInterval(?DateTimeInterval $submissionInterval): self
205
    {
206
        $this->submission_interval = $submissionInterval;
207
 
208
        return $this;
209
    }
210
}