ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilObjFileListGUI.php
Go to the documentation of this file.
1 <?php
2 
26 
35 {
37 
42  protected string $title;
44  private Services $irss;
45 
46  public function __construct(int $context = self::CONTEXT_REPOSITORY)
47  {
48  global $DIC;
49  $this->capability_context = new Context(
50  0,
51  0,
52  match($context) {
53  self::CONTEXT_REPOSITORY => Context::CONTEXT_REPO,
54  self::CONTEXT_WORKSPACE => Context::CONTEXT_WORKSPACE,
55  self::CONTEXT_SEARCH => Context::CONTEXT_SEARCH,
56  default => Context::CONTEXT_REPO,
57  }
58  );
59 
61 
62  $DIC->language()->loadLanguageModule('wopi');
63  $this->file_info = new ilObjFileInfoRepository();
64  $this->capability_builder = new CapabilityBuilder(
65  $this->file_info,
66  $this->access,
67  $this->ctrl,
68  new ActionDBRepository($DIC->database()),
69  $DIC->http(),
70  $DIC['static_url.uri_builder']
71  );
72  }
73 
74  protected function updateContext(): void
75  {
76  $this->capability_context = $this->capability_context
77  ->withCallingId($this->ref_id ?? 0)
78  ->withObjectId($this->obj_id ?? 0);
79  }
80 
85  public function insertCommands(): void
86  {
87  }
88 
92  #[\Override]
93  public function init(): void
94  {
95  $this->delete_enabled = true;
96  $this->cut_enabled = true;
97  $this->copy_enabled = true;
98  $this->subscribe_enabled = true;
99  $this->link_enabled = true;
100  $this->info_screen_enabled = false;
101  $this->type = ilObjFile::OBJECT_TYPE;
102  $this->gui_class_name = ilObjFileGUI::class;
103  $this->icon_repo = new IconDatabaseRepository();
104 
105  $this->substitutions = ilAdvancedMDSubstitution::_getInstanceByObjectType($this->type);
106  if ($this->substitutions->isActive()) {
107  $this->substitutions_enabled = true;
108  }
109 
110  $this->commands = ilObjFileAccess::_getCommands();
111  $this->updateContext();
112  }
113 
114  #[\Override]
115  public function getCommands(): array
116  {
117  $this->updateContext();
118  $this->capabilities = $this->capability_builder->get($this->capability_context);
119 
120  $best = $this->capabilities->getBest();
121 
122  $default_key = null;
123 
124  foreach ($this->commands as $key => $command) {
125  if ($command['cmd'] === $best->getCapability()->value) {
126  $default_key = $key;
127  $this->commands[$key]['default'] = true;
128  }
129  }
130 
131  // we put a copy of the default command to the array, since otherwise its not rendered in the dropdown
132  if ($default_key !== null) {
133  $command_copy = $this->commands[$default_key];
134  $command_copy['default'] = false;
135 
136  $commands = [];
137 
138  foreach ($this->commands as $key => $command) {
139  if ($key === $default_key) {
140  $commands[] = $command_copy;
141  }
142  $commands[] = $command;
143  }
144  $this->commands = $commands;
145  }
146 
147  return parent::getCommands();
148  }
149 
150  #[\Override]
151  public function getCommandLink(string $cmd): string
152  {
153  $this->updateContext();
154  $this->capabilities = $this->capability_builder->get($this->capability_context);
155 
156  $needed_capability = Capabilities::fromCommand($cmd);
157  $capability = $this->capabilities->get($needed_capability);
158  if ($capability === false || !$capability->isUnlocked()) {
159  return '';
160  }
161 
162  switch ($this->context) {
163  case self::CONTEXT_REPOSITORY:
164  return (string) $capability->getURI();
165  case self::CONTEXT_WORKSPACE:
166  $this->ctrl->setParameterByClass(ilObjFileGUI::class, 'wsp_id', $this->ref_id);
167  if ($cmd === "sendfile" && !ilObjFileAccess::_shouldDownloadDirectly($this->obj_id)) {
168  return $this->ctrl->getLinkTargetByClass(
169  ilObjFileGUI::class,
170  Capabilities::INFO_PAGE->value
171  );
172  }
173  break;
174  }
175 
176  return parent::getCommandLink($cmd);
177  }
178 
179 
180 
181  #[\Override]
182  public function getTitle(): string
183  {
184  return $this->file_info->getByObjectId($this->obj_id)->getListTitle();
185  }
186 
187  public function stripTitleOfFileExtension(string $a_title): string
188  {
189  return $this->secure(preg_replace('/\.[^.]*$/', '', $a_title));
190  }
191 
192  #[\Override]
193  public function getCommandFrame(string $cmd): string
194  {
195  $this->updateContext();
196  $info = $this->file_info->getByObjectId($this->obj_id);
197 
198  if ($cmd === Capabilities::DOWNLOAD->value) {
199  return $info->shouldDeliverInline() ? '_blank' : '';
200  }
201 
202  return '';
203  }
204 
212  #[\Override]
213  public function getIconImageType(): string
214  {
215  return $this->file_info->getByObjectId($this->obj_id)->shouldDeliverInline()
216  ? $this->type . '_inline'
217  : $this->type;
218  }
219 
227  #[\Override]
228  public function getProperties(): array
229  {
230  global $DIC;
231 
232  $this->capabilities = $this->capability_builder->get($this->capability_context);
233 
234  $props = parent::getProperties();
235 
236  $info = $this->file_info->getByObjectId($this->obj_id);
237 
238  $props[] = [
239  "alert" => false,
240  "property" => $DIC->language()->txt("type"),
241  "value" => $info->getSuffix(),
242  'propertyNameVisible' => false,
243  ];
244 
245  $props[] = [
246  "alert" => false,
247  "property" => $DIC->language()->txt("size"),
248  "value" => (string) $info->getFileSize(),
249  'propertyNameVisible' => false,
250  ];
251 
252  $version = $info->getVersion();
253  if ($version > 1) {
254  // add versions link
255  if ($this->capabilities->get(Capabilities::MANAGE_VERSIONS)->isUnlocked()) {
256  $link = $this->getCommandLink("versions");
257  $value = "<a href=\"$link\">" . $DIC->language()->txt("version") . ": $version</a>";
258  } else {
259  $value = $DIC->language()->txt("version") . ": $version";
260  }
261  $props[] = [
262  "alert" => false,
263  "property" => $DIC->language()->txt("version"),
264  "value" => $value,
265  "propertyNameVisible" => false
266  ];
267  }
268 
269  $props[] = [
270  "alert" => false,
271  "property" => $DIC->language()->txt("last_update"),
273  new ilDateTime($info->getCreationDate()->format('U'), IL_CAL_UNIX)
274  ),
275  'propertyNameVisible' => false,
276  ];
277 
278  if ($info->getPageCount() !== null && $info->getPageCount() > 0) {
279  $props[] = [
280  "alert" => false,
281  "property" => $DIC->language()->txt("page_count"),
282  "value" => $info->getPageCount(),
283  'propertyNameVisible' => true,
284  ];
285  }
286 
287  return $props;
288  }
289 
293  #[\Override]
294  public function getCommandImage($a_cmd): string
295  {
296  return "";
297  }
298 
299  #[\Override]
300  public function checkCommandAccess(
301  string $permission,
302  string $cmd,
303  int $ref_id,
304  string $type,
305  ?int $obj_id = null
306  ): bool {
307  $this->updateContext();
308 
309  $this->capability_context = $this->capability_context
310  ->withCallingId($ref_id)
311  ->withObjectId($obj_id ?? $this->capability_context->getObjectId());
312 
313  // LP settings only in repository
314  if ($this->context !== self::CONTEXT_REPOSITORY && $permission === "edit_learning_progress") {
315  return false;
316  }
317 
318  $this->capabilities = $this->capability_builder->get($this->capability_context);
319 
320  $capability = Capabilities::fromCommand($cmd);
321  $additional_check = $this->capabilities->get($capability)->isUnlocked();
322 
323  return $additional_check && parent::checkCommandAccess(
324  $permission,
325  $cmd,
326  $ref_id,
327  $type,
328  $obj_id
329  );
330  }
331 
332 }
$version
Definition: plugin.php:24
getIconImageType()
Returns the icon image type.
const OBJECT_TYPE
static _getCommands()
get commands this method returns an array of all possible commands/permission combinations example: $...
const IL_CAL_UNIX
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
insertCommands()
This methods seems to be called by ItemRenderer
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26
static _shouldDownloadDirectly(int $obj_id)
__construct(int $context=self::CONTEXT_REPOSITORY)
ilObjFileInfoRepository $file_info
CapabilityCollection $capabilities
CapabilityBuilder $capability_builder
trait ilObjFileSecureString
Trait ilObjFileSecureString.
getProperties()
Get item properties.
__construct(Container $dic, ilPlugin $plugin)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
$info
Definition: entry_point.php:21
IconDatabaseRepository $icon_repo
stripTitleOfFileExtension(string $a_title)
Class ilObjFileListGUI.
checkCommandAccess(string $permission, string $cmd, int $ref_id, string $type, ?int $obj_id=null)
getCommandImage($a_cmd)
Get command icon image.
static _getInstanceByObjectType(string $a_type)