ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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  public function init(): void
93  {
94  $this->delete_enabled = true;
95  $this->cut_enabled = true;
96  $this->copy_enabled = true;
97  $this->subscribe_enabled = true;
98  $this->link_enabled = true;
99  $this->info_screen_enabled = false;
100  $this->type = ilObjFile::OBJECT_TYPE;
101  $this->gui_class_name = ilObjFileGUI::class;
102  $this->icon_repo = new IconDatabaseRepository();
103 
104  $this->substitutions = ilAdvancedMDSubstitution::_getInstanceByObjectType($this->type);
105  if ($this->substitutions->isActive()) {
106  $this->substitutions_enabled = true;
107  }
108 
109  $this->commands = ilObjFileAccess::_getCommands();
110  $this->updateContext();
111  }
112 
113  public function getCommands(): array
114  {
115  $this->updateContext();
116  $this->capabilities = $this->capability_builder->get($this->capability_context);
117 
118  $best = $this->capabilities->getBest();
119 
120  $default_key = null;
121 
122  foreach ($this->commands as $key => $command) {
123  if ($command['cmd'] === $best->getCapability()->value) {
124  $default_key = $key;
125  $this->commands[$key]['default'] = true;
126  }
127  }
128 
129  // we put a copy of the default command to the array, since otherwise its not rendered in the dropdown
130  if ($default_key !== null) {
131  $command_copy = $this->commands[$default_key];
132  $command_copy['default'] = false;
133 
134  $commands = [];
135 
136  foreach ($this->commands as $key => $command) {
137  if ($key === $default_key) {
138  $commands[] = $command_copy;
139  }
140  $commands[] = $command;
141  }
142  $this->commands = $commands;
143  }
144 
145  return parent::getCommands();
146  }
147 
148  public function getCommandLink(string $cmd): string
149  {
150  $this->updateContext();
151  $this->capabilities = $this->capability_builder->get($this->capability_context);
152 
153  $needed_capability = Capabilities::fromCommand($cmd);
154  $capability = $this->capabilities->get($needed_capability);
155  if ($capability === false || !$capability->isUnlocked()) {
156  return '';
157  }
158 
159  switch ($this->context) {
160  case self::CONTEXT_REPOSITORY:
161  return (string) $capability->getURI();
162  case self::CONTEXT_WORKSPACE:
163  $this->ctrl->setParameterByClass(ilObjFileGUI::class, 'wsp_id', $this->ref_id);
164  if ($cmd === "sendfile" && !ilObjFileAccess::_shouldDownloadDirectly($this->obj_id)) {
165  return $this->ctrl->getLinkTargetByClass(
166  ilObjFileGUI::class,
167  Capabilities::INFO_PAGE->value
168  );
169  }
170  break;
171  }
172 
173  return parent::getCommandLink($cmd);
174  }
175 
176  public function getTitle(): string
177  {
178  return $this->file_info->getByObjectId($this->obj_id)->getListTitle();
179  }
180 
181  public function stripTitleOfFileExtension(string $a_title): string
182  {
183  return $this->secure(preg_replace('/\.[^.]*$/', '', $a_title));
184  }
185 
186  public function getCommandFrame(string $cmd): string
187  {
188  $this->updateContext();
189  $info = $this->file_info->getByObjectId($this->obj_id);
190 
191  if ($cmd === Capabilities::DOWNLOAD->value) {
192  return $info->shouldDeliverInline() ? '_blank' : '';
193  }
194 
195  return '';
196  }
197 
205  public function getIconImageType(): string
206  {
207  return $this->file_info->getByObjectId($this->obj_id)->shouldDeliverInline()
208  ? $this->type . '_inline'
209  : $this->type;
210  }
211 
219  public function getProperties(): array
220  {
221  global $DIC;
222 
223  $this->capabilities = $this->capability_builder->get($this->capability_context);
224 
225  $props = parent::getProperties();
226 
227  $info = $this->file_info->getByObjectId($this->obj_id);
228 
229  $props[] = [
230  "alert" => false,
231  "property" => $DIC->language()->txt("type"),
232  "value" => $info->getSuffix(),
233  'propertyNameVisible' => false,
234  ];
235 
236  $props[] = [
237  "alert" => false,
238  "property" => $DIC->language()->txt("size"),
239  "value" => (string) $info->getFileSize(),
240  'propertyNameVisible' => false,
241  ];
242 
243  $version = $info->getVersion();
244  if ($version > 1) {
245  // add versions link
246  if ($this->capabilities->get(Capabilities::MANAGE_VERSIONS)->isUnlocked()) {
247  $link = $this->getCommandLink("versions");
248  $value = "<a href=\"$link\">" . $DIC->language()->txt("version") . ": $version</a>";
249  } else {
250  $value = $DIC->language()->txt("version") . ": $version";
251  }
252  $props[] = [
253  "alert" => false,
254  "property" => $DIC->language()->txt("version"),
255  "value" => $value,
256  "propertyNameVisible" => false
257  ];
258  }
259 
260  $props[] = [
261  "alert" => false,
262  "property" => $DIC->language()->txt("last_update"),
264  new ilDateTime($info->getCreationDate()->format('U'), IL_CAL_UNIX)
265  ),
266  'propertyNameVisible' => false,
267  ];
268 
269  if ($info->getPageCount() !== null && $info->getPageCount() > 0) {
270  $props[] = [
271  "alert" => false,
272  "property" => $DIC->language()->txt("page_count"),
273  "value" => $info->getPageCount(),
274  'propertyNameVisible' => true,
275  ];
276  }
277 
278  return $props;
279  }
280 
284  public function getCommandImage($a_cmd): string
285  {
286  return "";
287  }
288 
289  public function checkCommandAccess(
290  string $permission,
291  string $cmd,
292  int $ref_id,
293  string $type,
294  ?int $obj_id = null
295  ): bool {
296  $this->updateContext();
297 
298  $this->capability_context = $this->capability_context
299  ->withCallingId($ref_id)
300  ->withObjectId($obj_id ?? $this->capability_context->getObjectId());
301 
302  // LP settings only in repository
303  if ($this->context !== self::CONTEXT_REPOSITORY && $permission === "edit_learning_progress") {
304  return false;
305  }
306 
307  $this->capabilities = $this->capability_builder->get($this->capability_context);
308 
309  $capability = Capabilities::fromCommand($cmd);
310  $additional_check = $this->capabilities->get($capability)->isUnlocked();
311 
312  return $additional_check && parent::checkCommandAccess(
313  $permission,
314  $cmd,
315  $ref_id,
316  $type,
317  $obj_id
318  );
319  }
320 
321 }
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ilObjUser $user=null,)
$version
Definition: plugin.php:25
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
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:25
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)
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)