ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
CapabilityBuilder.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\File\Capabilities;
22 
36 
41 {
42  protected array $cache = [];
46  private array $checks = [];
47 
48  public function __construct(
49  private \ilObjFileInfoRepository $file_info_repository,
50  private \ilAccessHandler $access,
51  private \ilCtrlInterface $ctrl,
52  private ActionRepository $action_repository,
53  private Services $http,
54  private ?TypeResolver $type_resolver = null,
55  private ?\ilWorkspaceAccessHandler $workspace_access_handler = null
56  ) {
57  $this->checks = [
58  new ForcedInfo(),
59  new Download(),
60  new Edit(),
61  new EditContent(),
62  new Info(),
63  new Manage(),
64  new None(),
65  new Unzip(),
66  new ViewContent(),
67  ];
68  $this->type_resolver = $this->type_resolver ?? new CoreTypeResolver();
69  $this->workspace_access_handler = $this->workspace_access_handler ?? new \ilWorkspaceAccessHandler();
70  }
71 
72  public function get(Context $context): CapabilityCollection
73  {
74  if (isset($this->cache[$context->getNode()])) {
75  return $this->cache[$context->getNode()];
76  }
77 
83  $capabilities = [
84  new Capability(Capabilities::FORCED_INFO_PAGE, ...Permissions::ANY()),
85  new Capability(Capabilities::VIEW_EXTERNAL, Permissions::VIEW_CONTENT),
86  new Capability(Capabilities::EDIT_EXTERNAL, Permissions::EDIT_CONTENT),
87  new Capability(Capabilities::DOWNLOAD, Permissions::READ),
88  new Capability(Capabilities::MANAGE_VERSIONS, Permissions::WRITE),
89  new Capability(Capabilities::EDIT_SETTINGS, Permissions::WRITE),
90  new Capability(Capabilities::INFO_PAGE, ...Permissions::ANY()),
91  new Capability(Capabilities::NONE, Permissions::NONE),
92  new Capability(Capabilities::UNZIP, Permissions::WRITE),
93  ];
94 
95  if ($this->type_resolver->resolveTypeByObjectId($context->getObjectId()) !== 'file') {
96  return new CapabilityCollection($capabilities);
97  }
98 
99  $info = $this->file_info_repository->getByObjectId($context->getObjectId());
100  $helpers = new CheckHelpers(
101  $this->access,
102  $this->ctrl,
103  $this->action_repository,
104  $this->http,
105  $this->workspace_access_handler
106  );
107 
108  $calling_id = $context->getCallingId();
109 
110  if ($calling_id > 0) {
111  $this->ctrl->setParameterByClass(\ilObjFileGUI::class, 'ref_id', $calling_id);
112  }
113 
114  foreach ($capabilities as $capability) {
115  foreach ($this->checks as $check) {
116  if ($check->canUnlock() === $capability->getCapability()) {
117  $capability = $check->maybeUnlock($capability, $helpers, $info, $context);
118  $capability = $check->maybeBuildURI($capability, $helpers, $context);
119  }
120  }
121  }
122  return $this->cache[$context->getNode()] = new CapabilityCollection($capabilities);
123  }
124 
125 }
$context
Definition: webdav.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(private \ilObjFileInfoRepository $file_info_repository, private \ilAccessHandler $access, private \ilCtrlInterface $ctrl, private ActionRepository $action_repository, private Services $http, private ?TypeResolver $type_resolver=null, private ?\ilWorkspaceAccessHandler $workspace_access_handler=null)
static http()
Fetches the global http state from ILIAS.
$http
Definition: raiseError.php:7
$check
Definition: buildRTE.php:81