ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
trait.ilObjFileInfoProvider.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
28{
32 public function getFileInfoForUsers(): array
33 {
34 // page count
35 $page_count = $this->getFileObj()->getPageCount();
36 $page_count = ($page_count !== 0) ? $page_count : null;
37 // preview
38 $preview_renderer = new ilObjFilePreviewRendererGUI($this->getFileObj()->getId());
39 $preview = null;
40 if ($preview_renderer->has() && !$this->getCtrl()->isAsynch()) {
41 $preview = $preview_renderer->getRenderedTriggerComponents(true);
42 }
43
44 $data_size = new DataSize(
45 $this->getFileObj()->getFileSize(),
46 DataSize::KB
47 );
48
49 return [
50 $this->getLanguage()->txt("filename") => $this->getFileObj()->getFileName(),
51 $this->getLanguage()->txt("type") => $this->getFileObj()->getFileExtension(),
52 $this->getLanguage()->txt("size") => (string) $data_size,
53 $this->getLanguage()->txt("page_count") => $page_count,
54 $this->getLanguage()->txt("preview") => $preview
55 ];
56 }
57
64 public function getFileInfoForAll(): array
65 {
66 // version number
67 $version_nr = $this->getFileObj()->getVersion();
68 // version date
69 $version = $this->getFileObj()->getVersions([$version_nr]);
70 $version = end($version);
71 $version_date = null;
72 if ($version instanceof ilObjFileVersion) {
73 $version_date = (new ilDateTime($version->getDate(), IL_CAL_DATETIME))->get(IL_CAL_DATETIME);
74 }
75 // version uploader
76 $version_uploader = $version["user_id"] ?? -1; // unknown uploader
77 // download link
78 $download_link_tpl = null;
79 if ($this->getAccessHandler()->checkAccessOfUser(
80 $this->getUser()->getId(),
81 "read",
82 "sendfile",
83 $this->getFileObj()->getRefId()
84 )) {
85 $download_link_tpl = new ilTemplate("tpl.download_link.html", true, true, "components/ILIAS/File");
86 $download_link_tpl->setVariable("LINK", ilObjFileAccess::_getPermanentDownloadLink($this->getNodeID()));
87 }
88
89 return [
90 $this->getLanguage()->txt("version") => $version_nr,
91 $this->getLanguage()->txt("version_uploaded") => $version_date,
92 $this->getLanguage()->txt("file_uploaded_by") => ilUserUtil::getNamePresentation($version_uploader),
93 $this->getLanguage()->txt("download_link") => $download_link_tpl->get(),
94 $this->getLanguage()->txt("download_link") => $download_link_tpl->get(),
95 ];
96 }
97
101 public function getFileInfoForAuthorsAndAdmins(): array
102 {
103 $amount_of_downloads = null;
104
105 if ($this->getGeneralSettings()->isShowAmountOfDownloads()) {
106 $amount_of_downloads = sprintf(
107 $this->getLanguage()->txt("amount_of_downloads_since"),
108 $this->getFileObj()->getAmountOfDownloads(),
109 $this->getFileObj()->getCreateDate(),
110 );
111 }
112
113 return [
114 $this->getLanguage()->txt("mime_type") => $this->getFileObj()->getFileType(),
115 $this->getLanguage()->txt("resource_id") => $this->getFileObj()->getResourceId(),
116 $this->getLanguage()->txt("storage_id") => $this->getFileObj()->getStorageID(),
117 $this->getLanguage()->txt("amount_of_downloads") => $amount_of_downloads
118 ];
119 }
120
127 public function getAllFileInfoForCurrentUser(): array
128 {
129 $file_info = [];
130 $access_handler = $this->getAccessHandler();
131
132 if ($access_handler instanceof ilWorkspaceAccessHandler) {
133 return []; // ilWorkspaceAccessHandler has a different checkAccessOfUser method
134 }
135
136 if ($access_handler->checkAccessOfUser(
137 $this->getUser()->getId(),
138 "read",
139 "",
140 $this->getFileObj()->getRefId()
141 )) {
142 $file_info['for_users'] = $this->getFileInfoForUsers();
143 $file_info['for_all'] = $this->getFileInfoForAll();
144 }
145 if ($access_handler->checkAccessOfUser(
146 $this->getUser()->getId(),
147 "write",
148 "",
149 $this->getFileObj()->getRefId()
150 )) {
151 $file_info['for_authors_and_admins'] = $this->getFileInfoForAuthorsAndAdmins();
152 }
153
154 return $file_info;
155 }
156
157 abstract protected function getAccessHandler(); // must be compatible with ilObject2GUI::getAccessHandler()
158
159 abstract protected function getCtrl(): ilCtrl;
160
161 abstract protected function getFileObj(): ?ilObjFile;
162
163 abstract protected function getFileStakeholder(): ilObjFileStakeholder;
164
165 abstract protected function getGeneralSettings(): General;
166
167 abstract protected function getLanguage(): ilLanguage;
168
169 abstract protected function getNodeID(): int;
170
171 abstract protected function getUser(): ilObjUser;
172}
$version
Definition: plugin.php:24
This class provides the data size with additional information to remove the work to calculate the siz...
Definition: DataSize.php:31
const IL_CAL_DATETIME
Class ilCtrl provides processing control methods.
@classDescription Date and time handling
language handling
static _getPermanentDownloadLink(int $ref_id)
Gets the permanent download link for the file.
Class ilObjFileStakeholder.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjFile.
User class.
special template class to simplify handling of ITX/PEAR
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link='', bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path=null)
Default behaviour is:
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getCtrl()
getFileStakeholder()
getNodeID()
getFileObj()
getGeneralSettings()
getUser()
trait ilObjFileInfoProvider
getLanguage()