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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
<?php
namespace Courseware\BlockTypes;
/**
* This class represents the content of a Courseware gallery block.
*
* @author Ron Lucke <lucke@elan-ev.de>
* @license GPL2 or any later version
*
* @since Stud.IP 5.0
*/
class Gallery extends BlockType
{
public static function getType(): string
{
return 'gallery';
}
public static function getTitle(): string
{
return _('Galerie');
}
public static function getDescription(): string
{
return _('Bilder aus einem Ordner im Dateibereich zeigen.');
}
/**
* Returns the decoded payload of the block associated with this instance.
*
* @return mixed the decoded payload
*/
public function getPayload()
{
$user = \User::findCurrent();
$payload = $this->decodePayloadString($this->block['payload']);
$folder = \Folder::find($payload['folder_id']);
$payload['folder-type'] = null;
$payload['files'] = [];
if ($folder) {
$typedFolder = $folder->getTypedFolder();
if ($typedFolder->folder_type === 'HiddenFolder' && !$typedFolder->download_allowed) {
return $payload;
}
$payload['folder-type'] = $typedFolder->folder_type;
foreach ($typedFolder->getFiles() as $folderFile) {
$fileRef = $folderFile->getFileRef();
$file = [];
$file['id'] = $folderFile->id;
$file['attributes'] = [
'name' => $folderFile->name,
'mime-type' => $folderFile->mime_type,
'filesize' => (int) $folderFile->size,
'description' => $fileRef->description,
'mkdate' => date('c', $folderFile->mkdate),
];
$file['relationships'] = [
'owner' => [
'data' => ['type' => 'users', 'id' => $folderFile->user_id],
'meta' => ['name' => $fileRef->getAuthorName()]
]
];
$file['meta'] = [
'download-url' => $folderFile->getDownloadURL(),
];
if ($this->filePermission($typedFolder, $file, $user) && $fileRef->isImage()) {
array_push($payload['files'], $file);
}
}
}
return $payload;
}
private function filePermission($typedFolder, $file, $user): bool
{
return $typedFolder->folder_type !== 'HomeworkFolder' || $user->id === $file['relationships']['owner']['data']['id'] || $typedFolder->isReadable($user->id);
}
public function initialPayload(): array
{
return [
'folder_id' => '',
'layout' => 'carousel',
'autoplay' => 'false',
'autoplay_timer' => '2',
'nav' => 'true',
'height' => '620',
'cols' => '25',
'show_filenames' => 'true',
'show_description' => 'false',
'mouseover_filenames' => 'false',
];
}
/**
* get all files related to this bloc.
*
* @return \FileRef[] list of file references realted to this block
*/
public function getFiles(): array
{
$payload = $this->getPayload();
if (!$payload['folder_id']) {
return [];
}
$files = [];
if ($fileRefs = \FileRef::findByFolder_id($payload['folder_id'])) {
$files = $fileRefs;
}
return $files;
}
public function copyPayload(string $rangeId = ''): array
{
$payload = $this->getPayload();
if ('' != $payload['folder_id']) {
$payload['folder_id'] = $this->copyFolderById($payload['folder_id'], $rangeId);
}
return $payload;
}
public static function getJsonSchema(): string
{
$schemaFile = __DIR__.'/Gallery.json';
return file_get_contents($schemaFile);
}
public static function getCategories(): array
{
return ['multimedia'];
}
public static function getContentTypes(): array
{
return ['image'];
}
public static function getFileTypes(): array
{
return ['image'];
}
public static function getTags(): array
{
return [
_('Bild'), _('Gestaltung'), _('Galerie'), _('Bilderkarussell'), _('Illustration'),
_('Foto'), 'jpg', 'png', 'gif', _('Abbildung'), _('Slideshow'),
_('Diashow'), _('Slider'), _('blättern'), _('Veranschaulichung'), _('Visualisierung')
];
}
}
|