ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilCronOerHarvester.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
6 
8 
14 {
15  public const CRON_JOB_IDENTIFIER = 'meta_oer_harvester';
16  public const DEFAULT_SCHEDULE_VALUE = 1;
17 
18  private ilLogger $logger;
19  private ilLanguage $lng;
20 
22 
23  public function __construct()
24  {
25  global $DIC;
26 
27  $this->logger = $DIC->logger()->meta();
28  $this->lng = $DIC->language();
29  $this->lng->loadLanguageModule('meta');
30 
32  }
33 
34  public function getTitle(): string
35  {
36  return $this->lng->txt('meta_oer_harvester');
37  }
38 
39  public function getDescription(): string
40  {
41  return $this->lng->txt('meta_oer_harvester_desc');
42  }
43 
44  public function getId(): string
45  {
46  return self::CRON_JOB_IDENTIFIER;
47  }
48 
49  public function hasAutoActivation(): bool
50  {
51  return false;
52  }
53 
54  public function hasFlexibleSchedule(): bool
55  {
56  return true;
57  }
58 
60  {
61  return CronJobScheduleType::SCHEDULE_TYPE_DAILY;
62  }
63 
64  public function getDefaultScheduleValue(): ?int
65  {
66  return self::DEFAULT_SCHEDULE_VALUE;
67  }
68 
69  public function hasCustomSettings(): bool
70  {
71  return true;
72  }
73 
74  public function addCustomSettingsToForm(ilPropertyFormGUI $a_form): void
75  {
76  // target selection
77  $target = new ilRepositorySelector2InputGUI(
78  $this->lng->txt('meta_oer_target'),
79  'target',
80  false,
81  $a_form
82  );
83 
84  $explorer = $target->getExplorerGUI();
85  $explorer->setSelectMode('target', false);
86  $explorer->setRootId(ROOT_FOLDER_ID);
87  $explorer->setTypeWhiteList(['cat']);
88 
89  if ($this->settings->getTarget()) {
90  $explorer->setPathOpen($this->settings->getTarget());
91  $target->setValue($this->settings->getTarget());
92  }
93 
94  $target->setRequired(true);
95  $a_form->addItem($target);
96 
97  // copyright selection
98  $checkbox_group = new ilCheckboxGroupInputGUI(
99  $this->lng->txt('meta_oer_copyright_selection'),
100  'copyright'
101  );
102  $checkbox_group->setValue($this->settings->getCopyrightTemplates());
103  $checkbox_group->setInfo(
104  $this->lng->txt('meta_oer_copyright_selection_info')
105  );
106 
107  foreach (ilMDCopyrightSelectionEntry::_getEntries() as $copyright_entry) {
108  $copyright_checkox = new ilCheckboxOption(
109  $copyright_entry->getTitle(),
110  (string) $copyright_entry->getEntryId(),
111  $copyright_entry->getDescription()
112  );
113  $checkbox_group->addOption($copyright_checkox);
114  }
115  $a_form->addItem($checkbox_group);
116  }
117 
118  public function saveCustomSettings(ilPropertyFormGUI $a_form): bool
119  {
120  $this->settings->setTarget((int) $a_form->getInput('target'));
121  $this->settings->setCopyrightTemplates($a_form->getInput('copyright'));
122  $this->settings->save();
123 
124  return true;
125  }
126 
127  public function run(): ilCronJobResult
128  {
129  $this->logger->info('Started cron oer harvester.');
130  $harvester = new ilOerHarvester(new ilCronJobResult());
131  $res = $harvester->run();
132  $this->logger->info('cron oer harvester finished');
133 
134  return $res;
135  }
136 
137  public function addToExternalSettingsForm(int $a_form_id, array &$a_fields, bool $a_is_active): void
138  {
139  switch ($a_form_id) {
141 
142  $a_fields['meta_oer_harvester'] =
143  (
144  $a_is_active ?
145  $this->lng->txt('enabled') :
146  $this->lng->txt('disabled')
147  );
148  break;
149  }
150  }
151 }
ilOerHarvesterSettings $settings
$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.
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: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
Cron job for definition for oer harvesting.