ILIAS  release_8 Revision v8.24
class.ilObjFileListGUI.php
Go to the documentation of this file.
1<?php
2
20
28{
30
32 protected string $title;
33
34 public function __construct(int $context = self::CONTEXT_REPOSITORY)
35 {
37 $this->file_info = new ilObjFileInfoRepository();
38 }
39
43 public function init(): void
44 {
45 $this->delete_enabled = true;
46 $this->cut_enabled = true;
47 $this->copy_enabled = true;
48 $this->subscribe_enabled = true;
49 $this->link_enabled = true;
50 $this->info_screen_enabled = true;
51 $this->type = ilObjFile::OBJECT_TYPE;
52 $this->gui_class_name = ilObjFileGUI::class;
53 $this->commands = ilObjFileAccess::_getCommands();
54 }
55
59 public function getCommandFrame(string $cmd): string
60 {
61 $info = $this->file_info->getByObjectId($this->obj_id);
62
63 $frame = "";
64 switch ($cmd) {
65 case 'sendfile':
66 if ($info->shouldDeliverInline()) {
67 $frame = '_blank';
68 }
69 break;
70 case "":
71 $frame = ilFrameTargetInfo::_getFrame("RepositoryContent");
72 break;
73
74 default:
75 }
76
77 return $frame;
78 }
79
80
81
89 public function getIconImageType(): string
90 {
91 return $this->file_info->getByObjectId($this->obj_id)->shouldDeliverInline()
92 ? $this->type . '_inline'
94 }
95
96
97 public function getTitle(): string
98 {
99 // Remove filename extension from title
100 return $this->file_info->getByObjectId($this->obj_id)->getListTitle();
101
102 return $this->secure(preg_replace('/\\.[a-z0-9]+\\z/i', '', $this->title));
103
104 }
105
113 public function getProperties(): array
114 {
115 global $DIC;
116
117 $props = parent::getProperties();
118
119 $info = $this->file_info->getByObjectId($this->obj_id);
120
121 $revision = $info->getVersion();
122
123 $props[] = array(
124 "alert" => false,
125 "property" => $DIC->language()->txt("type"),
126 "value" => $info->getSuffix(),
127 'propertyNameVisible' => false,
128 );
129
130 $props[] = array(
131 "alert" => false,
132 "property" => $DIC->language()->txt("size"),
133 "value" => (string) $info->getFileSize(),
134 'propertyNameVisible' => false,
135 );
136
137 $version = $info->getVersion();
138 if ($version > 1) {
139 // add versions link
140 if (parent::checkCommandAccess("write", "versions", $this->ref_id, $this->type)) {
141 $link = $this->getCommandLink("versions");
142 $value = "<a href=\"$link\">" . $DIC->language()->txt("version") . ": $version</a>";
143 } else {
144 $value = $DIC->language()->txt("version") . ": $version";
145 }
146 $props[] = array(
147 "alert" => false,
148 "property" => $DIC->language()->txt("version"),
149 "value" => $value,
150 "propertyNameVisible" => false,
151 );
152 }
153
154 $props[] = array(
155 "alert" => false,
156 "property" => $DIC->language()->txt("last_update"),
158 new ilDateTime($info->getCreationDate()->format('U'), IL_CAL_UNIX)
159 ),
160 'propertyNameVisible' => false,
161 );
162
163 if ($info->getPageCount() !== null && $info->getPageCount() > 0) {
164 $props[] = array(
165 "alert" => false,
166 "property" => $DIC->language()->txt("page_count"),
167 "value" => $info->getPageCount(),
168 'propertyNameVisible' => true,
169 );
170 }
171
172 return $props;
173 }
174
178 public function getCommandImage($a_cmd): string
179 {
180 return "";
181 }
182
183 public function checkCommandAccess(
184 string $permission,
185 string $cmd,
186 int $ref_id,
187 string $type,
188 ?int $obj_id = null
189 ): bool {
190 if (ilFileVersionsGUI::CMD_UNZIP_CURRENT_REVISION === $cmd) {
191 $info = $this->file_info->getByObjectId($this->obj_id);
192
193 return $info->isZip() && parent::checkCommandAccess(
194 $permission,
195 $cmd,
196 $ref_id,
197 $type,
198 $obj_id
199 );
200 }
201
202 return parent::checkCommandAccess(
203 $permission,
204 $cmd,
205 $ref_id,
206 $type,
207 $obj_id
208 );
209 }
210
211 public function getCommandLink(string $cmd): string
212 {
213 // only create permalink for repository
214 if ($cmd === "sendfile" && $this->context === self::CONTEXT_REPOSITORY) {
215 // return the perma link for downloads
216 return ilObjFileAccess::_getPermanentDownloadLink($this->ref_id);
217 }
218
220 $info = $this->file_info->getByObjectId($this->obj_id);
221
222 if ($info->isZip()) {
223 $this->ctrl->setParameterByClass(ilRepositoryGUI::class, 'ref_id', $this->ref_id);
224 $cmd_link = $this->ctrl->getLinkTargetByClass(
225 ilRepositoryGUI::class,
227 );
228 $this->ctrl->setParameterByClass(ilRepositoryGUI::class, 'ref_id', $this->requested_ref_id);
229 } else {
230 $access_granted = false;
231 }
232 }
233
234
235 return parent::getCommandLink($cmd);
236 }
237}
$version
Definition: plugin.php:24
Mime type determination.
Definition: MimeType.php:28
const IL_CAL_UNIX
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
Class ilFileVersionsGUI.
static _getFrame(string $a_class)
static _getCommands()
get commands this method returns an array of all possible commands/permission combinations example: $...
static _getPermanentDownloadLink(int $ref_id)
Gets the permanent download link for the file.
Class ilObjFileListGUI.
getCommandLink(string $cmd)
Get command link url.
checkCommandAccess(string $permission, string $cmd, int $ref_id, string $type, ?int $obj_id=null)
getProperties()
Get item properties.
getTitle()
getTitle overwritten in class.ilObjLinkResourceList.php
getCommandFrame(string $cmd)
Get command target frame.
ilObjFileInfoRepository $file_info
getCommandImage($a_cmd)
Get command icon image.
getIconImageType()
Returns the icon image type.
__construct(int $context=self::CONTEXT_REPOSITORY)
const OBJECT_TYPE
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
trait ilObjFileSecureString
Trait ilObjFileSecureString.