ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 
52  public function getPlaceholderValues(int $userId, int $objId): array
53  {
55  $user = $this->objectHelper->getInstanceByObjId($userId);
56  if (!$user instanceof ilObjUser) {
57  throw new ilException('The entered id: ' . $userId . ' is not an user object');
58  }
59 
60  $course_defined_fields = ilCourseDefinedFieldDefinition::_getFields($objId);
61  $field_values = ilCourseUserData::_getValuesByObjId($objId);
62 
63  $placeholder = [];
64  foreach ($course_defined_fields as $field) {
65  $field_id = $field->getId();
66 
67  $placeholderText = '+' . str_replace(' ', '_', ilStr::strToUpper($field->getName()));
68  $placeholder[$placeholderText] =
69  !empty($field_values[$userId][$field_id]) ?
70  $this->utilHelper->prepareFormOutput(trim($field_values[$userId][$field_id])) :
71  '';
72  }
73 
74  return $placeholder;
75  }
76 
82  public function getPlaceholderValuesForPreview(int $userId, int $objId): array
83  {
84  global $DIC;
85 
86  $lng = $DIC->language();
87 
88  $course_defined_fields = ilCourseDefinedFieldDefinition::_getFields($objId);
89 
90  $placeholder = [];
91  foreach ($course_defined_fields as $field) {
92  $placeholderText = '+' . str_replace(' ', '_', ilStr::strToUpper($field->getName()));
93 
94  $placeholder[$placeholderText] = $placeholderText . '_' . ilStr::strToUpper($lng->txt('value'));
95  }
96 
97  return $placeholder;
98  }
99 }
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.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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
global $DIC
Definition: shib_login.php:22
global $lng
Definition: privfeed.php:31
getPlaceholderValues(int $userId, int $objId)
This method MUST return an array that contains the actual data for the given user of the given object...