ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
Custom.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\User\Profile\Fields\NoOverrides;
30use ILIAS\Refinery\Factory as Refinery;
32
33class Custom implements FieldDefinition
34{
35 use NoOverrides;
36
37 public function __construct(
38 private readonly Uuid $identifier,
39 private ?Type $type = null,
40 private string $label = '',
41 private ?AvailableSections $section = null,
42 private ?string $additional_edit_form_data = null
43 ) {
44 }
45
46 public function isUnspecific(): bool
47 {
48 return $this->type === null;
49 }
50
51 public function getIdentifier(): string
52 {
53 return $this->identifier->toString();
54 }
55
56 public function getLabel(Language $lng): string
57 {
58 return $this->label;
59 }
60
61 public function withLabel(string $label): self
62 {
63 $clone = clone $this;
64 $clone->label = $label;
65 return $clone;
66 }
67
68 public function getTypeLabel(Language $lng): string
69 {
70 return $this->type?->getLabel($lng) ?? '';
71 }
72
73 public function withType(Type $type): self
74 {
75 $clone = clone $this;
76 $clone->type = $type;
77 return $clone;
78 }
79
80 public function getSection(): AvailableSections
81 {
82 return $this->section;
83 }
84
85 public function withSection(AvailableSections $section): self
86 {
87 $clone = clone $this;
88 $clone->section = $section;
89 return $clone;
90 }
91
94 FieldFactory $ff,
96 ): ?FormInput {
98 $lng,
99 $ff,
100 $refinery,
101 $this->additional_edit_form_data
102 );
103 }
104
105 public function withAdditionalEditFormData(?string $data): self
106 {
107 $clone = clone $this;
108 $clone->additional_edit_form_data = $data;
109 return $clone;
110 }
111
112 public function toStorage(): array
113 {
114 return [
115 'field_name' => [
117 $this->label
118 ],
119 'field_type' => [
121 $this->type::class
122 ],
123 'field_values' => [
125 $this->additional_edit_form_data
126 ],
127 'section' => [
129 $this->section->value
130 ]
131 ];
132 }
133
134 public function getLegacyInput(
136 Context $context,
137 ?\ilObjUser $user = null
139 $value = $user === null
140 ? []
141 : $user->getProfileData()->getAdditionalFieldByIdentifier($this->getIdentifier()) ?? [];
142 return $this->type->getLegacyInput(
143 $lng,
144 $context,
145 $value,
146 $this->label,
147 $this->additional_edit_form_data
148 );
149 }
150
151 public function addValueToUserObject(
152 \ilObjUser $user,
153 mixed $input,
154 \ilPropertyFormGUI $form
155 ): \ilObjUser {
156 return $user->withProfileData(
157 $user->getProfileData()->withAdditionalFieldByIdentifier(
158 $this->getIdentifier(),
159 $this->type->prepareUserInputForStorage($input, $this->additional_edit_form_data)
160 )
161 );
162 }
163
164 public function retrieveValueFromUser(\ilObjUser $user): string
165 {
166 return implode(
167 ', ',
168 $user->getProfileData()->getAdditionalFieldByIdentifier($this->getIdentifier()) ?? []
169 );
170 }
171}
Builds data types.
Definition: Factory.php:36
withSection(AvailableSections $section)
Definition: Custom.php:85
getAdditionalEditFormInputs(Language $lng, FieldFactory $ff, Refinery $refinery)
Definition: Custom.php:92
addValueToUserObject(\ilObjUser $user, mixed $input, \ilPropertyFormGUI $form)
Definition: Custom.php:151
retrieveValueFromUser(\ilObjUser $user)
Definition: Custom.php:164
getLegacyInput(Language $lng, Context $context, ?\ilObjUser $user=null)
You don't need to add a post_var to the input as the User will handle this for you,...
Definition: Custom.php:134
__construct(private readonly Uuid $identifier, private ?Type $type=null, private string $label='', private ?AvailableSections $section=null, private ?string $additional_edit_form_data=null)
Definition: Custom.php:37
This class represents a property in a property form.
User class.
This class represents a property form user interface.
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This describes inputs that can be used in forms.
Definition: FormInput.php:33
This is what a factory for input fields looks like.
Definition: Factory.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $lng
Definition: privfeed.php:26
$data
Definition: storeScorm.php:45