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
|
<?php
/**
* HiddenFolder.php
*
* 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 Dominik Feldschnieders <dofeldsc@uos.de>
* @copyright 2016 Stud.IP Core-Group
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
*/
class HiddenFolder extends PermissionEnabledFolder
{
public static $sorter = 6;
// nobody can see, write or read in this folder except the lecturer and his tutors
protected $permission = 0;
public static function availableInRange(SimpleORMap|string $range_id_or_object, string $user_id): bool
{
$range_id = is_object($range_id_or_object) ? $range_id_or_object->id : $range_id_or_object;
return Seminar_Perm::get()->have_studip_perm('tutor', $range_id, $user_id);
}
/**
* Returns the name of the HiddenFolder type.
*
* @return string the name of the HiddenFolder type
*/
public static function getTypeName(): string
{
return _("Unsichtbarer Ordner");
}
/**
* This function returns the suitable Icon for this folder type (HiddenFolder)
*
* @return Icon The icon object for this folder type
*/
public function getIcon(string $role = Icon::DEFAULT_ROLE): Icon
{
$shape = $this->is_empty
? 'folder-lock-empty'
: 'folder-lock-full';
return Icon::create($shape, $role);
}
/**
* HiddenFolder constructor.
*/
public function __construct($folderdata = null)
{
parent::__construct($folderdata);
$this->permission = 0;
}
/**
* Returns the description template for a instance of a HiddenFolder type
*
* @return \Flexi\Template|string|null A description template for a instance of the type HiddenFolder
*/
public function getDescriptionTemplate(): \Flexi\Template|string|null
{
$template = $GLOBALS['template_factory']->open('filesystem/hidden_folder/description.php');
$template->type = self::getTypeName();
$template->folder = $this;
$template->folderdata = $this->folderdata;
return $template;
}
/**
* Returns the edit template for this folder type.
*
* @return \Flexi\Template|null
*/
public function getEditTemplate(): ?\Flexi\Template
{
$template = $GLOBALS['template_factory']->open('filesystem/hidden_folder/edit.php');
$template->download_allowed = $this->download_allowed;
return $template;
}
/**
* Sets the data from a submitted edit template.
*
* @param array|ArrayAccess $folderdata The data from the edit template.
*
* @return FolderType|MessageBox
*/
public function setDataFromEditTemplate(array|ArrayAccess $folderdata): FolderType|MessageBox
{
$this->download_allowed = (int) $folderdata['hidden_folder_download_allowed'];
return parent::setDataFromEditTemplate($folderdata);
}
/**
* @param $attribute
* @return mixed
*/
public function __get($attribute)
{
if ($attribute === 'download_allowed') {
return !empty($this->folderdata['data_content']['download_allowed']);
}
return $this->folderdata[$attribute];
}
/**
* @param $name
* @param $value
* @return mixed
*/
public function __set($name, $value)
{
if ($name === 'download_allowed') {
return $this->folderdata['data_content']['download_allowed'] = $value;
}
return $this->folderdata[$name] = $value;
}
/**
* @param FileRef $file_ref
* @param string $user_id
* @return bool
*/
public function isFileDownloadable(FileRef $file_ref, string $user_id): bool
{
if ($this->download_allowed || Seminar_Perm::get()->have_studip_perm('tutor', $this->range_id, $user_id)) {
return $file_ref->terms_of_use->isDownloadable($this->range_id, $this->range_type, true, $user_id);
}
return false;
}
}
|