diff options
| author | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2025-01-08 16:18:30 +0100 |
|---|---|---|
| committer | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2025-01-14 11:13:58 +0100 |
| commit | 0b864974695ab43c20751a3f046dd60fea831d65 (patch) | |
| tree | da9e6d822cd0cc53b6ca27aad2d5166fb9080d38 /lib | |
| parent | cc4cf319f3d1faacebd39e2d8415134b8e90b7c6 (diff) | |
remove displayDownloads() in favor of just a single method
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/filesystem/FileType.php | 5 | ||||
| -rw-r--r-- | lib/filesystem/FolderType.php | 12 | ||||
| -rw-r--r-- | lib/filesystem/InboxOutboxFolder.php | 7 | ||||
| -rw-r--r-- | lib/filesystem/PermissionEnabledFolder.php | 11 | ||||
| -rw-r--r-- | lib/filesystem/StandardFile.php | 7 | ||||
| -rw-r--r-- | lib/filesystem/StandardFolder.php | 12 | ||||
| -rw-r--r-- | lib/filesystem/UnknownFileType.php | 12 | ||||
| -rw-r--r-- | lib/filesystem/UnknownFolderType.php | 7 | ||||
| -rw-r--r-- | lib/filesystem/VirtualFolderType.php | 8 | ||||
| -rw-r--r-- | lib/models/FileRef.php | 2 |
10 files changed, 30 insertions, 53 deletions
diff --git a/lib/filesystem/FileType.php b/lib/filesystem/FileType.php index 3dcd32f..f634cd9 100644 --- a/lib/filesystem/FileType.php +++ b/lib/filesystem/FileType.php @@ -208,4 +208,9 @@ interface FileType * displayed in the information dialog. */ public function getInfoTemplate(bool $include_downloadable_infos = false); + + /** + * Returns the underlying file ref (or null, if none). + */ + public function getFileRef(): ?FileRef; } diff --git a/lib/filesystem/FolderType.php b/lib/filesystem/FolderType.php index ce976d5..4b0501a 100644 --- a/lib/filesystem/FolderType.php +++ b/lib/filesystem/FolderType.php @@ -286,18 +286,14 @@ interface FolderType /** * Returns (perhaps only a subset of) description and data_content of the folder for copying - * - * @return array */ public function copySettings(): array; /** * Returns whether the downloads in this folder should be counted or not. + * + * If a specific file ref is passed, you may decide whether to count the + * download for this file ref or not. */ - public function countDownload(FileRef $ref): bool; - - /** - * This method decides whether downloads should be displayed. - */ - public function displayDownloads(): bool; + public function countDownloads(?FileRef $ref = null): bool; } diff --git a/lib/filesystem/InboxOutboxFolder.php b/lib/filesystem/InboxOutboxFolder.php index 8077d04..bab9253 100644 --- a/lib/filesystem/InboxOutboxFolder.php +++ b/lib/filesystem/InboxOutboxFolder.php @@ -314,12 +314,7 @@ class InboxOutboxFolder implements FolderType return ['description' => $this->description]; } - public function countDownload(FileRef $ref): bool - { - return true; - } - - public function displayDownloads(): bool + public function countDownloads(?FileRef $ref = null): bool { return true; } diff --git a/lib/filesystem/PermissionEnabledFolder.php b/lib/filesystem/PermissionEnabledFolder.php index a732186..032f699 100644 --- a/lib/filesystem/PermissionEnabledFolder.php +++ b/lib/filesystem/PermissionEnabledFolder.php @@ -161,14 +161,9 @@ class PermissionEnabledFolder extends StandardFolder ]; } - public function countDownload(FileRef $ref): bool + public function countDownloads(?FileRef $ref = null): bool { - return $this->displayDownloads() - && parent::countDownload($ref); - } - - public function displayDownloads(): bool - { - return (bool) ($this->permission & $this->perms['r']); + return ($this->permission & $this->perms['r']) + && parent::countDownloads($ref); } } diff --git a/lib/filesystem/StandardFile.php b/lib/filesystem/StandardFile.php index b11e2f5..f357b47 100644 --- a/lib/filesystem/StandardFile.php +++ b/lib/filesystem/StandardFile.php @@ -14,12 +14,9 @@ */ class StandardFile implements FileType, ArrayAccess, StandardFileInterface { + protected ?FileRef $fileref = null; /** - * @var FileRef - */ - protected $fileref = null; - /** * @var File */ protected $file = null; @@ -453,7 +450,7 @@ class StandardFile implements FileType, ArrayAccess, StandardFileInterface return new static($fileref); } - public function getFileRef() + public function getFileRef(): ?FileRef { return $this->fileref; } diff --git a/lib/filesystem/StandardFolder.php b/lib/filesystem/StandardFolder.php index 9f5bf7b..61642e9 100644 --- a/lib/filesystem/StandardFolder.php +++ b/lib/filesystem/StandardFolder.php @@ -552,15 +552,13 @@ class StandardFolder implements FolderType return ['description' => $this->description]; } - - public function countDownload(FileRef $ref): bool + public function countDownloads(?FileRef $ref = null): bool { + if (!$ref) { + return true; + } + $user = User::findCurrent(); return !$user || $ref->user_id !== $user->id; } - - public function displayDownloads(): bool - { - return true; - } } diff --git a/lib/filesystem/UnknownFileType.php b/lib/filesystem/UnknownFileType.php index 33d6c53..5cb8a27 100644 --- a/lib/filesystem/UnknownFileType.php +++ b/lib/filesystem/UnknownFileType.php @@ -15,12 +15,9 @@ class UnknownFileType implements FileType, ArrayAccess { - /** - * @var FileRef - */ - protected $fileref = null; + protected ?FileRef $fileref = null; - public function __construct($fileref = null) + public function __construct(?FileRef $fileref = null) { $this->fileref = $fileref; } @@ -291,4 +288,9 @@ class UnknownFileType implements FileType, ArrayAccess { return false; } + + public function getFileRef(): ?FileRef + { + return $this->fileref; + } } diff --git a/lib/filesystem/UnknownFolderType.php b/lib/filesystem/UnknownFolderType.php index 5b38509..2cd7fd2 100644 --- a/lib/filesystem/UnknownFolderType.php +++ b/lib/filesystem/UnknownFolderType.php @@ -297,12 +297,7 @@ class UnknownFolderType implements FolderType return ['description' => $this->description]; } - public function countDownload(FileRef $ref): bool - { - return true; - } - - public function displayDownloads(): bool + public function countDownloads(?FileRef $ref = null): bool { return true; } diff --git a/lib/filesystem/VirtualFolderType.php b/lib/filesystem/VirtualFolderType.php index 269dd59..0e2c2b4 100644 --- a/lib/filesystem/VirtualFolderType.php +++ b/lib/filesystem/VirtualFolderType.php @@ -323,13 +323,7 @@ class VirtualFolderType implements FolderType return ['description' => $this->description]; } - - public function countDownload(FileRef $ref): bool - { - return true; - } - - public function displayDownloads(): bool + public function countDownloads(?FileRef $ref = null): bool { return true; } diff --git a/lib/models/FileRef.php b/lib/models/FileRef.php index 5f94024..eeedf26 100644 --- a/lib/models/FileRef.php +++ b/lib/models/FileRef.php @@ -223,7 +223,7 @@ class FileRef extends SimpleORMap implements PrivacyObject, FeedbackRange */ public function incrementDownloadCounter() { - if (!$this->folder->getTypedFolder()->countDownload($this)) { + if (!$this->folder->getTypedFolder()->countDownloads($this)) { return 0; } |
