ILIAS  release_8 Revision v8.24
class.ilCertificateSettingsCourseFormRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24
29{
37 private ilTree $tree;
39
40 public function __construct(
42 string $certificatePath,
43 bool $hasAdditionalElements,
45 ilCtrlInterface $ctrl,
46 ilAccess $access,
47 ilToolbarGUI $toolbar,
48 ilCertificatePlaceholderDescription $placeholderDescriptionObject,
54 ?ilTree $tree = null,
55 ?ilSetting $setting = null
56 ) {
57 $this->object = $object;
58
59 $this->language = $language;
60
61 if (null === $settingsFormFactory) {
63 $object->getId(),
64 $certificatePath,
65 $hasAdditionalElements,
67 $ctrl,
68 $access,
69 $toolbar,
70 $placeholderDescriptionObject
71 );
72 }
73 $this->settingsFormFactory = $settingsFormFactory;
74
75 if (null === $learningProgressObject) {
77 }
78 $this->learningProgressObject = $learningProgressObject;
79
80 if (null === $trackingHelper) {
82 }
83 $this->trackingHelper = $trackingHelper;
84
85 if (null === $objectHelper) {
87 }
88 $this->objectHelper = $objectHelper;
89
90 if (null === $lpHelper) {
92 }
93 $this->lpHelper = $lpHelper;
94
95 if (null === $tree) {
96 global $DIC;
97 $tree = $DIC['tree'];
98 }
99 $this->tree = $tree;
100
101 if (null === $setting) {
102 $setting = new ilSetting('crs');
103 }
104 $this->setting = $setting;
105 }
106
117 public function createForm(ilCertificateGUI $certificateGUI): ilPropertyFormGUI
118 {
119 $form = $this->settingsFormFactory->createForm($certificateGUI);
120
121 $objectLearningProgressSettings = new ilLPObjSettings($this->object->getId());
122
123 $mode = $objectLearningProgressSettings->getMode();
124 if (!$this->trackingHelper->enabledLearningProgress() || $mode === ilLPObjSettings::LP_MODE_DEACTIVATED) {
125 $subitems = new ilRepositorySelector2InputGUI($this->language->txt('objects'), 'subitems', true);
126
127 $formSection = new ilFormSectionHeaderGUI();
128 $formSection->setTitle($this->language->txt('cert_form_sec_add_features'));
129 $form->addItem($formSection);
130
131 $exp = $subitems->getExplorerGUI();
132 $exp->setSkipRootNode(true);
133 $exp->setRootId($this->object->getRefId());
134 $exp->setTypeWhiteList($this->getLPTypes($this->object->getRefId()));
135
136 $objectHelper = $this->objectHelper;
138 $subitems->setTitleModifier(function ($id) use ($objectHelper, $lpHelper) {
139 if (null === $id) {
140 return '';
141 }
142 $obj_id = $objectHelper->lookupObjId((int) $id);
143 $olp = $lpHelper->getInstance($obj_id);
144
145 $invalid_modes = $this->getInvalidLPModes();
146
147 $mode = $olp->getModeText($olp->getCurrentMode());
148
149 if (in_array($olp->getCurrentMode(), $invalid_modes, true)) {
150 $mode = '<strong>' . $mode . '</strong>';
151 }
152 return $objectHelper->lookupTitle($obj_id) . ' (' . $mode . ')';
153 });
154
155 $subitems->setRequired(true);
156 $form->addItem($subitems);
157 }
158
159 return $form;
160 }
161
166 public function save(array $formFields): void
167 {
168 $invalidModes = $this->getInvalidLPModes();
169
170 $titlesOfObjectsWithInvalidModes = [];
171 $refIds = $formFields['subitems'] ?? [];
172
173 foreach ($refIds as $refId) {
174 $objectId = $this->objectHelper->lookupObjId((int) $refId);
175 $learningProgressObject = $this->lpHelper->getInstance($objectId);
176 $currentMode = $learningProgressObject->getCurrentMode();
177 if (in_array($currentMode, $invalidModes, true)) {
178 $titlesOfObjectsWithInvalidModes[] = $this->objectHelper->lookupTitle($objectId);
179 }
180 }
181
182 if (count($titlesOfObjectsWithInvalidModes) > 0) {
183 $message = sprintf(
184 $this->language->txt('certificate_learning_progress_must_be_active'),
185 implode(', ', $titlesOfObjectsWithInvalidModes)
186 );
187 throw new ilException($message);
188 }
189
190 $this->setting->set(
191 'cert_subitems_' . $this->object->getId(),
192 json_encode($formFields['subitems'] ?? [], JSON_THROW_ON_ERROR)
193 );
194 }
195
196 public function fetchFormFieldData(string $content): array
197 {
198 $formFields = $this->settingsFormFactory->fetchFormFieldData($content);
199
200 $formFields['subitems'] = json_decode($this->setting->get(
201 'cert_subitems_' . $this->object->getId(),
202 json_encode([], JSON_THROW_ON_ERROR)
203 ), true, 512, JSON_THROW_ON_ERROR);
204 if ($formFields['subitems'] === 'null' || $formFields['subitems'] === null) {
205 $formFields['subitems'] = [];
206 }
207 return $formFields;
208 }
209
214 private function getLPTypes(int $a_parent_ref_id): array
215 {
216 $result = [];
217
218 $root = $this->tree->getNodeData($a_parent_ref_id);
219 $sub_items = $this->tree->getSubTree($root);
220 array_shift($sub_items); // remove root
221
222 foreach ($sub_items as $node) {
223 if ($this->lpHelper->isSupportedObjectType($node['type'])) {
224 $class = $this->lpHelper->getTypeClass($node['type']);
226 $modes = $class::getDefaultModes($this->trackingHelper->enabledLearningProgress());
227
228 if (count($modes) > 1) {
229 $result[] = $node['type'];
230 }
231 }
232 }
233
234 return $result;
235 }
236
240 private function getInvalidLPModes(): array
241 {
242 $invalid_modes = [
245 ];
246
247 // without active LP the following modes cannot be supported
248 if (!$this->trackingHelper->enabledLearningProgress()) {
249 // status cannot be set without active LP
250 $invalid_modes[] = ilLPObjSettings::LP_MODE_MANUAL;
253
254 // mode cannot be configured without active LP
255 $invalid_modes[] = ilLPObjSettings::LP_MODE_COLLECTION;
258 $invalid_modes[] = ilLPObjSettings::LP_MODE_SCORM;
259 $invalid_modes[] = ilLPObjSettings::LP_MODE_VISITS; // ?
260 }
261
262 return $invalid_modes;
263 }
264}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
GUI class to create PDF certificates.
__construct(ilObject $object, string $certificatePath, bool $hasAdditionalElements, ilLanguage $language, ilCtrlInterface $ctrl, ilAccess $access, ilToolbarGUI $toolbar, ilCertificatePlaceholderDescription $placeholderDescriptionObject, ?ilObjectLP $learningProgressObject=null, ?ilCertificateSettingsFormRepository $settingsFormFactory=null, ?ilCertificateObjUserTrackingHelper $trackingHelper=null, ?ilCertificateObjectHelper $objectHelper=null, ?ilCertificateObjectLPHelper $lpHelper=null, ?ilTree $tree=null, ?ilSetting $setting=null)
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...
language handling
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...
static getInstance(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a property form user interface.
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...
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...
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$message
Definition: xapiexit.php:32
$refId
Definition: xapitoken.php:58