ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
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, [], [], [], [], false);
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 $is_copyright_eligible = $this->isCopyrightEligibleForPublishing($obj_id, $type, $eligible_copyright_entry_ids);
63 return new StateInfo(
64 true,
65 $current_status,
67 $relevant_actions,
68 $this->getUnavailableActions($ref_id, $type, $obj_id, $relevant_actions, $is_copyright_eligible),
69 $eligible_copyright_entry_ids,
70 $is_copyright_eligible
71 );
72 }
73
74 public function isPublishingRelevantForObject(int $ref_id, string $type, int $obj_id): bool
75 {
76 return $this->access->checkAccess('write', '', $ref_id, $type, $obj_id) &&
77 (
78 $this->publishing_settings->isManualPublishingEnabled() ||
79 $this->publishing_settings->isAutomaticPublishingEnabled()
80 ) &&
81 in_array($type, $this->publishing_settings->getObjectTypesEligibleForPublishing());
82 }
83
84 public function getStatusForObject(int $obj_id): Status
85 {
86 if ($this->exposed_repo->doesUndeletedRecordExistForObjID($obj_id)) {
87 return Status::PUBLISHED;
88 }
89 if ($this->status_repo->isAlreadyHarvested($obj_id)) {
90 return Status::UNDER_REVIEW;
91 }
92 if ($this->status_repo->isHarvestingBlocked($obj_id)) {
93 return Status::BLOCKED;
94 }
95 return Status::UNPUBLISHED;
96 }
97
101 protected function getAllPossibleStatuses(): array
102 {
103 $statuses = [Status::UNPUBLISHED];
104 if ($this->publishing_settings->isAutomaticPublishingEnabled()) {
105 $statuses[] = Status::BLOCKED;
106 }
107 if ($this->publishing_settings->isEditorialStepEnabled()) {
108 $statuses[] = Status::UNDER_REVIEW;
109 }
110 $statuses[] = Status::PUBLISHED;
111 return $statuses;
112 }
113
114
118 protected function getRelevantActions(Status $status, int $ref_id): array
119 {
120 $actions = [];
121 switch ($status) {
122 case Status::UNPUBLISHED:
123 if ($this->publishing_settings->isAutomaticPublishingEnabled()) {
124 $actions[] = Action::BLOCK;
125 }
126 if (!$this->publishing_settings->isManualPublishingEnabled()) {
127 break;
128 }
129 if ($this->publishing_settings->isEditorialStepEnabled()) {
130 $actions[] = Action::SUBMIT;
131 } else {
132 $actions[] = Action::PUBLISH;
133 }
134 break;
135
136 case Status::BLOCKED:
137 $actions[] = Action::UNBLOCK;
138 break;
139
140 case Status::UNDER_REVIEW:
141 if ($this->isReferenceInEditorialCategory($ref_id)) {
142 $actions[] = Action::ACCEPT;
143 $actions[] = Action::REJECT;
144 } else {
145 $actions[] = Action::WITHDRAW;
146 }
147 break;
148
150 $actions[] = Action::WITHDRAW;
151 }
152 return $actions;
153 }
154
155 protected function isReferenceInEditorialCategory(int $ref_id): bool
156 {
157 if (!$this->publishing_settings->isEditorialStepEnabled()) {
158 return false;
159 }
160 return $this->repo_object_handler->isReferenceInContainer(
161 $ref_id,
162 $this->publishing_settings->getContainerRefIDForEditorialStep()
163 );
164 }
165
169 protected function getEligibleCopyrightEntryIDs(): array
170 {
171 return $this->publishing_settings->getCopyrightEntryIDsSelectedForPublishing();
172 }
173
179 protected function getUnavailableActions(
180 int $ref_id,
181 string $type,
182 int $obj_id,
183 array $relevant_actions,
184 bool $is_copyright_eligible
185 ): array {
186 $unavailable_actions = [];
187 foreach ($relevant_actions as $action) {
188 $available = match ($action) {
189 Action::BLOCK => $this->state_changer->checkPermissionsForBlock($ref_id, $type, $obj_id),
190 Action::UNBLOCK => $this->state_changer->checkPermissionsForUnblock($ref_id, $type, $obj_id),
191 Action::PUBLISH =>
192 $this->state_changer->checkPermissionsForPublish($ref_id, $type, $obj_id) &&
193 $is_copyright_eligible,
194 Action::WITHDRAW => $this->state_changer->checkPermissionsForWithdraw($ref_id, $type, $obj_id),
195 Action::SUBMIT =>
196 $this->state_changer->checkPermissionsForSubmit($ref_id, $type, $obj_id) &&
197 $is_copyright_eligible,
198 Action::ACCEPT => $this->state_changer->checkPermissionsForAccept($ref_id, $type, $obj_id),
199 Action::REJECT => $this->state_changer->checkPermissionsForReject($ref_id, $type, $obj_id),
200 };
201 if (!$available) {
202 $unavailable_actions[] = $action;
203 }
204 }
205 return $unavailable_actions;
206 }
207
209 int $obj_id,
210 string $type,
211 array $eligible_copyright_entry_ids
212 ): bool {
213 $copyright_path = $this->path_factory
214 ->custom()
215 ->withNextStep('rights')
216 ->withNextStep('description')
217 ->withNextStep('string')
218 ->get();
219 $set = $this->repository->getMD($obj_id, $obj_id, $type);
220 $copyright_string = $this->navigator_factory->navigator($copyright_path, $set->getRoot())
221 ->lastElementAtFinalStep()
222 ?->getData()
223 ?->value() ?? '';
224 if (!$this->copyright_identifier_handler->isIdentifierValid($copyright_string)) {
225 return false;
226 }
227 $entry_id = $this->copyright_identifier_handler->parseEntryIDFromIdentifier($copyright_string);
228 if (!in_array($entry_id, $eligible_copyright_entry_ids)) {
229 return false;
230 }
231 return true;
232 }
233}
isPublishingRelevantForObject(int $ref_id, string $type, int $obj_id)
getUnavailableActions(int $ref_id, string $type, int $obj_id, array $relevant_actions, bool $is_copyright_eligible)
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)