Newer
Older
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
<?php
class OwncloudFile implements FileType
{
public $data = [];
protected $foldertype = null;
public function __construct($data, $foldertype)
{
$this->data = $data;
$this->foldertype = $foldertype;
}
/**
* Returns the name of the icon shape that shall be used with the FileType implementation.
*
* @param string $role role of icon
* @return Icon icon for the FileType implementation.
*/
public function getIcon($role)
{
$shape = FileManager::getIconNameForMimeType(
$this->data['mime_type']
);
return Icon::create($shape, $role);
}
/**
* Returns the id of the file which is most likely the id of the FileRef object
* within the FileType object.
* @return mixed
*/
public function getId()
{
return $this->data['id'];
}
/**
* Filename of the FileType-object.
* @return mixed
*/
public function getFilename()
{
return $this->data['name'];
}
/**
* The user_id in Stud.IP if the author has Stud.IP account. If it has none, return null.
* @return mixed|null
*/
public function getUserId()
{
return $this->data['user_id'];
}
/**
* Return the name of the author as a string.
* @return string|null
*/
public function getUserName()
{
return get_fullname($this->data['user_id']);
}
/**
* @returns The User object representing the author.
*/
public function getUser()
{
return new User($this->data['user_id']);
}
/**
* Returns the size of the file in bytes. If this is null, the file doesn't exist
* physically - is probably only a weblink or a request for libraries.
* @return integer|null
*/
public function getSize()
{
return $this->data['size'];
}
/**
* Returns the URL to download the file. May be sendfile.php?... or an external link.
* @return string|null
*/
public function getDownloadURL()
{
return $this->data['download_url'];
}
/**
* Returns the number of downloads this file already has. Returns null if information is not available.
* @return integer|null
*/
public function getDownloads()
{
return 0;
}
/**
* Returns the (real) file system path for the file.
* This is only relevant for FileType implementations storing real files
* on the server disk. Other implementations shall just return
* an empty string.
*
* @returns The file system path for the file or an empty string if the
* file doesn't have a path in the file system.
*/
public function getPath() : string
{
return "";
}
/**
* Returns the UNIX-Timestamp of the last change or null if this information is unknown.
* @return integer|null
*/
public function getLastChangeDate()
{
return $this->data['chdate'];
}
/**
* Returns the UNIX-timestamp of creation of that file
* @return integer|null
*/
public function getMakeDate()
{
return $this->data['chdate'];
}
/**
* Returns the description of that FileType object.
* @return string|null
*/
public function getDescription()
{
return $this->data['description'];
}
/**
* Returns the mime-type of that FileType-object.
* @return string
*/
public function getMimeType()
{
return $this->data['mime_type'];
}
/**
* @return ContentTermsOfUse
*/
public function getTermsOfUse()
{
return ContentTermsOfUse::findDefault();
}
/**
* Returns an instance of ActionMenu.
* @return ActionMenu|null
*/
public function getActionmenu()
{
$actionMenu = ActionMenu::get();
$actionMenu->addLink(
URLHelper::getURL("dispatch.php/file/details/{$this->getId()}", [
'to_plugin' => "OwnCloudPlugin",
'from_plugin' => "OwnCloudPlugin",
'file_navigation' => 1
]),
_('Info'),
Icon::create('info-circle', Icon::ROLE_CLICKABLE, ['size' => 20]),
['data-dialog' => ''],
'file-display-info'
);
if ($current_action === 'flat') {
if (Navigation::hasItem('/course/files') && Navigation::getItem('/course/files')->isActive()) {
$actionMenu->addLink(
URLHelper::getURL('dispatch.php/course/files/index/' . $this->fileref->folder_id),
_('Ordner öffnen'),
Icon::create('folder-empty', Icon::ROLE_CLICKABLE, ['size' => 20])
);
} elseif (Navigation::hasItem('/files_dashboard/files') && Navigation::getItem('/files_dashboard/files')->isActive()) {
$actionMenu->addLink(
URLHelper::getURL('dispatch.php/files/index/' . $this->fileref->folder_id),
_('Ordner öffnen'),
Icon::create('folder-empty', Icon::ROLE_CLICKABLE, ['size' => 20])
);
}
}
if ($this->isEditable($GLOBALS['user']->id)) {
$actionMenu->addLink(
URLHelper::getURL('dispatch.php/file/edit/' . $this->fileref->id),
_('Datei bearbeiten'),
Icon::create('edit', Icon::ROLE_CLICKABLE, ['size' => 20]),
['data-dialog' => ''],
'file-edit'
);
$actionMenu->addLink(
URLHelper::getURL('dispatch.php/file/update/' . $this->fileref->id),
_('Datei aktualisieren'),
Icon::create('refresh', Icon::ROLE_CLICKABLE, ['size' => 20]),
['data-dialog' => ''],
'file-update'
);
}
if ($this->isWritable($GLOBALS['user']->id)) {
$actionMenu->addLink(
URLHelper::getURL('dispatch.php/file/choose_destination/move/' . $this->fileref->id),
_('Datei verschieben'),
Icon::create('file+move_right', Icon::ROLE_CLICKABLE, ['size' => 20]),
['data-dialog' => 'size=auto'],
'file-move'
);
}
if ($this->isDownloadable($GLOBALS['user']->id) && $GLOBALS['user']->id !== 'nobody') {
$actionMenu->addLink(
URLHelper::getURL('dispatch.php/file/choose_destination/copy/' . $this->fileref->id),
_('Datei kopieren'),
Icon::create('file+add', Icon::ROLE_CLICKABLE, ['size' => 20]),
['data-dialog' => 'size=auto'],
'file-copy'
);
$actionMenu->addLink(
$this->getDownloadURL('force_download'),
_('Link kopieren'),
Icon::create('group'),
['class' => 'copyable-link'],
'link-to-clipboard'
);
}
if (Context::isCourse() && Feedback::isActivated()) {
if (Feedback::hasCreatePerm(Context::getId())) {
$actionMenu->addLink(
URLHelper::getURL('dispatch.php/course/feedback/create_form/'. $this->fileref->id . '/FileRef'),
_('Neues Feedback-Element'),
Icon::create('star+add', Icon::ROLE_CLICKABLE, ['size' => 20]),
['data-dialog' => '1']
);
}
}
if ($this->isWritable($GLOBALS['user']->id)) {
$actionMenu->addButton(
'delete',
_('Datei löschen'),
Icon::create('trash', Icon::ROLE_CLICKABLE, ['size' => 20]),
[
'formaction' => URLHelper::getURL("dispatch.php/file/delete/{$this->getId()}", $flat_view ? ['from_flat_view' => 1] : []),
'data-confirm' => sprintf(_('Soll die Datei "%s" wirklich gelöscht werden?'), $this->getFilename()),
]
);
}
NotificationCenter::postNotification("FileActionMenuWillRender", $actionMenu, $this);
return $actionMenu;
}
/**
* Returns a list of Stud.IP button objects that represent actions
* that shall be visible for the file type in the info dialog.
*
* @param array $extra_link_params An optional array of URL parameters
* that should be added to Button URLs, if reasonable. The parameter
* names are the keys of the array while their values are also the
* array item values.
*
* @returns Interactable[] A list of Stud.IP buttons (LinkButton or Button).
*/
public function getInfoDialogButtons(array $extra_link_params = []) : array
{
return [];
}
/**
* Deletes that file.
* @return bool : true on success
*/
public function delete()
{
return $this->foldertype->deleteFile($this->getId());
}
/**
* Returns the FolderTyp of the parent folder.
* @return FolderType
*/
public function getFolderType()
{
return $this->foldertype;
}
/**
* Determines whether the file is visible for a user.
*
* @param string $user_id The user for which the visibility of the file
* shall be determined.
*
* @return boolean True, if the user is permitted to see the file, false otherwise.
*/
public function isVisible($user_id = null)
{
return true;
}
/**
* Determines if a user may download the file.
* @param string $user_id The user who wishes to download the file.
* @return boolean True, if the user is permitted to download the file, false otherwise.
*/
public function isDownloadable($user_id = null)
{
return true;
}
/**
* Determines if a user may edit the file.
* @param string $user_id The user who wishes to edit the file.
* @return boolean True, if the user is permitted to edit the file, false otherwise.
*/
public function isEditable($user_id = null)
{
return true;
}
/**
* Determines if a user may write to the file.
* @param string $user_id The user who wishes to write to the file.
* @return boolean True, if the user is permitted to write to the file, false otherwise.
*/
public function isWritable($user_id = null)
{
return true;
}
/**
* Returns an object of the class StandardFile or a derived class.
* @return StandardFile
*/
public function convertToStandardFile()
{
//TODO
}
/**
* Returns the content for that additional column, if it exists. You can return null a string
* or a Flexi_Template as the content.
* @param string $column_index
* @return null|string|Flexi_Template
*/
public function getContentForAdditionalColumn($column_index)
{
return null;
}
/**
* Returns an integer that marks the value the content of the given column should be
* ordered by.
* @param string $column_index
* @return integer : order value
*/
public function getAdditionalColumnOrderWeigh($column_index)
{
return 0;
}
/**
* Generates a Flexi_Template containing additional information that are
* displayes in the information dialog of a file.
*
* @param bool $include_downloadable_infos Whether to include information
* like file previews that can be downloaded (true) or to not
* include them (false). Defaults to false.
*
* @returns Flexi_Template|null Either a Flexi_Template containing
* additional information or null if no such information shall be
* displayed in the information dialog.
*/
public function getInfoTemplate(bool $include_downloadable_infos = false)
{
return null;
}
}