ILIAS  trunk Revision v11.0_alpha-1731-gff9cd7e2bd3
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Custom.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 class Custom implements CustomInterface
24 {
25  protected \ilObjUser $user;
26 
30  protected array $sets = [];
31 
32  public function __construct(
33  \ilObjUser $user,
34  string $type,
35  int $ref_id,
36  string $sub_type = '',
37  int $sub_id = 0
38  ) {
39  $this->user = $user;
40  $this->initSets($type, $ref_id, $sub_type, $sub_id);
41  }
42 
46  public function sets(): array
47  {
48  return $this->sets;
49  }
50 
51  protected function initSets(
52  string $type,
53  int $ref_id,
54  string $sub_type,
55  int $sub_id
56  ): void {
58  \ilObject::_lookupObjId($ref_id),
59  $type,
60  $sub_type,
61  $sub_id
62  ) as $record_id => $a_values) {
63  // this correctly binds group and definitions
64  $a_values->read();
65 
66  $fields = [];
67  $defs = $a_values->getDefinitions();
68  foreach ($a_values->getADTGroup()->getElements() as $element_id => $element) {
69  if (!$element->isNull()) {
70  $field_translations = \ilAdvancedMDFieldTranslations::getInstanceByRecordId($record_id);
71  $title = $field_translations->getTitleForLanguage($element_id, $this->user->getLanguage());
72 
73  $presentation_bridge = \ilADTFactory::getInstance()->getPresentationBridgeForInstance($element);
74  if ($element instanceof \ilADTLocation) {
75  $presentation_bridge->setSize('500px', '300px');
76  }
77 
78  $fields[] = new Field(
79  $title,
80  (string) $presentation_bridge->getSortable(),
81  $presentation_bridge->getHTML()
82  );
83  }
84  }
85 
86  $record_translations = \ilAdvancedMDRecordTranslations::getInstanceByRecordId($record_id);
87  $this->sets[] = new Set(
88  $record_translations->getTitleForLanguage($this->user->getLanguage()),
89  ...$fields
90  );
91  }
92  }
93 }
static getInstancesForObjectId(int $a_obj_id, ?string $a_obj_type=null, string $a_sub_type="-", int $a_sub_id=0)
static _lookupObjId(int $ref_id)
initSets(string $type, int $ref_id, string $sub_type, int $sub_id)
Definition: Custom.php:51
__construct(\ilObjUser $user, string $type, int $ref_id, string $sub_type='', int $sub_id=0)
Definition: Custom.php:32