aboutsummaryrefslogtreecommitdiff
path: root/lib/filesystem/HiddenFolder.php
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+github@gmail.com>2021-07-22 16:07:19 +0200
committerJan-Hendrik Willms <tleilax+github@gmail.com>2021-07-22 16:19:12 +0200
commita3da1483a9e689846179159355badfec8073dbec (patch)
tree770dcca6bdf5f6f2a11b0e7fcbbeda6919a3fc52 /lib/filesystem/HiddenFolder.php
current code from svn, revision 62608
Diffstat (limited to 'lib/filesystem/HiddenFolder.php')
-rw-r--r--lib/filesystem/HiddenFolder.php147
1 files changed, 147 insertions, 0 deletions
diff --git a/lib/filesystem/HiddenFolder.php b/lib/filesystem/HiddenFolder.php
new file mode 100644
index 0000000..ff71d3b
--- /dev/null
+++ b/lib/filesystem/HiddenFolder.php
@@ -0,0 +1,147 @@
+<?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($range_id_or_object, $user_id)
+ {
+ $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()
+ {
+ 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($role = Icon::DEFAULT_ROLE)
+ {
+ $shape = $this->is_empty
+ ? 'folder-lock-empty+visibility-invisible'
+ : 'folder-lock-full+visibility-invisible';
+ 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 mixed A description template for a instance of the type HiddenFolder
+ */
+ public function getDescriptionTemplate()
+ {
+ $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
+ */
+ public function getEditTemplate()
+ {
+ $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 $request The data from the edit template.
+ *
+ * @return FolderType
+ */
+ public function setDataFromEditTemplate($request)
+ {
+ $this->download_allowed = (int)$request['hidden_folder_download_allowed'];
+ return parent::setDataFromEditTemplate($request);
+ }
+
+ /**
+ * @param $attribute
+ * @return mixed
+ */
+ public function __get($attribute)
+ {
+ if ($attribute === 'download_allowed') {
+ return $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_or_id
+ * @param $user_id
+ * @return bool
+ */
+ public function isFileDownloadable($fileref_or_id, $user_id)
+ {
+ $fileref = FileRef::toObject($fileref_or_id);
+
+ if (is_object($fileref)) {
+ if (($this->download_allowed || Seminar_Perm::get()->have_studip_perm('tutor', $this->range_id, $user_id))
+ && $this->getParent()->isVisible($user_id)
+ && $this->getParent()->isReadable($user_id)) {
+ return $fileref->terms_of_use->IsDownloadable($this->range_id, $this->range_type, true, $user_id);
+ }
+ }
+ return false;
+ }
+
+}