ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
CopyrightHandler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\MetaData\Copyright\RepositoryInterface as CopyrightRepository;
29
31{
32 protected CopyrightRepository $repository;
33 protected Settings $settings;
34 protected OERHarvesterSettings $harvester_settings;
35 protected HarvestStatusRepository $harvest_status_repo;
36 protected CopyrightIDHandler $copyright_id_handler;
37
41 protected array $entries;
42
43 public function __construct(
44 CopyrightRepository $repository,
45 Settings $settings,
46 OERHarvesterSettings $harvester_settings,
47 HarvestStatusRepository $harvest_status_repo,
48 CopyrightIDHandler $copyright_id_handler
49 ) {
50 $this->repository = $repository;
51 $this->settings = $settings;
52 $this->harvester_settings = $harvester_settings;
53 $this->harvest_status_repo = $harvest_status_repo;
54 $this->copyright_id_handler = $copyright_id_handler;
55 }
56
57 public function isCPSelectionActive(): bool
58 {
59 return $this->settings->isCopyrightSelectionActive() && $this->hasCPEntries();
60 }
61
62 public function isObjectTypeHarvested(string $type): bool
63 {
64 return $this->harvester_settings->isObjectTypeSelectedForHarvesting($type);
65 }
66
67 public function isCopyrightTemplateActive(EntryInterface $entry): bool
68 {
69 return $this->harvester_settings->isCopyrightEntryIDSelectedForHarvesting($entry->id());
70 }
71
72 protected function hasCPEntries(): bool
73 {
74 $this->initCPEntries();
75 return !empty($this->entries);
76 }
77
81 public function getCPEntries(): \Generator
82 {
83 $this->initCPEntries();
84 yield from $this->entries;
85 }
86
87 protected function initCPEntries(): void
88 {
89 if (!isset($this->entries)) {
90 $this->entries = iterator_to_array($this->repository->getAllEntries());
91 }
92 }
93
94 public function extractCPEntryID(string $description): int
95 {
96 return $this->copyright_id_handler->parseEntryIDFromIdentifier($description);
97 }
98
99 public function createIdentifierForID(int $entry_id): string
100 {
101 return $this->copyright_id_handler->buildIdentifierFromEntryID($entry_id);
102 }
103
104 public function isOerHarvesterBlocked(int $obj_id): bool
105 {
106 return $this->harvest_status_repo->isHarvestingBlocked($obj_id);
107 }
108
109 public function setOerHarvesterBlocked(
110 int $obj_id,
111 bool $is_blocked
112 ): void {
113 $this->harvest_status_repo->setHarvestingBlocked($obj_id, $is_blocked);
114 }
115}
setOerHarvesterBlocked(int $obj_id, bool $is_blocked)
__construct(CopyrightRepository $repository, Settings $settings, OERHarvesterSettings $harvester_settings, HarvestStatusRepository $harvest_status_repo, CopyrightIDHandler $copyright_id_handler)