* @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; } }