ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
CopyrightHandler.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 
27 {
29 
33  protected array $entries;
34 
38  protected array $statuses = [];
39 
40  public function __construct(RepositoryInterface $repository)
41  {
42  $this->repository = $repository;
43  }
44 
45  public function isCPSelectionActive(): bool
46  {
48  return $settings->isCopyrightSelectionActive() && $this->hasCPEntries();
49  }
50 
52  {
53  return \ilOerHarvesterSettings::getInstance();
54  }
55 
56  public function doesObjectTypeSupportHarvesting(string $type): bool
57  {
58  return $this->getOerHarvesterSettings()->supportsHarvesting($type);
59  }
60 
61  public function isCopyrightTemplateActive(EntryInterface $entry): bool
62  {
63  return $this->getOerHarvesterSettings()->isActiveCopyrightTemplate($entry->id());
64  }
65 
66  protected function hasCPEntries(): bool
67  {
68  $this->initCPEntries();
69  return !empty($this->entries);
70  }
71 
75  public function getCPEntries(): \Generator
76  {
77  $this->initCPEntries();
78  yield from $this->entries;
79  }
80 
81  protected function initCPEntries(): void
82  {
83  if (!isset($this->entries)) {
84  $this->entries = iterator_to_array($this->repository->getAllEntries());
85  }
86  }
87 
88  public function extractCPEntryID(string $description): int
89  {
90  return \ilMDCopyrightSelectionEntry::_extractEntryId($description);
91  }
92 
93  public function createIdentifierForID(int $entry_id): string
94  {
95  return \ilMDCopyrightSelectionEntry::createIdentifier($entry_id);
96  }
97 
98  public function isOerHarvesterBlocked(int $obj_id): bool
99  {
100  $status = $this->getHarvesterStatus($obj_id);
101  return $status->isBlocked();
102  }
103 
104  public function setOerHarvesterBlocked(
105  int $obj_id,
106  bool $is_blocked
107  ): void {
108  $status = $this->getHarvesterStatus($obj_id);
109  $status->setBlocked($is_blocked);
110  $status->save();
111  }
112 
113  protected function getHarvesterStatus(int $obj_id): \ilOerHarvesterObjectStatus
114  {
115  if (isset($this->statuses[$obj_id])) {
116  return $this->statuses[$obj_id];
117  }
118  return $this->statuses[$obj_id] = new \ilOerHarvesterObjectStatus($obj_id);
119  }
120 }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
__construct(RepositoryInterface $repository)
Cron job for definition for oer harvesting.
setOerHarvesterBlocked(int $obj_id, bool $is_blocked)