ILIAS  trunk Revision v11.0_alpha-1866-gfa368f7776e
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 ilLanguage $lng, private Services $http, private ilMMItemFacadeInterface $item_facade, private ilMMItemRepository $repository)
 
 save ()
 
 getHTML ()
 

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 ilLanguage  $lng,
private Services  $http,
private ilMMItemFacadeInterface  $item_facade,
private ilMMItemRepository  $repository 
)

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

References ILIAS\Repository\access(), ILIAS\Repository\ctrl(), ilMMAbstractItemGUI\IDENTIFIER, and initForm().

65  {
66  $this->access = new ilObjMainMenuAccess();
67  if (!$this->item_facade->isEmpty()) {
68  $this->ctrl->saveParameterByClass(ilMMTopItemGUI::class, ilMMAbstractItemGUI::IDENTIFIER);
69  }
70 
71  $this->initForm();
72  }
+ Here is the call graph for this function:

Member Function Documentation

◆ getHTML()

ilMMTopItemFormGUI::getHTML ( )
Returns
string

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

References ILIAS\Repository\form().

209  : string
210  {
211  return $this->ui_re->render([$this->form]);
212  }
form( $class_path, string $cmd, string $submit_caption="")
+ Here is the call graph for this function:

◆ getTypeGroups()

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

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

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

Referenced by initForm().

218  : array
219  {
220  $type_groups = [];
221  $type_informations = $this->repository->getPossibleTopItemTypesWithInformation($new);
222  foreach ($type_informations as $classname => $information) {
223  if ($this->item_facade->isEmpty()
224  || (!$this->item_facade->isEmpty() && $classname === $this->item_facade->getType() && $this->item_facade->isCustom())
225  ) { // https://mantis.ilias.de/view.php?id=24152
226  $inputs = $this->repository->getTypeHandlerForType($classname)->getAdditionalFieldsForSubForm($this->item_facade->identification());
227  $type_groups[$this->hash($classname)] = $f()->field()->group(
228  $inputs,
229  $information->getTypeNameForPresentation()
230  );
231  }
232  }
233 
234  return $type_groups;
235  }
repository()
description: > Example for rendering a repository card
Definition: repository.php:33
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initForm()

ilMMTopItemFormGUI::initForm ( )
private

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

References Vendor\Package\$f, $txt, ILIAS\Repository\access(), ilMMTopItemGUI\CMD_ADD, ilMMTopItemGUI\CMD_CREATE, ilMMTopItemGUI\CMD_EDIT, ilMMTopItemGUI\CMD_UPDATE, ILIAS\Repository\ctrl(), ILIAS\Repository\form(), getTypeGroups(), ILIAS\Repository\lng(), and null.

Referenced by __construct().

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

◆ save()

ilMMTopItemFormGUI::save ( )

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

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

163  : bool
164  {
165  $this->form = $this->form->withRequest($this->http->request());
166  $data = $this->form->getData();
167  if (is_null($data)) {
168  return false;
169  }
170 
171  $this->item_facade->setAction((string) ($data[0]['action'] ?? ''));
172  $this->item_facade->setDefaultTitle((string) $data[0][self::F_TITLE]);
173  $this->item_facade->setActiveStatus((bool) $data[0][self::F_ACTIVE]);
174  if ($this->item_facade->supportsRoleBasedVisibility()) {
175  $this->item_facade->setRoleBasedVisibility((bool) $data[0][self::F_ROLE_BASED_VISIBILITY]);
176  if ($data[0][self::F_ROLE_BASED_VISIBILITY] && !empty($data[0][self::F_ROLE_BASED_VISIBILITY])) {
177  $this->item_facade->setGlobalRoleIDs((array) $data[0][self::F_ROLE_BASED_VISIBILITY][0]);
178  }
179  }
180 
181  $this->item_facade->setIsTopItm(true);
182 
183  if ($this->item_facade->isEmpty()) {
184  $type = $this->unhash((string) ($data[0][self::F_TYPE][0]));
185  $this->item_facade->setType($type);
186  $this->repository->createItem($this->item_facade);
187  }
188 
189  if ($this->item_facade->supportsCustomIcon()) {
190  $icon = (string) ($data[0][self::F_ICON][0] ?? '');
191  $this->item_facade->setIconID($icon);
192  }
193 
194  if ($this->item_facade->isCustom()) {
195  $type = $this->item_facade->getType();
196  $type_specific_data = (array) $data[0][self::F_TYPE][1];
197  $type_handler = $this->repository->getTypeHandlerForType($type);
198  $type_handler->saveFormFields($this->item_facade->identification(), $type_specific_data);
199  }
200 
201  $this->repository->updateItem($this->item_facade);
202 
203  return true;
204  }
repository()
description: > Example for rendering a repository card
Definition: repository.php:33
static http()
Fetches the global http state from ILIAS.
form( $class_path, string $cmd, string $submit_caption="")
+ Here is the call graph for this function:

Field Documentation

◆ $access

ilObjMainMenuAccess ilMMTopItemFormGUI::$access
private

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

◆ $form

Standard ilMMTopItemFormGUI::$form
private

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

◆ F_ACTIVE

const ilMMTopItemFormGUI::F_ACTIVE = 'active'

ilMMTopItemFormGUI constructor.

Parameters
ilCtrl$ctrl
Factory$ui_fa
Renderer$ui_re

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

◆ F_ICON

const ilMMTopItemFormGUI::F_ICON = 'icon'
private

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

◆ F_ROLE_BASED_VISIBILITY

const ilMMTopItemFormGUI::F_ROLE_BASED_VISIBILITY = "role_based_visibility"

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

◆ F_TITLE

const ilMMTopItemFormGUI::F_TITLE = 'title'

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

◆ F_TYPE

const ilMMTopItemFormGUI::F_TYPE = 'type'

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


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