ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
CapabilityBuilder.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
37
42{
43 protected array $cache = [];
47 private array $checks = [];
48
49 public function __construct(
50 private readonly \ilObjFileInfoRepository $file_info_repository,
51 private readonly \ilAccessHandler $access,
52 private readonly \ilCtrlInterface $ctrl,
53 private readonly ActionRepository $action_repository,
54 private readonly Services $http,
55 private readonly URIBuilder $static_url,
56 private readonly TypeResolver $type_resolver = new CoreTypeResolver(),
57 private readonly \ilWorkspaceAccessHandler $workspace_access_handler = new \ilWorkspaceAccessHandler()
58 ) {
59 $this->checks = [
60 new ForcedInfo(),
61 new Download(),
62 new Edit(),
63 new EditContent(),
64 new Info(),
65 new Manage(),
66 new None(),
67 new Unzip(),
68 new ViewContent(),
69 ];
70 }
71
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->static_url,
106 $this->workspace_access_handler
107 );
108
109 $calling_id = $context->getCallingId();
110
111 if ($calling_id > 0) {
112 $this->ctrl->setParameterByClass(\ilObjFileGUI::class, 'ref_id', $calling_id);
113 }
114
115 foreach ($capabilities as $capability) {
116 foreach ($this->checks as $check) {
117 if ($check->canUnlock() === $capability->getCapability()) {
118 $capability = $check->maybeUnlock($capability, $helpers, $info, $context);
119 $capability = $check->maybeBuildURI($capability, $helpers, $context);
120 }
121 }
122 }
123 return $this->cache[$context->getNode()] = new CapabilityCollection($capabilities);
124 }
125
126}
$check
Definition: buildRTE.php:81
__construct(private readonly \ilObjFileInfoRepository $file_info_repository, private readonly \ilAccessHandler $access, private readonly \ilCtrlInterface $ctrl, private readonly ActionRepository $action_repository, private readonly Services $http, private readonly URIBuilder $static_url, private readonly TypeResolver $type_resolver=new CoreTypeResolver(), private readonly \ilWorkspaceAccessHandler $workspace_access_handler=new \ilWorkspaceAccessHandler())
Class Services.
Definition: Services.php:38
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$http
Definition: deliver.php:30
$info
Definition: entry_point.php:21
$static_url
Definition: goto.php:29
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$context
Definition: webdav.php:31