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