ILIAS  release_8 Revision v8.24
ilMMTopItemFormGUI Class Reference

Class ilMMTopItemFormGUI. More...

+ Collaboration diagram for ilMMTopItemFormGUI:

Public Member Functions

 __construct (ilCtrl $ctrl, Factory $ui_fa, Renderer $ui_re, ilLanguage $lng, Services $http, ilMMItemFacadeInterface $item, 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"
 

Protected Attributes

ilLanguage $lng
 
ilCtrl $ctrl
 
ILIAS UI Factory $ui_fa
 
ILIAS UI Renderer $ui_re
 

Private Member Functions

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

Private Attributes

const F_ICON = 'icon'
 
Services $http
 
ilMMItemRepository $repository
 
Standard $form
 
ilMMItemFacadeInterface $item_facade
 
ilObjMainMenuAccess $access
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilMMTopItemFormGUI::__construct ( ilCtrl  $ctrl,
Factory  $ui_fa,
Renderer  $ui_re,
ilLanguage  $lng,
Services  $http,
ilMMItemFacadeInterface  $item,
ilMMItemRepository  $repository 
)

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

76 {
77 $this->repository = $repository;
78 $this->http = $http;
79 $this->ctrl = $ctrl;
80 $this->ui_fa = $ui_fa;
81 $this->ui_re = $ui_re;
82 $this->lng = $lng;
83 $this->item_facade = $item;
84 $this->access = new ilObjMainMenuAccess();
85 if (!$this->item_facade->isEmpty()) {
86 $this->ctrl->saveParameterByClass(ilMMTopItemGUI::class, ilMMAbstractItemGUI::IDENTIFIER);
87 }
88
89 $this->initForm();
90 }
ilMMItemRepository $repository
Class ilObjMainMenuAccess.
static http()
Fetches the global http state from ILIAS.

References $ctrl, $http, $lng, $repository, $ui_fa, $ui_re, ILIAS\Repository\access(), ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), ilMMAbstractItemGUI\IDENTIFIER, initForm(), ILIAS\Repository\lng(), and ILIAS\UI\examples\Deck\repository().

+ Here is the call graph for this function:

Member Function Documentation

◆ getHTML()

ilMMTopItemFormGUI::getHTML ( )
Returns
string

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

231 : string
232 {
233 return $this->ui_re->render([$this->form]);
234 }
form( $class_path, string $cmd)

References ILIAS\Repository\form().

+ Here is the call graph for this function:

◆ getTypeGroups()

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

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

240 : array
241 {
242 $type_groups = [];
243 $type_informations = $this->repository->getPossibleTopItemTypesWithInformation($new);
244 foreach ($type_informations as $classname => $information) {
245 if ($this->item_facade->isEmpty()
246 || (!$this->item_facade->isEmpty() && $classname === $this->item_facade->getType() && $this->item_facade->isCustom())
247 ) { // https://mantis.ilias.de/view.php?id=24152
248 $inputs = $this->repository->getTypeHandlerForType($classname)->getAdditionalFieldsForSubForm($this->item_facade->identification());
249 $type_groups[$this->hash($classname)] = $f()->field()->group(
250 $inputs,
251 $information->getTypeNameForPresentation()
252 );
253 }
254 }
255
256 return $type_groups;
257 }

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 92 of file class.ilMMTopItemFormGUI.php.

92 : void
93 {
94 $txt = function ($key) {
95 return $this->lng->txt($key);
96 };
97 $f = function (): InputFactory {
98 return $this->ui_fa->input();
99 };
100
101 // TITLE
102 $title = $f()->field()->text($txt('topitem_title_default'), $txt('topitem_title_default_byline'))
103 ->withRequired(true);
104 if (!$this->item_facade->isEmpty()) {
105 $title = $title->withValue($this->item_facade->getDefaultTitle());
106 }
107
108 $items[self::F_TITLE] = $title;
109
110 if ($this->item_facade->supportsCustomIcon()) {
111 // ICON
112 $icon = $f()->field()->file(new ilMMUploadHandlerGUI(), $txt('topitem_icon'))
113 ->withByline($txt('topitem_icon_byline'))
114 ->withAcceptedMimeTypes([MimeType::IMAGE__SVG_XML]);
115 if ($this->item_facade->getIconID() !== null) {
116 $icon = $icon->withValue([$this->item_facade->getIconID()]);
117 }
118
119 $items[self::F_ICON] = $icon;
120 }
121
122 // TYPE
123 if (($this->item_facade->isEmpty() || $this->item_facade->isCustom())) {
124 $type_groups = $this->getTypeGroups($f, $this->item_facade->isEmpty());
125 $type = $f()->field()->switchableGroup(
126 $type_groups,
127 $txt('topitem_type'),
128 $txt('topitem_type_byline')
129 )->withRequired(true);
130 if (!$this->item_facade->isEmpty()) {
131 $string = $this->item_facade->getType() === '' ? TopParentItem::class : $this->item_facade->getType();
132 $type = $type->withValue($this->hash($string));
133 } else {
134 $type = $type->withValue($this->hash(TopParentItem::class));
135 }
136 $items[self::F_TYPE] = $type;
137 }
138
139 // ACTIVE
140 $active = $f()->field()->checkbox($txt('topitem_active'), $txt('topitem_active_byline'));
141 $active = $active->withValue($this->item_facade->isActivated());
142 $items[self::F_ACTIVE] = $active;
143
144 // ROLE BASED VISIBILITY
145 if ($this->item_facade->supportsRoleBasedVisibility()) {
146 $value_role_based_visibility = null;
147 $global_roles = $this->access->getGlobalRoles();
148 $global_role_ids = $this->item_facade->getGlobalRoleIDs();
149 if ($this->item_facade->hasRoleBasedVisibility() && !empty($global_role_ids)) {
150 // remove deleted roles, see https://mantis.ilias.de/view.php?id=34936
151 $value_role_based_visibility[0] = array_intersect(
152 $global_role_ids,
153 array_keys($global_roles)
154 );
155 }
156 $role_based_visibility = $f()->field()->optionalGroup(
157 [
158 $f()->field()->multiSelect(
159 $txt('sub_global_roles'),
160 $global_roles
161 )->withRequired(false)
162 ],
163 $txt('sub_role_based_visibility'),
164 $txt('sub_role_based_visibility_byline')
165 )->withValue($value_role_based_visibility);
166 $items[self::F_ROLE_BASED_VISIBILITY] = $role_based_visibility;
167 }
168
169 // RETURN FORM
170 if ($this->item_facade->isEmpty()) {
171 $section = $f()->field()->section($items, $txt(ilMMTopItemGUI::CMD_ADD), "");
172 $this->form = $f()->container()->form()->standard($this->ctrl->getLinkTargetByClass(
173 ilMMTopItemGUI::class,
175 ), [$section]);
176 } else {
177 $section = $f()->field()->section($items, $txt(ilMMTopItemGUI::CMD_EDIT), "");
178 $this->form = $f()->container()->form()->standard($this->ctrl->getLinkTargetByClass(
179 ilMMTopItemGUI::class,
181 ), [$section]);
182 }
183 }
const F_ACTIVE
ilMMTopItemFormGUI constructor.
getTypeGroups(Closure $f, bool $new)
Class ilMMUploadHandlerGUI.
$txt
Definition: error.php:13
string $key
Consumer key/client ID value.
Definition: System.php:193
$type

References Vendor\Package\$f, ILIAS\LTI\ToolProvider\$key, $txt, $type, ILIAS\Repository\access(), ilMMTopItemGUI\CMD_ADD, ilMMTopItemGUI\CMD_CREATE, ilMMTopItemGUI\CMD_EDIT, ilMMTopItemGUI\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 185 of file class.ilMMTopItemFormGUI.php.

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

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

+ Here is the call graph for this function:

Field Documentation

◆ $access

ilObjMainMenuAccess ilMMTopItemFormGUI::$access
private

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

◆ $ctrl

ilCtrl ilMMTopItemFormGUI::$ctrl
protected

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

Referenced by __construct().

◆ $form

Standard ilMMTopItemFormGUI::$form
private

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

◆ $http

Services ilMMTopItemFormGUI::$http
private

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

Referenced by __construct().

◆ $item_facade

ilMMItemFacadeInterface ilMMTopItemFormGUI::$item_facade
private

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

◆ $lng

ilLanguage ilMMTopItemFormGUI::$lng
protected

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

Referenced by __construct().

◆ $repository

ilMMItemRepository ilMMTopItemFormGUI::$repository
private

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

Referenced by __construct().

◆ $ui_fa

ILIAS UI Factory ilMMTopItemFormGUI::$ui_fa
protected

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

Referenced by __construct().

◆ $ui_re

ILIAS UI Renderer ilMMTopItemFormGUI::$ui_re
protected

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

Referenced by __construct().

◆ F_ACTIVE

const ilMMTopItemFormGUI::F_ACTIVE = 'active'

ilMMTopItemFormGUI constructor.

Parameters
ilCtrl$ctrl
Factory$ui_fa
Renderer$ui_re

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

Referenced by initForm().

◆ F_ICON

const ilMMTopItemFormGUI::F_ICON = 'icon'
private

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

Referenced by initForm().

◆ F_ROLE_BASED_VISIBILITY

const ilMMTopItemFormGUI::F_ROLE_BASED_VISIBILITY = "role_based_visibility"

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

Referenced by initForm().

◆ F_TITLE

const ilMMTopItemFormGUI::F_TITLE = 'title'

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

Referenced by initForm().

◆ F_TYPE

const ilMMTopItemFormGUI::F_TYPE = 'type'

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

Referenced by initForm().


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