ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
StateInfoFetcher.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ilAccess;
28use ILIAS\MetaData\Copyright\Identifiers\HandlerInterface as CopyrightIdentifierHandler;
33
35{
36 public function __construct(
37 protected ilAccess $access,
38 protected ExposedRecordsRepository $exposed_repo,
39 protected ResourceStatusRepository $status_repo,
40 protected PublishingSettings $publishing_settings,
41 protected RepoObjectHandler $repo_object_handler,
42 protected CopyrightIdentifierHandler $copyright_identifier_handler,
43 protected PublisherInterface $state_changer,
44 protected RepositoryInterface $repository,
45 protected NavigatorFactoryInterface $navigator_factory,
46 protected PathFactory $path_factory
47 ) {
48 }
49
51 int $ref_id,
52 int $obj_id,
53 string $type
55 $is_publishing_relevant = $this->isPublishingRelevantForObject($ref_id, $type, $obj_id);
56 if (!$is_publishing_relevant) {
57 return new StateInfo(false, Status::UNPUBLISHED, [], [], [], []);
58 }
59 $current_status = $this->getStatusForObject($obj_id);
60 $relevant_actions = $this->getRelevantActions($current_status, $ref_id);
61 $eligible_copyright_entry_ids = $this->getEligibleCopyrightEntryIDs();
62 return new StateInfo(
63 true,
64 $current_status,
66 $relevant_actions,
67 $this->getUnavailableActions($ref_id, $type, $obj_id, $relevant_actions, $eligible_copyright_entry_ids),
68 $eligible_copyright_entry_ids
69 );
70 }
71
72 public function isPublishingRelevantForObject(int $ref_id, string $type, int $obj_id): bool
73 {
74 return $this->access->checkAccess('write', '', $ref_id, $type, $obj_id) &&
75 (
76 $this->publishing_settings->isManualPublishingEnabled() ||
77 $this->publishing_settings->isAutomaticPublishingEnabled()
78 ) &&
79 in_array($type, $this->publishing_settings->getObjectTypesEligibleForPublishing());
80 }
81
82 public function getStatusForObject(int $obj_id): Status
83 {
84 if ($this->exposed_repo->doesUndeletedRecordExistForObjID($obj_id)) {
85 return Status::PUBLISHED;
86 }
87 if ($this->status_repo->isAlreadyHarvested($obj_id)) {
88 return Status::UNDER_REVIEW;
89 }
90 if ($this->status_repo->isHarvestingBlocked($obj_id)) {
91 return Status::BLOCKED;
92 }
93 return Status::UNPUBLISHED;
94 }
95
99 protected function getAllPossibleStatuses(): array
100 {
101 $statuses = [Status::UNPUBLISHED];
102 if ($this->publishing_settings->isAutomaticPublishingEnabled()) {
103 $statuses[] = Status::BLOCKED;
104 }
105 if ($this->publishing_settings->isEditorialStepEnabled()) {
106 $statuses[] = Status::UNDER_REVIEW;
107 }
108 $statuses[] = Status::PUBLISHED;
109 return $statuses;
110 }
111
112
116 protected function getRelevantActions(Status $status, int $ref_id): array
117 {
118 $actions = [];
119 switch ($status) {
120 case Status::UNPUBLISHED:
121 if ($this->publishing_settings->isAutomaticPublishingEnabled()) {
122 $actions[] = Action::BLOCK;
123 }
124 if (!$this->publishing_settings->isManualPublishingEnabled()) {
125 break;
126 }
127 if ($this->publishing_settings->isEditorialStepEnabled()) {
128 $actions[] = Action::SUBMIT;
129 } else {
130 $actions[] = Action::PUBLISH;
131 }
132 break;
133
134 case Status::BLOCKED:
135 $actions[] = Action::UNBLOCK;
136 break;
137
138 case Status::UNDER_REVIEW:
139 if ($this->isReferenceInEditorialCategory($ref_id)) {
140 $actions[] = Action::ACCEPT;
141 $actions[] = Action::REJECT;
142 } else {
143 $actions[] = Action::WITHDRAW;
144 }
145 break;
146
148 $actions[] = Action::WITHDRAW;
149 }
150 return $actions;
151 }
152
153 protected function isReferenceInEditorialCategory(int $ref_id): bool
154 {
155 if (!$this->publishing_settings->isEditorialStepEnabled()) {
156 return false;
157 }
158 return $this->repo_object_handler->isReferenceInContainer(
159 $ref_id,
160 $this->publishing_settings->getContainerRefIDForEditorialStep()
161 );
162 }
163
167 protected function getEligibleCopyrightEntryIDs(): array
168 {
169 return $this->publishing_settings->getCopyrightEntryIDsSelectedForPublishing();
170 }
171
177 protected function getUnavailableActions(
178 int $ref_id,
179 string $type,
180 int $obj_id,
181 array $relevant_actions,
182 array $eligible_copyright_entry_ids
183 ): array {
184 $unavailable_actions = [];
185 foreach ($relevant_actions as $action) {
186 $available = match ($action) {
187 Action::BLOCK => $this->state_changer->checkPermissionsForBlock($ref_id, $type, $obj_id),
188 Action::UNBLOCK => $this->state_changer->checkPermissionsForUnblock($ref_id, $type, $obj_id),
189 Action::PUBLISH =>
190 $this->state_changer->checkPermissionsForPublish($ref_id, $type, $obj_id) &&
191 $this->isCopyrightEligibleForPublishing($obj_id, $type, $eligible_copyright_entry_ids),
192 Action::WITHDRAW => $this->state_changer->checkPermissionsForWithdraw($ref_id, $type, $obj_id),
193 Action::SUBMIT =>
194 $this->state_changer->checkPermissionsForSubmit($ref_id, $type, $obj_id) &&
195 $this->isCopyrightEligibleForPublishing($obj_id, $type, $eligible_copyright_entry_ids),
196 Action::ACCEPT => $this->state_changer->checkPermissionsForAccept($ref_id, $type, $obj_id),
197 Action::REJECT => $this->state_changer->checkPermissionsForReject($ref_id, $type, $obj_id),
198 };
199 if (!$available) {
200 $unavailable_actions[] = $action;
201 }
202 }
203 return $unavailable_actions;
204 }
205
207 int $obj_id,
208 string $type,
209 array $eligible_copyright_entry_ids
210 ): bool {
211 $copyright_path = $this->path_factory
212 ->custom()
213 ->withNextStep('rights')
214 ->withNextStep('description')
215 ->withNextStep('string')
216 ->get();
217 $set = $this->repository->getMD($obj_id, $obj_id, $type);
218 $copyright_string = $this->navigator_factory->navigator($copyright_path, $set->getRoot())
219 ->lastElementAtFinalStep()
220 ?->getData()
221 ?->value() ?? '';
222 if (!$this->copyright_identifier_handler->isIdentifierValid($copyright_string)) {
223 return false;
224 }
225 $entry_id = $this->copyright_identifier_handler->parseEntryIDFromIdentifier($copyright_string);
226 if (!in_array($entry_id, $eligible_copyright_entry_ids)) {
227 return false;
228 }
229 return true;
230 }
231}
getUnavailableActions(int $ref_id, string $type, int $obj_id, array $relevant_actions, array $eligible_copyright_entry_ids)
isPublishingRelevantForObject(int $ref_id, string $type, int $obj_id)
isCopyrightEligibleForPublishing(int $obj_id, string $type, array $eligible_copyright_entry_ids)
getStateInfoForObjectReference(int $ref_id, int $obj_id, string $type)
__construct(protected ilAccess $access, protected ExposedRecordsRepository $exposed_repo, protected ResourceStatusRepository $status_repo, protected PublishingSettings $publishing_settings, protected RepoObjectHandler $repo_object_handler, protected CopyrightIdentifierHandler $copyright_identifier_handler, protected PublisherInterface $state_changer, protected RepositoryInterface $repository, protected NavigatorFactoryInterface $navigator_factory, protected PathFactory $path_factory)
Class ilAccessHandler Checks access for ILIAS objects.
$ref_id
Definition: ltiauth.php:66
get(string $class_name)