ILIAS  release_8 Revision v8.23
class.ilObjectCustomUserFieldsPlaceholderValues.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 {
28 
29  public function __construct(
30  ?ilCertificateObjectHelper $objectHelper = null,
31  ?ilCertificateUtilHelper $utilHelper = null
32  ) {
33  if (null === $objectHelper) {
34  $objectHelper = new ilCertificateObjectHelper();
35  }
36  $this->objectHelper = $objectHelper;
37  if (null === $utilHelper) {
38  $utilHelper = new ilCertificateUtilHelper();
39  }
40  $this->utilHelper = $utilHelper;
41  }
42 
55  public function getPlaceholderValues(int $userId, int $objId): array
56  {
58  $user = $this->objectHelper->getInstanceByObjId($userId);
59  if (!$user instanceof ilObjUser) {
60  throw new ilException('The entered id: ' . $userId . ' is not an user object');
61  }
62 
63  $course_defined_fields = ilCourseDefinedFieldDefinition::_getFields($objId);
64  $field_values = ilCourseUserData::_getValuesByObjId($objId);
65 
66  $placeholder = [];
67  foreach ($course_defined_fields as $key => $field) {
68  $field_id = $field->getId();
69 
70  $placeholderText = '+' . str_replace(' ', '_', ilStr::strToUpper($field->getName()));
71  $placeholder[$placeholderText] =
72  !empty($field_values[$userId][$field_id]) ?
73  $this->utilHelper->prepareFormOutput(trim($field_values[$userId][$field_id])) :
74  '';
75  }
76 
77  return $placeholder;
78  }
79 
88  public function getPlaceholderValuesForPreview(int $userId, int $objId): array
89  {
90  global $DIC;
91 
92  $lng = $DIC->language();
93 
94  $course_defined_fields = ilCourseDefinedFieldDefinition::_getFields($objId);
95 
96  $placeholder = [];
97  foreach ($course_defined_fields as $key => $field) {
98  $placeholderText = '+' . str_replace(' ', '_', ilStr::strToUpper($field->getName()));
99 
100  $placeholder[$placeholderText] = $placeholderText . '_' . ilStr::strToUpper($lng->txt('value'));
101  }
102 
103  return $placeholder;
104  }
105 }
$lng
static _getValuesByObjId(int $a_obj_id)
$objId
Definition: xapitoken.php:57
__construct(?ilCertificateObjectHelper $objectHelper=null, ?ilCertificateUtilHelper $utilHelper=null)
static _getFields(int $a_container_id, $a_sort=self::IL_CDF_SORT_NAME)
Get all fields of a container.
global $DIC
Definition: feed.php:28
getPlaceholderValuesForPreview(int $userId, int $objId)
This method is different then the &#39;getPlaceholderValues&#39; method, this method is used to create a plac...
static strToUpper(string $a_string)
Definition: class.ilStr.php:81
string $key
Consumer key/client ID value.
Definition: System.php:193
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...