aboutsummaryrefslogtreecommitdiff
path: root/lib/filesystem/VirtualFolderType.php
blob: ac868ca7afe561fc621592a800ba8c49ac843021 (plain)
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
<?php
/**
 * VirtualFolderType.php
 *
 * This is a FolderType implementation for folders that dont exist in
 * the database table folders, e.g. folders from plugins
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * @author    Rasmus Fuhse <fuhse@data-quest.de>
 * @copyright 2016 Stud.IP Core-Group
 * @license   http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 * @category  Stud.IP
 */
class VirtualFolderType implements FolderType
{
    /**
     * @var array
     */
    protected $folderdata;
    /**
     * @var string
     */
    protected $plugin_id;

    /**
     * @var array
     */
    protected $files      = [];
    /**
     * @var array
     */
    protected $subfolders = [];

    /**
     * VirtualFolderType constructor.
     * @param array $folderdata
     * @param null $plugin_id
     */
    public function __construct($folderdata = [], $plugin_id = null)
    {
        $this->folderdata = $folderdata;
        //Make sure the description field is not empty so that folders
        //of this type are compatible with StandardFolder types:
        if (empty($this->folderdata['description'])) {
            $this->folderdata['description'] = '';
        }
        $this->plugin_id  = $plugin_id;
    }

    /**
     * @return string
     */
    public static function getTypeName()
    {
        return _('Virtueller Ordner');
    }

    /**
     * @param Object|string $range_id_or_object
     * @param string $user_id
     * @return bool
     */
    public static function availableInRange($range_id_or_object, $user_id)
    {
        return false;
    }

    /**
     * @param string $role
     * @return Icon
     */
    public function getIcon($role = 'info')
    {
        return Icon::create('folder-empty', $role);
    }

    /**
     * @return mixed
     */
    public function getId()
    {
        return $this->folderdata['id'];
    }

    /**
     * @param $attribute
     * @return mixed
     */
    public function __get($attribute)
    {
        return $this->folderdata[$attribute] ?? null;
    }

    /**
     * @param $attribute
     * @param $value
     */
    public function __set($attribute, $value)
    {
        $this->folderdata[$attribute] = $value;
    }

    /**
     * @param $user_id
     * @return bool
     */
    public function isVisible($user_id)
    {
        return true;
    }

    /**
     * @param string $user_id
     * @return bool
     */
    public function isReadable($user_id)
    {
        return true;
    }

    /**
     * @param string $user_id
     * @return bool
     */
    public function isWritable($user_id)
    {
        return false;
    }

    /**
     * @param string $user_id
     * @return bool
     */
    public function isEditable($user_id)
    {
        return false;
    }

    /**
     * @param string $user_id
     * @return bool
     */
    public function isSubfolderAllowed($user_id)
    {
        return false;
    }

    /**
     * @return null
     */
    public function getDescriptionTemplate()
    {
        return null;
    }

    /**
     * @return null
     */
    public function getEditTemplate()
    {
        return null;
    }

    /**
     * @param ArrayAccess|Request $request
     */
    public function setDataFromEditTemplate($request)
    {
        return MessageBox::error('Not applicable for virtual folder type');
    }

    /**
     * @param $uploadedfile
     * @param string $user_id
     * @return bool
     */
    public function validateUpload(FileType $file, $user_id)
    {
        return false;
    }

    /**
     * @return array
     */
    public function getSubfolders()
    {
        return $this->subfolders;
    }

    /**
     * @return array
     */
    public function getFiles()
    {
        return $this->files;
    }

    /**
     * @return null
     */
    public function getParent()
    {
        if (!$this->folderdata['parent_id']) {
            return null;
        }

        if ($this->plugin_id) {
            return PluginManager::getInstance()->getPluginById($this->plugin_id)->getFolder($this->folderdata->parent_id);
        }

        return $this->folderdata->parent_id
             ? $this->folderdata->parentfolder->getTypedFolder()
             : null;
    }

    /**
     * @param array|ArrayAccess $file
     * @return FileRef
     */
    public function addFile(FileType $file, $user_id = null)
    {
        $this->files[] = $file;
        return end($this->files);
    }

    /**
     * @param string $file_ref_id
     * @return bool
     */
    public function deleteFile($file_ref_id)
    {
        return true;
    }

    /**
     * @param FolderType $folderdata
     * @return FolderType
     */
    public function createSubfolder(FolderType $folderdata)
    {
        $this->subfolders[] = $folderdata;
        return $folderdata;
    }

    /**
     * @param string $subfolder_id
     * @return bool
     */
    public function deleteSubfolder($subfolder_id)
    {
        return true;
    }

    /**
     * @return bool
     */
    public function delete()
    {
        return true;
    }

    public function store()
    {
        return 0;
    }

    /**
     * @param string $fileref_or_id
     * @param string $user_id
     * @return bool
     */
    public function isFileDownloadable($fileref_or_id, $user_id)
    {
        return true;
    }

    /**
     * @param string $fileref_or_id
     * @param string $user_id
     * @return bool
     */
    public function isFileEditable($fileref_or_id, $user_id)
    {
        return false;
    }

    /**
     * @param $fileref_or_id
     * @param string $user_id
     * @return bool
     */
    public function isFileWritable($fileref_or_id, $user_id)
    {
        return false;
    }

    public function getAdditionalColumns()
    {
        return [];
    }

    public function getContentForAdditionalColumn($column_index)
    {
        return null;
    }

    public function getAdditionalColumnOrderWeigh($column_index)
    {
        return 0;
    }

    public function getAdditionalActionButtons()
    {
        return [];
    }

    /**
     * @see FolderType::copySettings()
     */
    public function copySettings()
    {
        return ['description' => $this->description];
    }

}