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

Class ilMMTopItemFormGUI. More...

+ Collaboration diagram for ilMMTopItemFormGUI:

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)
 
 save ()
 
 getHTML ()
 
 get ()
 

Data Fields

const F_ACTIVE = 'active'
 ilMMTopItemFormGUI constructor. More...
 
const F_TITLE = 'title'
 
const F_TYPE = 'type'
 
const F_ROLE_BASED_VISIBILITY = "role_based_visibility"
 

Private Member Functions

 initForm ()
 
 getTypeGroups (Closure $f, bool $new)
 

Private Attributes

const F_ICON = 'icon'
 
Standard $form
 
ilObjMainMenuAccess $access
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilMMTopItemFormGUI::__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 
)

Definition at line 58 of file class.ilMMTopItemFormGUI.php.

References ILIAS\Repository\access(), and initForm().

+ Here is the call graph for this function:

Member Function Documentation

◆ get()

ilMMTopItemFormGUI::get ( )

Definition at line 215 of file class.ilMMTopItemFormGUI.php.

215 : Standard
216 {
217 return $this->form;
218 }
This describes a standard form.
Definition: Standard.php:29

References $form.

◆ getHTML()

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

Definition at line 210 of file class.ilMMTopItemFormGUI.php.

210 : string
211 {
212 return $this->ui_re->render([$this->form]);
213 }
form( $class_path, string $cmd, string $submit_caption="")

References ILIAS\Repository\form().

+ Here is the call graph for this function:

◆ getTypeGroups()

ilMMTopItemFormGUI::getTypeGroups ( Closure  $f,
bool  $new 
)
private

Definition at line 220 of file class.ilMMTopItemFormGUI.php.

220 : array
221 {
222 $type_groups = [];
223 $type_informations = $this->repository->getPossibleTopItemTypesWithInformation($new);
224 foreach ($type_informations as $classname => $information) {
225 if ($this->item_facade->isEmpty()
226 || (!$this->item_facade->isEmpty() && $classname === $this->item_facade->getType(
227 ) && $this->item_facade->isCustom())
228 ) { // https://mantis.ilias.de/view.php?id=24152
229 $inputs = $this->repository->getTypeHandlerForType($classname)->getAdditionalFieldsForSubForm(
230 $this->item_facade->identification()
231 );
232 $type_groups[$this->hash($classname)] = $f()->field()->group(
233 $inputs,
234 $information->getTypeNameForPresentation()
235 );
236 }
237 }
238
239 return $type_groups;
240 }

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()

ilMMTopItemFormGUI::initForm ( )
private

Definition at line 71 of file class.ilMMTopItemFormGUI.php.

71 : void
72 {
73 $txt = (fn($key): string => $this->lng->txt($key));
74 $f = (fn(): InputFactory => $this->ui_fa->input());
75
76 // TITLE
77 $title = $f()->field()->text($txt('topitem_title_default'), $txt('topitem_title_default_byline'))
78 ->withRequired(true);
79 if (!$this->item_facade->isEmpty()) {
80 $title = $title->withValue($this->item_facade->getDefaultTitle());
81 }
82
83 $items[self::F_TITLE] = $title;
84
85 if ($this->item_facade->supportsCustomIcon()) {
86 // ICON
87 $icon = $f()->field()->file(new ilMMUploadHandlerGUI(), $txt('topitem_icon'))
88 ->withByline($txt('topitem_icon_byline'))
89 ->withAcceptedMimeTypes([MimeType::IMAGE__SVG_XML]);
90 if ($this->item_facade->getIconID() !== null) {
91 $icon = $icon->withValue([$this->item_facade->getIconID()]);
92 }
93
94 $items[self::F_ICON] = $icon;
95 }
96
97 // TYPE
98 if (($this->item_facade->isEmpty() || $this->item_facade->isCustom())) {
99 $type_groups = $this->getTypeGroups($f, $this->item_facade->isEmpty());
100 $type = $f()->field()->switchableGroup(
101 $type_groups,
102 $txt('topitem_type'),
103 $txt('topitem_type_byline')
104 )->withRequired(true);
105 if (!$this->item_facade->isEmpty()) {
106 $string = $this->item_facade->getType() === '' ? TopParentItem::class : $this->item_facade->getType();
107 $type = $type->withValue($this->hash($string));
108 } else {
109 $type = $type->withValue($this->hash(TopParentItem::class));
110 }
111 $items[self::F_TYPE] = $type;
112 }
113
114 // ACTIVE
115 $active = $f()->field()->checkbox($txt('topitem_active'), $txt('topitem_active_byline'));
116 $active = $active->withValue($this->item_facade->isActivated());
117 $items[self::F_ACTIVE] = $active;
118
119 // ROLE BASED VISIBILITY
120 if ($this->item_facade->supportsRoleBasedVisibility()) {
121 $value_role_based_visibility = null;
122 $global_roles = $this->access->getGlobalRoles();
123 $global_role_ids = $this->item_facade->getGlobalRoleIDs();
124 if ($this->item_facade->hasRoleBasedVisibility() && !empty($global_role_ids)) {
125 // remove deleted roles, see https://mantis.ilias.de/view.php?id=34936
126 $value_role_based_visibility[0] = array_intersect(
127 $global_role_ids,
128 array_keys($global_roles)
129 );
130 }
131 $role_based_visibility = $f()->field()->optionalGroup(
132 [
133 $f()->field()->multiSelect(
134 $txt('sub_global_roles'),
135 $global_roles
136 )->withRequired(false)
137 ],
138 $txt('sub_role_based_visibility'),
139 $txt('sub_role_based_visibility_byline')
140 )->withValue($value_role_based_visibility);
141 $items[self::F_ROLE_BASED_VISIBILITY] = $role_based_visibility;
142 }
143
144 // RETURN FORM
145 if ($this->item_facade->isEmpty()) {
146 $this->form = $f()->container()->form()->standard(
147 $this->ctrl->getLinkTargetByClass(
148 ilMMTopItemGUI::class,
150 ),
151 $items
152 );
153 } else {
154 $this->form = $f()->container()->form()->standard(
155 $this->ctrl->getLinkTargetByClass(
156 ilMMTopItemGUI::class,
158 ),
159 $items
160 );
161 }
162 }
const F_ACTIVE
ilMMTopItemFormGUI constructor.
getTypeGroups(Closure $f, bool $new)
Class ilMMUploadHandlerGUI.
$txt
Definition: error.php:31

References Vendor\Package\$f, $txt, ILIAS\Repository\access(), ilMMBaseGUI\CMD_CREATE, ilMMBaseGUI\CMD_UPDATE, ILIAS\Repository\ctrl(), F_ACTIVE, F_ICON, F_ROLE_BASED_VISIBILITY, F_TITLE, F_TYPE, ILIAS\Repository\form(), getTypeGroups(), and ILIAS\Repository\lng().

Referenced by __construct().

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

◆ save()

ilMMTopItemFormGUI::save ( )

Definition at line 164 of file class.ilMMTopItemFormGUI.php.

164 : bool
165 {
166 $this->form = $this->form->withRequest($this->request);
167 $data = $this->form->getData();
168 if (is_null($data)) {
169 return false;
170 }
171
172 $this->item_facade->setAction((string) ($data['action'] ?? ''));
173 $this->item_facade->setDefaultTitle((string) $data[self::F_TITLE]);
174 $this->item_facade->setActiveStatus((bool) $data[self::F_ACTIVE]);
175 if ($this->item_facade->supportsRoleBasedVisibility()) {
176 $this->item_facade->setRoleBasedVisibility((bool) $data[self::F_ROLE_BASED_VISIBILITY]);
177 if ($data[self::F_ROLE_BASED_VISIBILITY] && !empty($data[self::F_ROLE_BASED_VISIBILITY])) {
178 $this->item_facade->setGlobalRoleIDs((array) $data[self::F_ROLE_BASED_VISIBILITY][0]);
179 }
180 }
181
182 $this->item_facade->setIsTopItm(true);
183
184 if ($this->item_facade->isEmpty()) {
185 $type = $this->unhash((string) ($data[self::F_TYPE][0]));
186 $this->item_facade->setType($type);
187 $this->repository->createItem($this->item_facade);
188 }
189
190 if ($this->item_facade->supportsCustomIcon()) {
191 $icon = (string) ($data[self::F_ICON][0] ?? '');
192 $this->item_facade->setIconID($icon);
193 }
194
195 if ($this->item_facade->isCustom()) {
196 $type = $this->item_facade->getType();
197 $type_specific_data = (array) $data[self::F_TYPE][1];
198 $type_handler = $this->repository->getTypeHandlerForType($type);
199 $type_handler->saveFormFields($this->item_facade->identification(), $type_specific_data);
200 }
201
202 $this->repository->updateItem($this->item_facade);
203
204 return true;
205 }

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

+ Here is the call graph for this function:

Field Documentation

◆ $access

ilObjMainMenuAccess ilMMTopItemFormGUI::$access
private

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

◆ $form

Standard ilMMTopItemFormGUI::$form
private

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

Referenced by get().

◆ F_ACTIVE

const ilMMTopItemFormGUI::F_ACTIVE = 'active'

ilMMTopItemFormGUI constructor.

Parameters
ilCtrl$ctrl
Factory$ui_fa
Renderer$ui_re

Definition at line 53 of file class.ilMMTopItemFormGUI.php.

Referenced by initForm().

◆ F_ICON

const ilMMTopItemFormGUI::F_ICON = 'icon'
private

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

Referenced by initForm().

◆ F_ROLE_BASED_VISIBILITY

const ilMMTopItemFormGUI::F_ROLE_BASED_VISIBILITY = "role_based_visibility"

Definition at line 56 of file class.ilMMTopItemFormGUI.php.

Referenced by initForm().

◆ F_TITLE

const ilMMTopItemFormGUI::F_TITLE = 'title'

Definition at line 54 of file class.ilMMTopItemFormGUI.php.

Referenced by initForm().

◆ F_TYPE

const ilMMTopItemFormGUI::F_TYPE = 'type'

Definition at line 55 of file class.ilMMTopItemFormGUI.php.

Referenced by initForm().


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