* @copyright 2016 data-quest * @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2 * @category Stud.IP */ class HomeworkFolder extends PermissionEnabledFolder { public static $sorter = 2; /** * Returns a localised name of the HomeworkFolder type. * * @return string The localised name of this folder type. */ public static function getTypeName(): string { return _('Ordner für Hausarbeiten'); } public static function availableInRange(SimpleORMap|string $range_id_or_object, string $user_id): bool { $course = Course::toObject($range_id_or_object); if ($course && !$course->isNew()) { return Seminar_Perm::get()->have_studip_perm('tutor', $course->id, $user_id); } return false; } public function __construct($folderdata = null) { parent::__construct($folderdata); $this->permission = 3; } /** * Returns the Icon object for the HomeworkFolder type. * * @return Icon An icon object with the icon for this folder type. */ public function getIcon(string $role = Icon::DEFAULT_ROLE): Icon { $shape = $this->is_empty ? 'folder-edit-empty' : 'folder-edit-full'; return Icon::create($shape, $role); } /** * Homework folders don't allow subfolders. * * @return bool False */ public function isSubfolderAllowed(string $user_id): bool { //no subfolders allowed (I'm a homework folder, not a home folder backup!) return false; } /** * Returns the description template for a HomeworkFolder instance. * * @return \Flexi\Template|string|null A description for the HomeworkFolder instance. */ public function getDescriptionTemplate(): \Flexi\Template|string|null { $template = $GLOBALS['template_factory']->open('filesystem/homework_folder/description.php'); $template->folder = $this; $template->folderdata = $this->folderdata; return $template; } /** * @param string|null $user_id * @return bool */ public function isReadable(string $user_id = null): bool { return StandardFolder::isReadable($user_id); } /** * Determines if a user may see the file. * @param FileRef|string $fileref_or_id * @param string $user_id * @return bool */ public function isFileVisible($fileref_or_id, $user_id) { $fileref = FileRef::toObject($fileref_or_id); return $fileref->user_id === $user_id || parent::isReadable($user_id); } /** * @param FileRef $file_ref * @param string $user_id * @return bool */ public function isFileEditable(FileRef $file_ref, string $user_id): bool { return $GLOBALS['perm']->have_studip_perm('tutor', $this->range_id, $user_id); } /** * Checks if a user has write permissions to a file. * * For standard folders write permissions are granted * if the user is the owner of the file or if the user has at least * tutor permissions on the Stud.IP object specified by range_id * (such objects may be courses or institutes for example). * * @param FileRef $file_ref * @param string $user_id * @return bool */ public function isFileWritable(FileRef $file_ref, string $user_id): bool { return $GLOBALS['perm']->have_studip_perm('tutor', $this->range_id, $user_id); } }