1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the xAPI package. |
5
|
|
|
* |
6
|
|
|
* (c) Christian Flothmann <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Xabbuh\XApi\Model; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* An Experience API statement {@link https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#attachments attachment}. |
16
|
|
|
* |
17
|
|
|
* @author Christian Flothmann <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
final class Attachment |
20
|
|
|
{ |
21
|
|
|
private $usageType; |
22
|
|
|
private $contentType; |
23
|
|
|
private $length; |
24
|
|
|
private $sha2; |
25
|
|
|
private $display; |
26
|
|
|
private $description; |
27
|
|
|
private $fileUrl; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param string $usageType The type of usage of this attachment |
31
|
|
|
* @param string $contentType The content type of the attachment |
32
|
|
|
* @param int $length The length of the attachment data in octets |
33
|
|
|
* @param string $sha2 The SHA-2 hash of the attachment data |
34
|
|
|
* @param LanguageMap $display Localized display name (title) |
35
|
|
|
* @param LanguageMap|null $description Localized description |
36
|
|
|
* @param string|null $fileUrl An IRL at which the attachment data can be retrieved |
37
|
|
|
*/ |
38
|
|
|
public function __construct($usageType, $contentType, $length, $sha2, LanguageMap $display, LanguageMap $description = null, $fileUrl = null) |
39
|
|
|
{ |
40
|
|
|
$this->usageType = $usageType; |
41
|
|
|
$this->contentType = $contentType; |
42
|
|
|
$this->length = $length; |
43
|
|
|
$this->sha2 = $sha2; |
44
|
|
|
$this->display = $display; |
45
|
|
|
$this->description = $description; |
46
|
|
|
$this->fileUrl = $fileUrl; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getUsageType() |
50
|
|
|
{ |
51
|
|
|
return $this->usageType; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getContentType() |
55
|
|
|
{ |
56
|
|
|
return $this->contentType; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function getLength() |
60
|
|
|
{ |
61
|
|
|
return $this->length; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getSha2() |
65
|
|
|
{ |
66
|
|
|
return $this->sha2; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function getDisplay() |
70
|
|
|
{ |
71
|
|
|
return $this->display; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function getDescription() |
75
|
|
|
{ |
76
|
|
|
return $this->description; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getFileUrl() |
80
|
|
|
{ |
81
|
|
|
return $this->fileUrl; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function equals(Attachment $attachment) |
85
|
|
|
{ |
86
|
|
|
if ($this->usageType !== $attachment->usageType) { |
87
|
|
|
return false; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
if ($this->contentType !== $attachment->contentType) { |
91
|
|
|
return false; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
if ($this->length !== $attachment->length) { |
95
|
|
|
return false; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
if ($this->sha2 !== $attachment->sha2) { |
99
|
|
|
return false; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
if (!$this->display->equals($attachment->display)) { |
103
|
|
|
return false; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
if (null !== $this->description xor null !== $attachment->description) { |
107
|
|
|
return false; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
if (null !== $this->description && null !== $attachment->description && !$this->description->equals($attachment->description)) { |
111
|
|
|
return false; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
if ($this->fileUrl !== $attachment->fileUrl) { |
115
|
|
|
return false; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
return true; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|