ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilScormPlaceholderDescription.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24{
26 private readonly ilLanguage $language;
27 private array $placeholder;
29
30 public function __construct(
31 private readonly ilObject $object,
32 ?ilDefaultPlaceholderDescription $defaultPlaceholderDescriptionObject = null,
33 ?ilLanguage $language = null,
35 ?ilUserDefinedFieldsPlaceholderDescription $userDefinedFieldPlaceHolderDescriptionObject = null,
36 ?Profile $profile = null
37 ) {
38 global $DIC;
39
40 if (null === $language) {
41 $language = $DIC->language();
42 $language->loadLanguageModule('certificate');
43 }
44 $this->language = $language;
45
46 if (null === $defaultPlaceholderDescriptionObject) {
47 $defaultPlaceholderDescriptionObject = new ilDefaultPlaceholderDescription(
49 $profile ?? $DIC['user']->getProfile(),
50 $userDefinedFieldPlaceHolderDescriptionObject
51 );
52 }
53 $this->defaultPlaceHolderDescriptionObject = $defaultPlaceholderDescriptionObject;
54
55 if (null === $learningProgressObject) {
57 }
58 $this->learningProgressObject = $learningProgressObject;
59
60 $this->placeholder = $this->defaultPlaceHolderDescriptionObject->getPlaceholderDescriptions();
61
62 $this->placeholder['SCORM_TITLE'] = $language->txt('certificate_ph_scormtitle');
63 $this->placeholder['SCORM_POINTS'] = $language->txt('certificate_ph_scormpoints');
64 $this->placeholder['SCORM_POINTS_MAX'] = $language->txt('certificate_ph_scormmaxpoints');
65 $this->placeholder['DATE_COMPLETED'] = ilLegacyFormElementsUtil::prepareFormOutput(
66 $language->txt('certificate_ph_date_completed')
67 );
68 $this->placeholder['DATETIME_COMPLETED'] = ilLegacyFormElementsUtil::prepareFormOutput(
69 $language->txt('certificate_ph_datetime_completed')
70 );
71 }
72
79 public function createPlaceholderHtmlDescription(?ilTemplate $template = null): string
80 {
81 if (null === $template) {
82 $template = new ilTemplate('tpl.scorm_description.html', true, true, 'components/ILIAS/Certificate');
83 }
84
85 $template->setCurrentBlock('items');
86
87 foreach ($this->placeholder as $id => $caption) {
88 $template->setVariable('ID', $id);
89 $template->setVariable('TXT', $caption);
90 $template->parseCurrentBlock();
91 }
92
93 $template->setVariable('PH_INTRODUCTION', $this->language->txt('certificate_ph_introduction'));
94
95 $collection = $this->learningProgressObject->getCollectionInstance();
96 $items = [];
97 if ($collection !== null) {
98 $items = $collection->getPossibleItems();
99 }
100
101 if ($items) {
102 $template->setCurrentBlock('SCOS');
103 $template->setVariable('PH_SCOS', $this->language->txt('certificate_ph_scos'));
104 $template->parseCurrentBlock();
105 $template->setCurrentBlock('SCO_HEADER');
106 $template->setVariable('PH_TITLE_SCO', $this->language->txt('certificate_ph_title_sco'));
107 $template->setVariable('PH_SCO_TITLE', $this->language->txt('certificate_ph_sco_title'));
108 $template->setVariable('PH_SCO_POINTS_RAW', $this->language->txt('certificate_ph_sco_points_raw'));
109 $template->setVariable('PH_SCO_POINTS_MAX', $this->language->txt('certificate_ph_sco_points_max'));
110 $template->setVariable('PH_SCO_POINTS_SCALED', $this->language->txt('certificate_ph_sco_points_scaled'));
111 } else {
112 $template->setCurrentBlock('NO_SCO');
113 $template->setVariable('PH_NO_SCO', $this->language->txt('certificate_ph_no_sco'));
114 }
115 $template->parseCurrentBlock();
116
117 if ($collection !== null) {
118 $counter = 0;
119 foreach ($items as $item_id => $sahs_item) {
120 if ($collection->isAssignedEntry($item_id)) {
121 $template->setCurrentBlock('SCO');
122 $template->setVariable('SCO_TITLE', $sahs_item['title']);
123 $template->setVariable('PH_SCO_TITLE', '[SCO_T_' . $counter . ']');
124 $template->setVariable('PH_SCO_POINTS_RAW', '[SCO_P_' . $counter . ']');
125 $template->setVariable('PH_SCO_POINTS_MAX', '[SCO_PM_' . $counter . ']');
126 $template->setVariable('PH_SCO_POINTS_SCALED', '[SCO_PP_' . $counter . ']');
127 $template->parseCurrentBlock();
128 $counter++;
129 }
130 }
131 }
132
133 return $template->get();
134 }
135
141 public function getPlaceholderDescriptions(): array
142 {
143 return $this->placeholder;
144 }
145}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Collection of basic placeholder values that can be used.
language handling
loadLanguageModule(string $a_module)
Load language module.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static prepareFormOutput($a_str, bool $a_strip=false)
Base class for object lp connectors.
static getInstance(int $obj_id)
Class ilObject Basic functions for all objects.
getPlaceholderDescriptions()
This method MUST return an array containing an array with the the description as array value.
createPlaceholderHtmlDescription(?ilTemplate $template=null)
This methods MUST return an array containing an array with the the description as array value.
readonly ilDefaultPlaceholderDescription $defaultPlaceHolderDescriptionObject
__construct(private readonly ilObject $object, ?ilDefaultPlaceholderDescription $defaultPlaceholderDescriptionObject=null, ?ilLanguage $language=null, ?ilObjectLP $learningProgressObject=null, ?ilUserDefinedFieldsPlaceholderDescription $userDefinedFieldPlaceHolderDescriptionObject=null, ?Profile $profile=null)
special template class to simplify handling of ITX/PEAR
global $DIC
Definition: shib_login.php:26
$counter