ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilCronOerHarvester.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 
33 {
34  protected const string CRON_JOB_IDENTIFIER = 'meta_oer_harvester';
35  protected const int DEFAULT_SCHEDULE_VALUE = 1;
36 
37  private ilLogger $logger;
38  private ilLanguage $lng;
41 
42  public function __construct()
43  {
44  global $DIC;
45 
46  $this->logger = $DIC->logger()->meta();
47  $this->lng = $DIC->language();
48  $this->lng->loadLanguageModule('meta');
49 
50  $this->initiator = new Initiator($DIC);
51  $this->settings = $this->initiator->settings();
52  }
53 
54  public function getTitle(): string
55  {
56  return $this->lng->txt('meta_oer_harvester');
57  }
58 
59  public function getDescription(): string
60  {
61  return $this->lng->txt('meta_oer_harvester_desc');
62  }
63 
64  public function getId(): string
65  {
66  return self::CRON_JOB_IDENTIFIER;
67  }
68 
69  public function hasAutoActivation(): bool
70  {
71  return false;
72  }
73 
74  public function hasFlexibleSchedule(): bool
75  {
76  return true;
77  }
78 
80  {
81  return JobScheduleType::DAILY;
82  }
83 
84  public function getDefaultScheduleValue(): ?int
85  {
86  return self::DEFAULT_SCHEDULE_VALUE;
87  }
88 
89  public function hasCustomSettings(): bool
90  {
91  return true;
92  }
93 
94  public function addCustomSettingsToForm(ilPropertyFormGUI $a_form): void
95  {
96  // target selection
97  $header = new ilFormSectionHeaderGUI();
98  $header->setTitle($this->lng->txt('meta_oer_categories'));
99  $a_form->addItem($header);
100 
101  $target = new ilRepositorySelector2InputGUI(
102  $this->lng->txt('meta_oer_target'),
103  'target',
104  false,
105  $a_form
106  );
107 
108  $explorer = $target->getExplorerGUI();
109  $explorer->setRootId(ROOT_FOLDER_ID);
110  $explorer->setTypeWhiteList(['cat']);
111 
112  $target_ref_id = $this->settings->getContainerRefIDForHarvesting();
113  if ($target_ref_id) {
114  $explorer->setPathOpen($target_ref_id);
115  $target->setValue($target_ref_id);
116  }
117 
118  $target->setRequired(true);
119  $a_form->addItem($target);
120 
121  // source for exposing
122  $ex_target = new ilRepositorySelector2InputGUI(
123  $this->lng->txt('meta_oer_exposed_source'),
124  'exposed_source',
125  false,
126  $a_form
127  );
128 
129  $ex_explorer = $ex_target->getExplorerGUI();
130  $ex_explorer->setRootId(ROOT_FOLDER_ID);
131  $ex_explorer->setTypeWhiteList(['cat']);
132 
133  $ex_target_ref_id = $this->settings->getContainerRefIDForExposing();
134  if ($ex_target_ref_id) {
135  $ex_explorer->setPathOpen($ex_target_ref_id);
136  $ex_target->setValue($ex_target_ref_id);
137  }
138 
139  $ex_target->setRequired(true);
140  $a_form->addItem($ex_target);
141 
142  // copyright selection
143  $header = new ilFormSectionHeaderGUI();
144  $header->setTitle($this->lng->txt('meta_oer_harvested_licences'));
145  $a_form->addItem($header);
146 
147  $checkbox_group = new ilCheckboxGroupInputGUI(
148  $this->lng->txt('meta_oer_copyright_selection'),
149  'copyright'
150  );
151  $checkbox_group->setRequired(true);
152  $checkbox_group->setValue($this->settings->getCopyrightEntryIDsSelectedForHarvesting());
153  $checkbox_group->setInfo(
154  $this->lng->txt('meta_oer_copyright_selection_info')
155  );
156 
157  foreach ($this->initiator->copyrightRepository()->getAllEntries() as $copyright_entry) {
158  $copyright_checkox = new ilCheckboxOption(
159  $copyright_entry->title(),
160  (string) $copyright_entry->id(),
161  $copyright_entry->description()
162  );
163  $checkbox_group->addOption($copyright_checkox);
164  }
165  $a_form->addItem($checkbox_group);
166 
167  // object type selection
168  $header = new ilFormSectionHeaderGUI();
169  $header->setTitle($this->lng->txt('meta_oer_harvested_types'));
170  $a_form->addItem($header);
171 
172  $checkbox_group = new ilCheckboxGroupInputGUI(
173  $this->lng->txt('meta_oer_object_type_selection'),
174  'object_type'
175  );
176  $checkbox_group->setRequired(true);
177  $checkbox_group->setValue($this->settings->getObjectTypesSelectedForHarvesting());
178 
179  foreach ($this->settings->getObjectTypesEligibleForHarvesting() as $type) {
180  $copyright_checkox = new ilCheckboxOption(
181  $this->lng->txt('objs_' . $type),
182  $type
183  );
184  $checkbox_group->addOption($copyright_checkox);
185  }
186  $a_form->addItem($checkbox_group);
187  }
188 
189  public function saveCustomSettings(ilPropertyFormGUI $a_form): bool
190  {
191  $copyrights = [];
192  foreach ($a_form->getInput('copyright') as $id) {
193  $copyrights[] = (int) $id;
194  }
195 
196  $this->settings->saveContainerRefIDForHarvesting((int) $a_form->getInput('target'));
197  $this->settings->saveContainerRefIDForExposing((int) $a_form->getInput('exposed_source'));
198  $this->settings->saveCopyrightEntryIDsSelectedForHarvesting(...$copyrights);
199  $this->settings->saveObjectTypesSelectedForHarvesting(...$a_form->getInput('object_type'));
200  return true;
201  }
202 
203  public function run(): JobResult
204  {
205  $this->logger->info('Started cron oer harvester.');
206  $harvester = $this->initiator->harvester();
207  $res = $harvester->run(new ResultWrapper(new JobResult()));
208  $this->logger->info('cron oer harvester finished');
209 
210  return $res->get();
211  }
212 
213  public function addToExternalSettingsForm(int $a_form_id, array &$a_fields, bool $a_is_active): void
214  {
215  switch ($a_form_id) {
217 
218  $a_fields['meta_oer_harvester'] =
219  (
220  $a_is_active ?
221  $this->lng->txt('enabled') :
222  $this->lng->txt('disabled')
223  );
224  break;
225  }
226  }
227 }
$res
Definition: ltiservices.php:66
This class represents an option in a checkbox group.
addCustomSettingsToForm(ilPropertyFormGUI $a_form)
const ROOT_FOLDER_ID
Definition: constants.php:32
Cron job for definition for oer harvesting.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
global $DIC
Definition: shib_login.php:22
addToExternalSettingsForm(int $a_form_id, array &$a_fields, bool $a_is_active)
This class represents a property in a property form.
saveCustomSettings(ilPropertyFormGUI $a_form)
setRequired(bool $a_required)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23