ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilMMSubitemFormGUI Class Reference

Class ilMMSubitemFormGUI. More...

+ Collaboration diagram for ilMMSubitemFormGUI:

Public Member Functions

 __construct (protected ilCtrl $ctrl, protected ILIAS\UI\Factory $ui_fa, protected Renderer $ui_re, protected Translator $lng, private RequestInterface $request, private ilMMItemFacadeInterface $item_facade, private ilMMItemRepository $repository, private ?ilMMItemFacadeInterface $parent_item=null)
 ilMMSubitemFormGUI constructor. More...
 
 save ()
 
 getHTML ()
 
 get ()
 

Data Fields

const F_TITLE = "title"
 
const F_TYPE = "type"
 
const F_PARENT = "parent"
 
const F_ACTIVE = "active"
 
const F_ICON = "icon"
 
const F_ROLE_BASED_VISIBILITY = "role_based_visibility"
 

Private Member Functions

 initForm ()
 
 getTypeGroups (Closure $f)
 

Private Attributes

Standard $form
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilMMSubitemFormGUI::__construct ( protected ilCtrl  $ctrl,
protected ILIAS\UI\Factory  $ui_fa,
protected Renderer  $ui_re,
protected Translator  $lng,
private RequestInterface  $request,
private ilMMItemFacadeInterface  $item_facade,
private ilMMItemRepository  $repository,
private ?ilMMItemFacadeInterface  $parent_item = null 
)

ilMMSubitemFormGUI constructor.

Parameters
ilCtrl$ctrl
Factory$ui_fa
Renderer$ui_re
ilLanguage$lng
ilMMItemFacadeInterface$item_facade
ilMMItemRepository$repository

Definition at line 57 of file class.ilMMSubitemFormGUI.php.

66 {
67 $this->initForm();
68 }

References initForm().

+ Here is the call graph for this function:

Member Function Documentation

◆ get()

ilMMSubitemFormGUI::get ( )

Definition at line 238 of file class.ilMMSubitemFormGUI.php.

238 : Standard
239 {
240 return $this->form;
241 }
This describes a standard form.
Definition: Standard.php:29

References $form.

◆ getHTML()

ilMMSubitemFormGUI::getHTML ( )
Deprecated:
use get() instead

Definition at line 233 of file class.ilMMSubitemFormGUI.php.

233 : string
234 {
235 return $this->ui_re->render([$this->form]);
236 }
form( $class_path, string $cmd, string $submit_caption="")

References ILIAS\Repository\form().

+ Here is the call graph for this function:

◆ getTypeGroups()

ilMMSubitemFormGUI::getTypeGroups ( Closure  $f)
private
Parameters
Closure$f
Returns
array

Definition at line 247 of file class.ilMMSubitemFormGUI.php.

247 : array
248 {
249 $type_groups = [];
250 $type_informations = $this->repository->getPossibleSubItemTypesWithInformation();
251 foreach ($type_informations as $classname => $information) {
252 if ($this->item_facade->isEmpty()
253 || (!$this->item_facade->isEmpty() && $classname === $this->item_facade->getType(
254 ) && $this->item_facade->isCustom())
255 ) { // https://mantis.ilias.de/view.php?id=24152
256 $inputs = $this->repository->getTypeHandlerForType($classname)->getAdditionalFieldsForSubForm(
257 $this->item_facade->identification()
258 );
259 $type_groups[$this->hash($classname)] = $f()->field()->group(
260 $inputs,
261 $information->getTypeNameForPresentation()
262 );
263 }
264 }
265
266 return $type_groups;
267 }

References Vendor\Package\$f, ILIAS\UI\Implementation\Component\Input\$inputs, and ILIAS\UI\examples\Deck\repository().

Referenced by initForm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initForm()

ilMMSubitemFormGUI::initForm ( )
private

Definition at line 70 of file class.ilMMSubitemFormGUI.php.

70 : void
71 {
72 // TITLE
73 $txt = (fn($id): string => $this->lng->txt($id));
74 $f = (fn(): InputFactory => $this->ui_fa->input());
75
76 $title = $f()->field()->text($txt('sub_title_default'), $txt('sub_title_default_byline'));
77 if (!$this->item_facade->isEmpty()) {
78 $title = $title->withValue($this->item_facade->getDefaultTitle());
79 }
80 $items[self::F_TITLE] = $title;
81
82 // TYPE
83 if (($this->item_facade->isEmpty() || $this->item_facade->isCustom())) {
84 $type_groups = $this->getTypeGroups($f);
85 $type = $f()->field()->switchableGroup(
86 $type_groups,
87 $txt('sub_type'),
88 $txt('sub_type_byline')
89 )->withRequired(true);
90 if (!$this->item_facade->isEmpty()) {
91 $string = $this->item_facade->getType() === '' ? Link::class : $this->item_facade->getType();
92 $type = $type->withValue($this->hash($string));
93 } else {
94 $type = $type->withValue($this->hash(Link::class));
95 }
96 $items[self::F_TYPE] = $type;
97 }
98
99 // ICON
100 if ($this->item_facade->supportsCustomIcon()) {
101 // ICON
102 $icon = $f()->field()->file(new ilMMUploadHandlerGUI(), $txt('sub_icon'))
103 ->withByline($txt('sub_icon_byline'))
104 ->withAcceptedMimeTypes([MimeType::IMAGE__SVG_XML]);
105 if ($this->item_facade->getIconID() !== null) {
106 $icon = $icon->withValue([$this->item_facade->getIconID()]);
107 }
108
109 $items[self::F_ICON] = $icon;
110 }
111
112 // PARENT
113 $possible_parents = array_keys($this->repository->getPossibleParentsForFormAndTable());
114 if (!$this->item_facade->isEmpty()
115 && !$this->item_facade->isInLostItem()
116 && in_array($this->item_facade->getParentIdentificationString(), $possible_parents, true)) {
117
118 $parent = $f()->field()
119 ->select(
120 $txt('sub_parent'),
121 $this->repository->getPossibleParentsForFormAndTable()
122 )
123 ->withRequired(true)
124 ->withValue($this->item_facade->getParentIdentificationString());
125 } else {
126 $parent = $f()->field()
127 ->hidden()
128 ->withRequired(true)
129 ->withValue(
130 $this->parent_item?->identification()->serialize() ?? reset($possible_parents)
131 );
132 }
133 $items[self::F_PARENT] = $parent;
134
135 // ACTIVE
136 $active = $f()->field()->checkbox($txt('sub_active'), $txt('sub_active_byline'));
137 $active = $active->withValue($this->item_facade->isActivated());
138 $items[self::F_ACTIVE] = $active;
139
140 // ROLE BASED VISIBILITY
141 if ($this->item_facade->supportsRoleBasedVisibility()) {
142 $access = new ilObjMainMenuAccess();
143 $value_role_based_visibility = null;
144 if ($this->item_facade->hasRoleBasedVisibility() && !empty($this->item_facade->getGlobalRoleIDs())) {
145 // remove deleted roles, see https://mantis.ilias.de/view.php?id=34936
146 $value_role_based_visibility[0] = array_intersect(
147 $this->item_facade->getGlobalRoleIDs(),
148 array_keys($access->getGlobalRoles())
149 );
150 }
151 $role_based_visibility = $f()->field()->optionalGroup(
152 [
153 $f()->field()->multiSelect(
154 $txt('sub_global_roles'),
155 $access->getGlobalRoles()
156 )->withRequired(false)
157 ],
158 $txt('sub_role_based_visibility'),
159 $txt('sub_role_based_visibility_byline')
160 )->withValue($value_role_based_visibility);
161 $items[self::F_ROLE_BASED_VISIBILITY] = $role_based_visibility;
162 }
163
164 // RETURN FORM
165 if ($this->item_facade->isEmpty()) {
166 $this->form = $f()->container()->form()->standard(
167 $this->ctrl->getLinkTargetByClass(
168 ilMMSubItemGUI::class,
170 ),
171 $items
172 );
173 } else {
174 $this->form = $f()->container()->form()->standard(
175 $this->ctrl->getLinkTargetByClass(
176 ilMMSubItemGUI::class,
178 ),
179 $items
180 );
181 }
182 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Class ilMMUploadHandlerGUI.
Class ilObjMainMenuAccess.
$txt
Definition: error.php:31

References Vendor\Package\$f, $id, $txt, ilMMBaseGUI\CMD_CREATE, ilMMBaseGUI\CMD_UPDATE, ILIAS\Repository\ctrl(), F_ACTIVE, F_ICON, F_PARENT, F_ROLE_BASED_VISIBILITY, F_TITLE, F_TYPE, ILIAS\Repository\form(), getTypeGroups(), ILIAS\Repository\lng(), and ILIAS\UI\examples\Deck\repository().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ save()

ilMMSubitemFormGUI::save ( )

Definition at line 184 of file class.ilMMSubitemFormGUI.php.

184 : bool
185 {
186 $r = new ilMMItemRepository();
187 $this->form = $this->form->withRequest($this->request);
188 $data = $this->form->getData();
189
190 if (is_null($data)) {
191 return false;
192 }
193
194 $role_based_visibility = $data[self::F_ROLE_BASED_VISIBILITY] ?? false;
195 $this->item_facade->setDefaultTitle((string) $data[self::F_TITLE]);
196 $this->item_facade->setActiveStatus((bool) $data[self::F_ACTIVE]);
197 $this->item_facade->setRoleBasedVisibility((bool) $role_based_visibility);
198
199 if ($role_based_visibility) {
200 $this->item_facade->setGlobalRoleIDs((array) $role_based_visibility[0]);
201 }
202 if ((string) $data[self::F_PARENT] !== '' && (string) $data[self::F_PARENT] !== '0') {
203 $this->item_facade->setParent((string) $data[self::F_PARENT]);
204 }
205 $this->item_facade->setIsTopItm(false);
206
207 if ($this->item_facade->isEmpty()) {
208 $type = $this->unhash((string) ($data[self::F_TYPE][0]));
209 $this->item_facade->setType($type);
210 $r->createItem($this->item_facade);
211 }
212
213 if ($this->item_facade->supportsCustomIcon()) {
214 $icon = (string) ($data[self::F_ICON][0] ?? '');
215 $this->item_facade->setIconID($icon);
216 }
217
218 if ($this->item_facade->isCustom()) {
219 $type = $this->item_facade->getType();
220 $type_specific_data = (array) $data[self::F_TYPE][1];
221 $type_handler = $this->repository->getTypeHandlerForType($type);
222 $type_handler->saveFormFields($this->item_facade->identification(), $type_specific_data);
223 }
224
225 $r->updateItem($this->item_facade);
226
227 return true;
228 }

References $data, F_ROLE_BASED_VISIBILITY, ILIAS\Repository\form(), and ILIAS\UI\examples\Deck\repository().

+ Here is the call graph for this function:

Field Documentation

◆ $form

Standard ilMMSubitemFormGUI::$form
private

Definition at line 46 of file class.ilMMSubitemFormGUI.php.

Referenced by get().

◆ F_ACTIVE

const ilMMSubitemFormGUI::F_ACTIVE = "active"

Definition at line 42 of file class.ilMMSubitemFormGUI.php.

Referenced by initForm().

◆ F_ICON

const ilMMSubitemFormGUI::F_ICON = "icon"

Definition at line 43 of file class.ilMMSubitemFormGUI.php.

Referenced by initForm().

◆ F_PARENT

const ilMMSubitemFormGUI::F_PARENT = "parent"

Definition at line 41 of file class.ilMMSubitemFormGUI.php.

Referenced by initForm().

◆ F_ROLE_BASED_VISIBILITY

const ilMMSubitemFormGUI::F_ROLE_BASED_VISIBILITY = "role_based_visibility"

Definition at line 44 of file class.ilMMSubitemFormGUI.php.

Referenced by initForm(), and save().

◆ F_TITLE

const ilMMSubitemFormGUI::F_TITLE = "title"

Definition at line 39 of file class.ilMMSubitemFormGUI.php.

Referenced by initForm().

◆ F_TYPE

const ilMMSubitemFormGUI::F_TYPE = "type"

Definition at line 40 of file class.ilMMSubitemFormGUI.php.

Referenced by initForm().


The documentation for this class was generated from the following file: