ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilStudyProgrammePlaceholderValues.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
5{
10
14 private $language;
15
20
25
30
39 public function __construct(
40 ilDefaultPlaceholderValues $defaultPlaceholderValues = null,
41 ilLanguage $language = null,
45 ) {
46 if (null === $language) {
47 global $DIC;
48 $language = $DIC->language();
49 $language->loadLanguageModule('certificate');
50 }
51 $this->language = $language;
52
53 if (null === $defaultPlaceholderValues) {
54 $defaultPlaceholderValues = new ilDefaultPlaceholderValues();
55 }
56
57 if (null === $objectHelper) {
59 }
60 $this->objectHelper = $objectHelper;
61
62 if (null === $participantsHelper) {
64 }
65 $this->participantsHelper = $participantsHelper;
66
67 if (null === $ilUtilHelper) {
69 }
70 $this->ilUtilHelper = $ilUtilHelper;
71
72 $this->defaultPlaceholderValuesObject = $defaultPlaceholderValues;
73 }
74
88 public function getPlaceholderValues(int $userId, int $objId) : array
89 {
90 $object = $this->objectHelper->getInstanceByObjId($objId);
91 $placeholders = $this->defaultPlaceholderValuesObject->getPlaceholderValues($userId, $objId);
92 $latest_progress = array_reduce(
93 $object->getProgressesOf($userId),
94 function ($one, $other) {
95 if ($one !== null && $one->isSuccessful() && $other !== null && $other->isSuccessful()) {
96 return
97 $one->getCompletionDate()->format('Y-m-d H:i:s') > $other->getCompletionDate()->format('Y-m-d H:i:s') ?
98 $one :
99 $other;
100 }
101 if ($one !== null && $one->isSuccessful()) {
102 return $one;
103 }
104 if ($other !== null && $other->isSuccessful()) {
105 return $other;
106 }
107 return null;
108 }
109 );
110
111 if (!$latest_progress) {
112 throw new \ilInvalidCertificateException('PRG: no valid progress for user ' . $userId . ' while generating certificate');
113 }
114
115 $type = $object->getSubType();
116 $placeholders['PRG_TITLE'] = ilUtil::prepareFormOutput($object->getTitle());
117 $placeholders['PRG_DESCRIPTION'] = ilUtil::prepareFormOutput($object->getDescription());
118 $placeholders['PRG_TYPE'] = ilUtil::prepareFormOutput($type ? $type->getTitle() : '');
119 $placeholders['PRG_POINTS'] = ilUtil::prepareFormOutput($object->getPoints());
120 $placeholders['PRG_COMPLETION_DATE'] = ilUtil::prepareFormOutput($latest_progress->getCompletionDate() instanceof \DateTimeImmutable ? $latest_progress->getCompletionDate()->format('d.m.Y') : '');
121 $placeholders['PRG_EXPIRES_AT'] = ilUtil::prepareFormOutput($latest_progress->getValidityOfQualification() instanceof \DateTimeImmutable ? $latest_progress->getValidityOfQualification()->format('d.m.Y') : '');
122 return $placeholders;
123 }
124
134 public function getPlaceholderValuesForPreview(int $userId, int $objId)
135 {
136 $placeholders = $this->defaultPlaceholderValuesObject->getPlaceholderValuesForPreview($userId, $objId);
137
138 $object = $this->objectHelper->getInstanceByObjId($objId);
139 $type = $object->getSubType();
140 $today = ilUtil::prepareFormOutput((new DateTime())->format('d.m.Y'));
141 $placeholders['PRG_TITLE'] = ilUtil::prepareFormOutput($object->getTitle());
142 $placeholders['PRG_DESCRIPTION'] = ilUtil::prepareFormOutput($object->getDescription());
143 $placeholders['PRG_TYPE'] = ilUtil::prepareFormOutput($type ? $type->getTitle() : '');
144 $placeholders['PRG_POINTS'] = ilUtil::prepareFormOutput($object->getPoints());
145 $placeholders['PRG_COMPLETION_DATE'] = $today;
146 $placeholders['PRG_EXPIRES_AT'] = $today;
147 return $placeholders;
148 }
149}
An exception for terminatinating execution or to throw for unit testing.
Just a wrapper class to create Unit Test for other classes.
Collection of basic placeholder values that can be used.
language handling
__construct(ilDefaultPlaceholderValues $defaultPlaceholderValues=null, ilLanguage $language=null, ilCertificateObjectHelper $objectHelper=null, ilCertificateParticipantsHelper $participantsHelper=null, ilCertificateUtilHelper $ilUtilHelper=null)
getPlaceholderValues(int $userId, int $objId)
This method MUST return an array that contains the actual data for the given user of the given object...
getPlaceholderValuesForPreview(int $userId, int $objId)
This method is different then the 'getPlaceholderValues' method, this method is used to create a plac...
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
Definition: confirmReg.php:12
global $DIC
Definition: goto.php:24
language()
Definition: language.php:2
$type
$objId
Definition: xapitoken.php:39