ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 
19  private $objectHelper;
20 
25 
29  private $ilUtilHelper;
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 
92  $placeholders = $this->defaultPlaceholderValuesObject->getPlaceholderValues($userId, $objId);
93  $latest_progress = array_reduce(
94  $object->getProgressesOf($userId),
95  function ($one, $other) {
96  if ($one !== null && $one->isSuccessful() && $other !== null && $other->isSuccessful()) {
97  return
98  $one->getCompletionDate()->format('Y-m-d H:i:s') > $other->getCompletionDate()->format('Y-m-d H:i:s') ?
99  $one :
100  $other;
101  }
102  if ($one !== null && $one->isSuccessful()) {
103  return $one;
104  }
105  if ($other !== null && $other->isSuccessful()) {
106  return $other;
107  }
108  return null;
109  }
110  );
111  $type = $object->getSubType();
112  $placeholders['PRG_TITLE'] = ilUtil::prepareFormOutput($object->getTitle());
113  $placeholders['PRG_DESCRIPTION'] = ilUtil::prepareFormOutput($object->getDescription());
114  $placeholders['PRG_TYPE'] = ilUtil::prepareFormOutput($type ? $type->getTitle() : '');
115  $placeholders['PRG_POINTS'] = ilUtil::prepareFormOutput($object->getPoints());
116  $placeholders['PRG_COMPLETION_DATE'] = ilUtil::prepareFormOutput($latest_progress->getCompletionDate() instanceof \DateTime ? $latest_progress->getCompletionDate()->format('d.m.Y') : '');
117  $placeholders['PRG_EXPIRES_AT'] = ilUtil::prepareFormOutput($latest_progress->getValidityOfQualification() instanceof \DateTime ? $latest_progress->getValidityOfQualification()->format('d.m.Y') : '');
118  return $placeholders;
119  }
120 
130  public function getPlaceholderValuesForPreview(int $userId, int $objId)
131  {
132  $placeholders = $this->defaultPlaceholderValuesObject->getPlaceholderValuesForPreview($userId, $objId);
133 
134  $object = $this->objectHelper->getInstanceByObjId($objId);
135  $type = $object->getSubType();
136  $today = ilUtil::prepareFormOutput((new DateTime())->format('d.m.Y'));
137  $placeholders['PRG_TITLE'] = ilUtil::prepareFormOutput($object->getTitle());
138  $placeholders['PRG_DESCRIPTION'] = ilUtil::prepareFormOutput($object->getDescription());
139  $placeholders['PRG_TYPE'] = ilUtil::prepareFormOutput($type ? $type->getTitle() : '');
140  $placeholders['PRG_POINTS'] = ilUtil::prepareFormOutput($object->getPoints());
141  $placeholders['PRG_COMPLETION_DATE'] = $today;
142  $placeholders['PRG_EXPIRES_AT'] = $today;
143  return $placeholders;
144  }
145 }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
Collection of basic placeholder values that can be used.
__construct(ilDefaultPlaceholderValues $defaultPlaceholderValues=null, ilLanguage $language=null, ilCertificateObjectHelper $objectHelper=null, ilCertificateParticipantsHelper $participantsHelper=null, ilCertificateUtilHelper $ilUtilHelper=null)
$type
$objId
Definition: xapitoken.php:41
getPlaceholderValuesForPreview(int $userId, int $objId)
This method is different then the &#39;getPlaceholderValues&#39; method, this method is used to create a plac...
Just a wrapper class to create Unit Test for other classes.
getPlaceholderValues(int $userId, int $objId)
This method MUST return an array that contains the actual data for the given user of the given object...
$DIC
Definition: xapitoken.php:46
language handling
language()
Definition: language.php:2