ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilCertificateSettingsCourseFormRepository.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
8{
12 private $language;
13
18
22 private $object;
23
28
33
38
42 private $lpHelper;
43
47 private $tree;
48
52 private $setting;
53
70 public function __construct(
72 string $certificatePath,
73 bool $hasAdditionalElements,
75 ilCtrl $controller,
76 ilAccess $access,
77 ilToolbarGUI $toolbar,
78 ilCertificatePlaceholderDescription $placeholderDescriptionObject,
84 ilTree $tree = null,
85 ilSetting $setting = null
86 ) {
87 $this->object = $object;
88
89 $this->language = $language;
90
91 if (null === $settingsFromFactory) {
93 $object->getId(),
94 $certificatePath,
95 $hasAdditionalElements,
97 $controller,
98 $access,
99 $toolbar,
100 $placeholderDescriptionObject
101 );
102 }
103 $this->settingsFromFactory = $settingsFromFactory;
104
105 if (null === $learningProgressObject) {
106 $learningProgressObject = ilObjectLP::getInstance($this->object->getId());
107 }
108 $this->learningProgressObject = $learningProgressObject;
109
110 if (null === $trackingHelper) {
112 }
113 $this->trackingHelper = $trackingHelper;
114
115 if (null === $objectHelper) {
117 }
118 $this->objectHelper = $objectHelper;
119
120 if (null === $lpHelper) {
122 }
123 $this->lpHelper = $lpHelper;
124
125 if (null === $tree) {
126 global $DIC;
127 $tree = $DIC['tree'];
128 }
129 $this->tree = $tree;
130
131 if (null === $setting) {
132 $setting = new ilSetting('crs');
133 }
134 $this->setting = $setting;
135 }
136
147 public function createForm(ilCertificateGUI $certificateGUI)
148 {
149 $form = $this->settingsFromFactory->createForm($certificateGUI);
150
151 $objectLearningProgressSettings = new ilLPObjSettings($this->object->getId());
152
153 $mode = $objectLearningProgressSettings->getMode();
154 if (!$this->trackingHelper->enabledLearningProgress() || $mode == ilLPObjSettings::LP_MODE_DEACTIVATED) {
155 $subitems = new ilRepositorySelector2InputGUI($this->language->txt('objects'), 'subitems', true);
156
157 $formSection = new \ilFormSectionHeaderGUI();
158 $formSection->setTitle($this->language->txt('cert_form_sec_add_features'));
159 $form->addItem($formSection);
160
161 $exp = $subitems->getExplorerGUI();
162 $exp->setSkipRootNode(true);
163 $exp->setRootId($this->object->getRefId());
164 $exp->setTypeWhiteList($this->getLPTypes($this->object->getId()));
165
168 $subitems->setTitleModifier(function ($id) use ($objectHelper, $lpHelper) {
169 if (null === $id) {
170 return '';
171 }
172 $obj_id = $objectHelper->lookupObjId((int) $id);
173 $olp = $lpHelper->getInstance($obj_id);
174
175 $invalid_modes = $this->getInvalidLPModes();
176
177 $mode = $olp->getModeText($olp->getCurrentMode());
178
179 if (in_array($olp->getCurrentMode(), $invalid_modes)) {
180 $mode = '<strong>' . $mode . '</strong>';
181 }
182 return $objectHelper->lookupTitle($obj_id) . ' (' . $mode . ')';
183 });
184
185 $subitems->setRequired(true);
186 $form->addItem($subitems);
187 }
188
189 return $form;
190 }
191
195 public function save(array $formFields)
196 {
197 $invalidModes = $this->getInvalidLPModes();
198
199 $titlesOfObjectsWithInvalidModes = array();
200 $refIds = array();
201 if (isset($formFields['subitems'])) {
202 $refIds = $formFields['subitems'];
203 }
204
205 foreach ($refIds as $refId) {
206 $objectId = $this->objectHelper->lookupObjId((int) $refId);
207 $learningProgressObject = $this->lpHelper->getInstance($objectId);
208 $currentMode = $learningProgressObject->getCurrentMode();
209 if (in_array($currentMode, $invalidModes)) {
210 $titlesOfObjectsWithInvalidModes[] = $this->objectHelper->lookupTitle($objectId);
211 }
212 }
213
214 if (sizeof($titlesOfObjectsWithInvalidModes)) {
215 $message = sprintf($this->language->txt('certificate_learning_progress_must_be_active'), implode(', ', $titlesOfObjectsWithInvalidModes));
216 throw new ilException($message);
217 }
218
219 $this->setting->set('cert_subitems_' . $this->object->getId(), json_encode($formFields['subitems']));
220 }
221
226 public function fetchFormFieldData(string $content)
227 {
228 $formFields = $this->settingsFromFactory->fetchFormFieldData($content);
229
230 $formFields['subitems'] = json_decode($this->setting->get('cert_subitems_' . $this->object->getId(), json_encode(array())));
231 if ($formFields['subitems'] === 'null' || $formFields['subitems'] === null) {
232 $formFields['subitems'] = array();
233 }
234 return $formFields;
235 }
236
241 private function getLPTypes(int $a_parent_ref_id) : array
242 {
243 $result = array();
244
245 $root = $this->tree->getNodeData($a_parent_ref_id);
246 $sub_items = $this->tree->getSubTree($root);
247 array_shift($sub_items); // remove root
248
249 foreach ($sub_items as $node) {
250 if ($this->lpHelper->isSupportedObjectType($node['type'])) {
251 $class = $this->lpHelper->getTypeClass($node['type']);
252 $modes = $class::getDefaultModes($this->trackingHelper->enabledLearningProgress());
253
254 if (sizeof($modes) > 1) {
255 $result[] = $node['type'];
256 }
257 }
258 }
259
260 return $result;
261 }
262
266 private function getInvalidLPModes()
267 {
268 $invalid_modes = array(
271 );
272
273 // without active LP the following modes cannot be supported
274 if (!$this->trackingHelper->enabledLearningProgress()) {
275 // status cannot be set without active LP
276 $invalid_modes[] = ilLPObjSettings::LP_MODE_MANUAL;
279
280 // mode cannot be configured without active LP
281 $invalid_modes[] = ilLPObjSettings::LP_MODE_COLLECTION;
284 $invalid_modes[] = ilLPObjSettings::LP_MODE_SCORM;
285 $invalid_modes[] = ilLPObjSettings::LP_MODE_VISITS; // ?
286 }
287
288 return $invalid_modes;
289 }
290}
$result
An exception for terminatinating execution or to throw for unit testing.
Class ilAccessHandler.
GUI class to create PDF certificates.
__construct(\ilObject $object, string $certificatePath, bool $hasAdditionalElements, ilLanguage $language, ilCtrl $controller, ilAccess $access, ilToolbarGUI $toolbar, ilCertificatePlaceholderDescription $placeholderDescriptionObject, ilObjectLP $learningProgressObject=null, ilCertificateSettingsFormRepository $settingsFromFactory=null, ilCertificateObjUserTrackingHelper $trackingHelper=null, ilCertificateObjectHelper $objectHelper=null, ilCertificateObjectLPHelper $lpHelper=null, ilTree $tree=null, ilSetting $setting=null)
This class provides processing control methods.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
static getInstance($a_obj_id)
Class ilObject Basic functions for all objects.
ILIAS Setting Class.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
global $DIC
Definition: goto.php:24
language()
Definition: language.php:2
$message
Definition: xapiexit.php:14
$refId
Definition: xapitoken.php:40