ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilScormPlaceholderDescription.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
24  private readonly ilLanguage $language;
25  private array $placeholder;
27 
28  public function __construct(
29  private readonly ilObject $object,
30  ?ilDefaultPlaceholderDescription $defaultPlaceholderDescriptionObject = null,
31  ?ilLanguage $language = null,
32  ?ilObjectLP $learningProgressObject = null,
33  ?ilUserDefinedFieldsPlaceholderDescription $userDefinedFieldPlaceHolderDescriptionObject = null
34  ) {
35  global $DIC;
36 
37  if (null === $language) {
38  $language = $DIC->language();
39  $language->loadLanguageModule('certificate');
40  }
41  $this->language = $language;
42 
43  if (null === $defaultPlaceholderDescriptionObject) {
44  $defaultPlaceholderDescriptionObject = new ilDefaultPlaceholderDescription(
45  $language,
46  $userDefinedFieldPlaceHolderDescriptionObject
47  );
48  }
49  $this->defaultPlaceHolderDescriptionObject = $defaultPlaceholderDescriptionObject;
50 
51  if (null === $learningProgressObject) {
52  $learningProgressObject = ilObjectLP::getInstance($this->object->getId());
53  }
54  $this->learningProgressObject = $learningProgressObject;
55 
56  $this->placeholder = $this->defaultPlaceHolderDescriptionObject->getPlaceholderDescriptions();
57 
58  $this->placeholder['SCORM_TITLE'] = $language->txt('certificate_ph_scormtitle');
59  $this->placeholder['SCORM_POINTS'] = $language->txt('certificate_ph_scormpoints');
60  $this->placeholder['SCORM_POINTS_MAX'] = $language->txt('certificate_ph_scormmaxpoints');
61  $this->placeholder['DATE_COMPLETED'] = ilLegacyFormElementsUtil::prepareFormOutput(
62  $language->txt('certificate_ph_date_completed')
63  );
64  $this->placeholder['DATETIME_COMPLETED'] = ilLegacyFormElementsUtil::prepareFormOutput(
65  $language->txt('certificate_ph_datetime_completed')
66  );
67  }
68 
75  public function createPlaceholderHtmlDescription(?ilTemplate $template = null): string
76  {
77  if (null === $template) {
78  $template = new ilTemplate('tpl.scorm_description.html', true, true, 'components/ILIAS/Certificate');
79  }
80 
81  $template->setCurrentBlock('items');
82 
83  foreach ($this->placeholder as $id => $caption) {
84  $template->setVariable('ID', $id);
85  $template->setVariable('TXT', $caption);
86  $template->parseCurrentBlock();
87  }
88 
89  $template->setVariable('PH_INTRODUCTION', $this->language->txt('certificate_ph_introduction'));
90 
91  $collection = $this->learningProgressObject->getCollectionInstance();
92  $items = [];
93  if ($collection !== null) {
94  $items = $collection->getPossibleItems();
95  }
96 
97  if ($items) {
98  $template->setCurrentBlock('SCOS');
99  $template->setVariable('PH_SCOS', $this->language->txt('certificate_ph_scos'));
100  $template->parseCurrentBlock();
101  $template->setCurrentBlock('SCO_HEADER');
102  $template->setVariable('PH_TITLE_SCO', $this->language->txt('certificate_ph_title_sco'));
103  $template->setVariable('PH_SCO_TITLE', $this->language->txt('certificate_ph_sco_title'));
104  $template->setVariable('PH_SCO_POINTS_RAW', $this->language->txt('certificate_ph_sco_points_raw'));
105  $template->setVariable('PH_SCO_POINTS_MAX', $this->language->txt('certificate_ph_sco_points_max'));
106  $template->setVariable('PH_SCO_POINTS_SCALED', $this->language->txt('certificate_ph_sco_points_scaled'));
107  } else {
108  $template->setCurrentBlock('NO_SCO');
109  $template->setVariable('PH_NO_SCO', $this->language->txt('certificate_ph_no_sco'));
110  }
111  $template->parseCurrentBlock();
112 
113  if ($collection !== null) {
114  $counter = 0;
115  foreach ($items as $item_id => $sahs_item) {
116  if ($collection->isAssignedEntry($item_id)) {
117  $template->setCurrentBlock('SCO');
118  $template->setVariable('SCO_TITLE', $sahs_item['title']);
119  $template->setVariable('PH_SCO_TITLE', '[SCO_T_' . $counter . ']');
120  $template->setVariable('PH_SCO_POINTS_RAW', '[SCO_P_' . $counter . ']');
121  $template->setVariable('PH_SCO_POINTS_MAX', '[SCO_PM_' . $counter . ']');
122  $template->setVariable('PH_SCO_POINTS_SCALED', '[SCO_PP_' . $counter . ']');
123  $template->parseCurrentBlock();
124  $counter++;
125  }
126  }
127  }
128 
129  return $template->get();
130  }
131 
137  public function getPlaceholderDescriptions(): array
138  {
139  return $this->placeholder;
140  }
141 }
readonly ilDefaultPlaceholderDescription $defaultPlaceHolderDescriptionObject
static prepareFormOutput($a_str, bool $a_strip=false)
getPlaceholderDescriptions()
This method MUST return an array containing an array with the the description as array value...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
createPlaceholderHtmlDescription(?ilTemplate $template=null)
This methods MUST return an array containing an array with the the description as array value...
global $DIC
Definition: shib_login.php:26
__construct(private readonly ilObject $object, ?ilDefaultPlaceholderDescription $defaultPlaceholderDescriptionObject=null, ?ilLanguage $language=null, ?ilObjectLP $learningProgressObject=null, ?ilUserDefinedFieldsPlaceholderDescription $userDefinedFieldPlaceHolderDescriptionObject=null)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
language()
description: > Example for rendring a language glyph.
Definition: language.php:41
static getInstance(int $obj_id)