ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
32  private $trackingHelper;
33 
37  private $objectHelper;
38 
42  private $lpHelper;
43 
47  private $tree;
48 
52  private $setting;
53 
71  public function __construct(
73  string $certificatePath,
76  ilCtrl $controller,
77  ilAccess $access,
78  ilToolbarGUI $toolbar,
79  ilCertificatePlaceholderDescription $placeholderDescriptionObject,
85  ilTree $tree = null,
86  ilSetting $setting = null
87  ) {
88  $this->object = $object;
89 
90  $this->language = $language;
91 
92  if (null === $settingsFromFactory) {
94  $object->getId(),
95  $certificatePath,
96  $language,
97  $template,
98  $controller,
99  $access,
100  $toolbar,
101  $placeholderDescriptionObject
102  );
103  }
104  $this->settingsFromFactory = $settingsFromFactory;
105 
106  if (null === $learningProgressObject) {
107  $learningProgressObject = ilObjectLP::getInstance($this->object->getId());
108  }
109  $this->learningProgressObject = $learningProgressObject;
110 
111  if (null === $trackingHelper) {
113  }
114  $this->trackingHelper = $trackingHelper;
115 
116  if (null === $objectHelper) {
118  }
119  $this->objectHelper = $objectHelper;
120 
121  if (null === $lpHelper) {
123  }
124  $this->lpHelper = $lpHelper;
125 
126  if (null === $tree) {
127  global $DIC;
128  $tree = $DIC['tree'];
129  }
130  $this->tree = $tree;
131 
132  if (null === $setting) {
133  $setting = new ilSetting('crs');
134  }
135  $this->setting = $setting;
136  }
137 
151  public function createForm(ilCertificateGUI $certificateGUI, ilCertificate $certificateObject)
152  {
153  $form = $this->settingsFromFactory->createForm($certificateGUI, $certificateObject);
154 
155  $objectLearningProgressSettings = new ilLPObjSettings($this->object->getId());
156 
157  $mode = $objectLearningProgressSettings->getMode();
158  if (!$this->trackingHelper->enabledLearningProgress() || $mode == ilLPObjSettings::LP_MODE_DEACTIVATED) {
159  $subitems = new ilRepositorySelector2InputGUI($this->language->txt('objects'), 'subitems', true);
160 
161  $formSection = new \ilFormSectionHeaderGUI();
162  $formSection->setTitle($this->language->txt('cert_form_sec_add_features'));
163  $form->addItem($formSection);
164 
165  $exp = $subitems->getExplorerGUI();
166  $exp->setSkipRootNode(true);
167  $exp->setRootId($this->object->getRefId());
168  $exp->setTypeWhiteList($this->getLPTypes($this->object->getId()));
169 
172  $subitems->setTitleModifier(function ($id) use ($objectHelper, $lpHelper) {
173  if (null === $id) {
174  return '';
175  }
176  $obj_id = $objectHelper->lookupObjId((int) $id);
177  $olp = $lpHelper->getInstance($obj_id);
178 
179  $invalid_modes = $this->getInvalidLPModes();
180 
181  $mode = $olp->getModeText($olp->getCurrentMode());
182 
183  if (in_array($olp->getCurrentMode(), $invalid_modes)) {
184  $mode = '<strong>' . $mode . '</strong>';
185  }
186  return $objectHelper->lookupTitle($obj_id) . ' (' . $mode . ')';
187  });
188 
189  $subitems->setRequired(true);
190  $form->addItem($subitems);
191  }
192 
193  return $form;
194  }
195 
199  public function save(array $formFields)
200  {
201  $invalidModes = $this->getInvalidLPModes();
202 
203  $titlesOfObjectsWithInvalidModes = array();
204  $refIds = array();
205  if (isset($formFields['subitems'])) {
206  $refIds = $formFields['subitems'];
207  }
208 
209  foreach ($refIds as $refId) {
210  $objectId = $this->objectHelper->lookupObjId((int) $refId);
211  $learningProgressObject = $this->lpHelper->getInstance($objectId);
212  $currentMode = $learningProgressObject->getCurrentMode();
213  if (in_array($currentMode, $invalidModes)) {
214  $titlesOfObjectsWithInvalidModes[] = $this->objectHelper->lookupTitle($objectId);
215  }
216  }
217 
218  if (sizeof($titlesOfObjectsWithInvalidModes)) {
219  $message = sprintf($this->language->txt('certificate_learning_progress_must_be_active'), implode(', ', $titlesOfObjectsWithInvalidModes));
220  throw new ilException($message);
221  }
222 
223  $this->setting->set('cert_subitems_' . $this->object->getId(), json_encode($formFields['subitems']));
224  }
225 
230  public function fetchFormFieldData(string $content)
231  {
232  $formFields = $this->settingsFromFactory->fetchFormFieldData($content);
233 
234  $formFields['subitems'] = json_decode($this->setting->get('cert_subitems_' . $this->object->getId(), json_encode(array())));
235  if ($formFields['subitems'] === 'null' || $formFields['subitems'] === null) {
236  $formFields['subitems'] = array();
237  }
238  return $formFields;
239  }
240 
245  private function getLPTypes(int $a_parent_ref_id) : array
246  {
247  $result = array();
248 
249  $root = $this->tree->getNodeData($a_parent_ref_id);
250  $sub_items = $this->tree->getSubTree($root);
251  array_shift($sub_items); // remove root
252 
253  foreach ($sub_items as $node) {
254  if ($this->lpHelper->isSupportedObjectType($node['type'])) {
255  $class = $this->lpHelper->getTypeClass($node['type']);
256  $modes = $class::getDefaultModes($this->trackingHelper->enabledLearningProgress());
257 
258  if (sizeof($modes) > 1) {
259  $result[] = $node['type'];
260  }
261  }
262  }
263 
264  return $result;
265  }
266 
270  private function getInvalidLPModes()
271  {
272  $invalid_modes = array(
275  );
276 
277  // without active LP the following modes cannot be supported
278  if (!$this->trackingHelper->enabledLearningProgress()) {
279  // status cannot be set without active LP
280  $invalid_modes[] = ilLPObjSettings::LP_MODE_MANUAL;
281  $invalid_modes[] = ilLPObjSettings::LP_MODE_MANUAL_BY_TUTOR;
283 
284  // mode cannot be configured without active LP
285  $invalid_modes[] = ilLPObjSettings::LP_MODE_COLLECTION;
286  $invalid_modes[] = ilLPObjSettings::LP_MODE_COLLECTION_MOBS;
287  $invalid_modes[] = ilLPObjSettings::LP_MODE_COLLECTION_TLT;
288  $invalid_modes[] = ilLPObjSettings::LP_MODE_SCORM;
289  $invalid_modes[] = ilLPObjSettings::LP_MODE_VISITS; // ?
290  }
291 
292  return $invalid_modes;
293  }
294 }
This class provides processing control methods.
$result
$template
global $DIC
Definition: saml.php:7
if(!array_key_exists('StateId', $_REQUEST)) $id
Class ilAccessHandler.
catch(Exception $e) $message
__construct(\ilObject $object, string $certificatePath, ilLanguage $language, ilTemplate $template, 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)
if(isset($_POST['submit'])) $form
getId()
get object id public
special template class to simplify handling of ITX/PEAR
setTitle($a_title)
Set Title.
GUI class to create PDF certificates.
$root
Definition: sabredav.php:45
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
Create PDF certificates.
language handling
createForm(ilCertificateGUI $certificateGUI, ilCertificate $certificateObject)
static getInstance($a_obj_id)