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
|
<?php
/**
* Class FilesystemVueDataManager is a manager that provides for a file or a folder
* the data that the vue component FilesTable needs to display the file or folder.
*/
class FilesystemVueDataManager
{
/**
* Provides for a file the data that the vue component FilesTable needs
* to display that file. Data is provides as an array that can be easily
* transferred into a JSON-object.
* @param FileType $file : the file that should be displayed
* @param FolderType $topFolder : The top-folder of that file
* @return array of data
*/
public static function getFileVueData(FileType $file, FolderType $topFolder, $last_visitdate = null)
{
$isDownloadable = $file->isDownloadable($GLOBALS['user']->id);
$terms = $file->getTermsOfUse();
$additionalColumns = [];
foreach ((array) $topFolder->getAdditionalColumns() as $index => $name) {
$additionalColumns[$index] = [
'html' => (string) $file->getContentForAdditionalColumn($index),
'order' => $file->getAdditionalColumnOrderWeigh($index)
];
}
$actionMenu = $file->getActionMenu();
return [
'id' => $file->getId(),
'name' => $file->getFilename(),
'download_url' => $isDownloadable ? $file->getDownloadURL() : null,
'downloads' => $file->getDownloads(),
'mime_type' => $file->getMimeType(),
'icon' => $file->getIcon($isDownloadable ? Icon::ROLE_CLICKABLE : Icon::ROLE_INFO)->getShape(),
'size' => $file->getSize(),
'author_url' => $file->getUser() && $file->getUserId() !== $GLOBALS['user']->id ? URLHelper::getURL('dispatch.php/profile', ['username' => $file->getUser()->username], true) : "",
'author_name' => $file->getUserName(),
'author_id' => $file->getUserId(),
'chdate' => (int) $file->getLastChangeDate(),
'additionalColumns' => $additionalColumns,
'details_url' => URLhelper::getURL("dispatch.php/file/details/{$file->getId()}", ['file_navigation' => '1']),
'restrictedTermsOfUse' => $terms && !$terms->isDownloadable($topFolder->range_id, $topFolder->range_type, false),
'actions' => $actionMenu ? (is_string($actionMenu) ? $actionMenu : $actionMenu->render()) : "",
'new' => isset($last_visitdate) && $file->getLastChangeDate() > $last_visitdate && $file->getUserId() !== $GLOBALS['user']->id,
'isEditable' => $file->isEditable(),
];
}
/**
* Provides for a folder the data that the vue component FilesTable needs
* to display that folder. Data is provides as an array that can be easily
* transferred into a JSON-object.
* @param FolderType $folder : the folder that should be displayed
* @param FolderType $topFolder : The top-folder of that file
* @return array of data
*/
public static function getFolderVueData(FolderType $folder, FolderType $topFolder)
{
$actionMenu = ActionMenu::get();
$actionMenu->addLink(
URLHelper::getURL('dispatch.php/file/details/' . $folder->getId()),
_('Info'),
Icon::create('info-circle', 'clickable', ['size' => 20]),
['data-dialog' => '1']
);
if ($folder->isEditable($GLOBALS['user']->id)) {
$actionMenu->addLink(
URLHelper::getURL('dispatch.php/file/edit_folder/' . $folder->getId()),
_('Ordner bearbeiten'),
Icon::create('edit', 'clickable', ['size' => 20]),
['data-dialog' => '1']
);
}
if ($folder->isReadable($GLOBALS['user']->id) && $GLOBALS['user']->id !== 'nobody') {
$actionMenu->addLink(
URLHelper::getURL('dispatch.php/file/download_folder/' . $folder->getId()),
_('Ordner herunterladen'),
Icon::create('download', 'clickable', ['size' => 20])
);
}
if ($folder->isEditable($GLOBALS['user']->id)) {
$actionMenu->addLink(
URLHelper::getURL('dispatch.php/file/choose_destination/move/' . $folder->getId(), ['isfolder' => 1]),
_('Ordner verschieben'),
Icon::create('folder-empty+move_right', 'clickable', ['size' => 20]),
['data-dialog' => 'size=auto']
);
$actionMenu->addLink(
URLHelper::getURL('dispatch.php/file/choose_destination/copy/' . $folder->getId(), ['isfolder' => 1]),
_('Ordner kopieren'),
Icon::create('folder-empty+add', 'clickable', ['size' => 20]),
['data-dialog' => 'size=auto']
);
$actionMenu->addLink(
URLHelper::getURL('dispatch.php/file/delete_folder/' . $folder->getId()),
_('Ordner löschen'),
Icon::create('trash', 'clickable', ['size' => 20]),
['onclick' => "return STUDIP.Dialog.confirmAsPost('" . sprintf(_('Soll der Ordner "%s" wirklich gelöscht werden?'), htmlReady($folder->name)) . "', this.href);"]
);
}
$permissions = "";
if ($folder->isReadable($GLOBALS['user']->id)) {
$permissions .= 'r';
}
if ($folder->isEditable($GLOBALS['user']->id)) {
$permissions .= 'w';
}
if ($folder->isReadable($GLOBALS['user']->id)) {
$permissions .= 'd';
}
$additionalColumns = [];
foreach ($topFolder->getAdditionalColumns() as $index => $name) {
$additionalColumns[$index] = [
'html' => (string) $folder->getContentForAdditionalColumn($index),
'order' => $folder->getAdditionalColumnOrderWeigh($index)
];
}
$controllerpath = 'files/index';
if (is_numeric($topFolder->range_type)) {
//plugin:
$controllerpath = 'files/system/' . $topFolder->range_type;
} elseif ($topFolder->range_type !== 'user') {
$controllerpath = $topFolder->range_type . '/' . $controllerpath;
}
$vue_folder = [
'id' => $folder->getId(),
'icon' => $folder->getIcon(Icon::ROLE_CLICKABLE)->getShape(),
'name' => $folder->name,
'url' => URLhelper::getURL('dispatch.php/' . $controllerpath . '/' . $folder->getId()),
'user_id' => $folder->user_id,
'author_name' => $folder->owner ? $folder->owner->getFullname('no_title_rev') : '',
'author_url' => $folder->owner && $folder->owner->id !== $GLOBALS['user']->id? URLHelper::getURL('dispatch.php/profile', ['username' => $folder->owner->username]) : '',
'chdate' => (int) $folder->chdate,
'actions' => $actionMenu->render(),
'mime_type' => get_class($folder),
'permissions' => $permissions,
'additionalColumns' => $additionalColumns
];
return $vue_folder;
}
}
|