ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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->setValue($this->settings->getCopyrightEntryIDsSelectedForHarvesting());
152  $checkbox_group->setInfo(
153  $this->lng->txt('meta_oer_copyright_selection_info')
154  );
155 
156  foreach ($this->initiator->copyrightRepository()->getAllEntries() as $copyright_entry) {
157  $copyright_checkox = new ilCheckboxOption(
158  $copyright_entry->title(),
159  (string) $copyright_entry->id(),
160  $copyright_entry->description()
161  );
162  $checkbox_group->addOption($copyright_checkox);
163  }
164  $a_form->addItem($checkbox_group);
165 
166  // object type selection
167  $header = new ilFormSectionHeaderGUI();
168  $header->setTitle($this->lng->txt('meta_oer_harvested_types'));
169  $a_form->addItem($header);
170 
171  $checkbox_group = new ilCheckboxGroupInputGUI(
172  $this->lng->txt('meta_oer_object_type_selection'),
173  'object_type'
174  );
175  $checkbox_group->setRequired(true);
176  $checkbox_group->setValue($this->settings->getObjectTypesSelectedForHarvesting());
177 
178  foreach ($this->settings->getObjectTypesEligibleForHarvesting() as $type) {
179  $type_checkox = new ilCheckboxOption(
180  $this->lng->txt('objs_' . $type),
181  $type
182  );
183  $checkbox_group->addOption($type_checkox);
184  }
185  $a_form->addItem($checkbox_group);
186  }
187 
188  public function saveCustomSettings(ilPropertyFormGUI $a_form): bool
189  {
190  $copyrights = [];
191  foreach ($a_form->getInput('copyright') as $id) {
192  $copyrights[] = (int) $id;
193  }
194 
195  $this->settings->saveContainerRefIDForHarvesting((int) $a_form->getInput('target'));
196  $this->settings->saveContainerRefIDForExposing((int) $a_form->getInput('exposed_source'));
197  $this->settings->saveCopyrightEntryIDsSelectedForHarvesting(...$copyrights);
198  $this->settings->saveObjectTypesSelectedForHarvesting(...$a_form->getInput('object_type'));
199  return true;
200  }
201 
202  public function run(): JobResult
203  {
204  $this->logger->info('Started cron oer harvester.');
205  $harvester = $this->initiator->harvester();
206  $res = $harvester->run(new ResultWrapper(new JobResult()));
207  $this->logger->info('cron oer harvester finished');
208 
209  return $res->get();
210  }
211 
212  public function addToExternalSettingsForm(int $a_form_id, array &$a_fields, bool $a_is_active): void
213  {
214  switch ($a_form_id) {
216 
217  $a_fields['meta_oer_harvester'] =
218  (
219  $a_is_active ?
220  $this->lng->txt('enabled') :
221  $this->lng->txt('disabled')
222  );
223  break;
224  }
225  }
226 }
$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:26
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