ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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 
63  $DIC->language()->loadLanguageModule('wopi');
64  $this->file_info = new ilObjFileInfoRepository();
65  $this->capability_builder = new CapabilityBuilder(
66  $this->file_info,
67  $this->access,
68  $this->ctrl,
69  new ActionDBRepository($DIC->database()),
70  $DIC->http()
71  );
72 
73 
74  }
75 
76  protected function updateContext(): void
77  {
78  $this->capability_context = $this->capability_context
79  ->withCallingId($this->ref_id ?? 0)
80  ->withObjectId($this->obj_id ?? 0);
81  }
82 
86  public function init(): void
87  {
88  $this->delete_enabled = true;
89  $this->cut_enabled = true;
90  $this->copy_enabled = true;
91  $this->subscribe_enabled = true;
92  $this->link_enabled = true;
93  $this->info_screen_enabled = false;
94  $this->type = ilObjFile::OBJECT_TYPE;
95  $this->gui_class_name = ilObjFileGUI::class;
96  $this->icon_repo = new IconDatabaseRepository();
97 
98  $this->substitutions = ilAdvancedMDSubstitution::_getInstanceByObjectType($this->type);
99  if ($this->substitutions->isActive()) {
100  $this->substitutions_enabled = true;
101  }
102 
103  $this->commands = ilObjFileAccess::_getCommands();
104  $this->updateContext();
105  }
106 
107  public function getCommands(): array
108  {
109  $this->updateContext();
110  $this->capabilities = $this->capability_builder->get($this->capability_context);
111 
112  $best = $this->capabilities->getBest();
113 
114  foreach ($this->commands as $key => $command) {
115  if ($command['cmd'] === $best->getCapability()->value) {
116  $default_set = true;
117  $this->commands[$key]['default'] = true;
118  }
119  }
120 
121  return parent::getCommands();
122  }
123 
124  public function getCommandLink(string $cmd): string
125  {
126  $this->updateContext();
127  $this->capabilities = $this->capability_builder->get($this->capability_context);
128 
129  $needed_capability = Capabilities::fromCommand($cmd);
130  $capability = $this->capabilities->get($needed_capability);
131  if ($capability === false || !$capability->isUnlocked()) {
132  return '';
133  }
134 
135  switch ($this->context) {
136  case self::CONTEXT_REPOSITORY:
137  return (string) $capability->getURI();
138  case self::CONTEXT_WORKSPACE:
139  $this->ctrl->setParameterByClass(ilObjFileGUI::class, 'wsp_id', $this->ref_id);
140  if ($cmd === "sendfile" && !ilObjFileAccess::_shouldDownloadDirectly($this->obj_id)) {
141  return $this->ctrl->getLinkTargetByClass(
142  ilObjFileGUI::class,
143  Capabilities::INFO_PAGE->value
144  );
145  }
146  break;
147 
148  }
149 
150  return parent::getCommandLink($cmd);
151  }
152 
153 
154 
155  public function getTitle(): string
156  {
157  return $this->file_info->getByObjectId($this->obj_id)->getListTitle();
158  }
159 
160  public function stripTitleOfFileExtension(string $a_title): string
161  {
162  return $this->secure(preg_replace('/\.[^.]*$/', '', $a_title));
163  }
164 
165  public function getCommandFrame(string $cmd): string
166  {
167  $this->updateContext();
168  $info = $this->file_info->getByObjectId($this->obj_id);
169 
170  if ($cmd === Capabilities::DOWNLOAD->value) {
171  return $info->shouldDeliverInline() ? '_blank' : '';
172  }
173 
174  return '';
175  }
176 
184  public function getIconImageType(): string
185  {
186  return $this->file_info->getByObjectId($this->obj_id)->shouldDeliverInline()
187  ? $this->type . '_inline'
188  : $this->type;
189  }
190 
191 
199  public function getProperties(): array
200  {
201  global $DIC;
202 
203  $this->capabilities = $this->capability_builder->get($this->capability_context);
204 
205  $props = parent::getProperties();
206 
207  $info = $this->file_info->getByObjectId($this->obj_id);
208 
209  $props[] = [
210  "alert" => false,
211  "property" => $DIC->language()->txt("type"),
212  "value" => $info->getSuffix(),
213  'propertyNameVisible' => false,
214  ];
215 
216  $props[] = [
217  "alert" => false,
218  "property" => $DIC->language()->txt("size"),
219  "value" => (string) $info->getFileSize(),
220  'propertyNameVisible' => false,
221  ];
222 
223  $version = $info->getVersion();
224  if ($version > 1) {
225 
226  // add versions link
227  if ($this->capabilities->get(Capabilities::MANAGE_VERSIONS)->isUnlocked()) {
228  $link = $this->getCommandLink("versions");
229  $value = "<a href=\"$link\">" . $DIC->language()->txt("version") . ": $version</a>";
230  } else {
231  $value = $DIC->language()->txt("version") . ": $version";
232  }
233  $props[] = [
234  "alert" => false,
235  "property" => $DIC->language()->txt("version"),
236  "value" => $value,
237  "propertyNameVisible" => false
238  ];
239  }
240 
241  $props[] = [
242  "alert" => false,
243  "property" => $DIC->language()->txt("last_update"),
245  new ilDateTime($info->getCreationDate()->format('U'), IL_CAL_UNIX)
246  ),
247  'propertyNameVisible' => false,
248  ];
249 
250  if ($info->getPageCount() !== null && $info->getPageCount() > 0) {
251  $props[] = [
252  "alert" => false,
253  "property" => $DIC->language()->txt("page_count"),
254  "value" => $info->getPageCount(),
255  'propertyNameVisible' => true,
256  ];
257  }
258 
259  return $props;
260  }
261 
265  public function getCommandImage($a_cmd): string
266  {
267  return "";
268  }
269 
270  public function checkCommandAccess(
271  string $permission,
272  string $cmd,
273  int $ref_id,
274  string $type,
275  ?int $obj_id = null
276  ): bool {
277  $this->updateContext();
278 
279  $this->capability_context = $this->capability_context
280  ->withCallingId($ref_id)
281  ->withObjectId($obj_id ?? $this->capability_context->getObjectId());
282 
283  // LP settings only in repository
284  if ($this->context !== self::CONTEXT_REPOSITORY && $permission === "edit_learning_progress") {
285  return false;
286  }
287 
288  $this->capabilities = $this->capability_builder->get($this->capability_context);
289 
290  $capability = Capabilities::fromCommand($cmd);
291  $additional_check = $this->capabilities->get($capability)->isUnlocked();
292 
293  return $additional_check && parent::checkCommandAccess(
294  $permission,
295  $cmd,
296  $ref_id,
297  $type,
298  $obj_id
299  );
300  }
301 
302 
303 }
getIconImageType()
Returns the icon image type.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
const OBJECT_TYPE
static _getCommands()
get commands this method returns an array of all possible commands/permission combinations example: $...
const IL_CAL_UNIX
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
string $key
Consumer key/client ID value.
Definition: System.php:193
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.
IconDatabaseRepository $icon_repo
stripTitleOfFileExtension(string $a_title)
$version
Definition: plugin.php:24
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)