ILIAS  release_7 Revision v7.30-3-g800a261c036
ilMMTopItemFormGUI Class Reference

Class ilMMTopItemFormGUI. More...

+ Collaboration diagram for ilMMTopItemFormGUI:

Public Member Functions

 __construct (ilCtrl $ctrl, Factory $ui_fa, Renderer $ui_re, ilLanguage $lng, \ILIAS\DI\HTTPServices $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

 $lng
 
 $ctrl
 
 $ui_fa
 
 $ui_re
 

Private Member Functions

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

Private Attributes

const F_ICON = 'icon'
 
 $http
 
 $repository
 
 $form
 
 $item_facade
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

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

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

References $ctrl, $http, $lng, $repository, $ui_fa, $ui_re, ILIAS\FileDelivery\http(), ilMMAbstractItemGUI\IDENTIFIER, initForm(), and repository().

70  {
71  $this->repository = $repository;
72  $this->http = $http;
73  $this->ctrl = $ctrl;
74  $this->ui_fa = $ui_fa;
75  $this->ui_re = $ui_re;
76  $this->lng = $lng;
77  $this->item_facade = $item;
78  if (!$this->item_facade->isEmpty()) {
79  $this->ctrl->saveParameterByClass(ilMMTopItemGUI::class, ilMMTopItemGUI::IDENTIFIER);
80  }
81 
82  $this->initForm();
83  }
static http()
Fetches the global http state from ILIAS.
repository()
Definition: repository.php:5
+ Here is the call graph for this function:

Member Function Documentation

◆ getHTML()

ilMMTopItemFormGUI::getHTML ( )
Returns
string

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

223  : string
224  {
225  return $this->ui_re->render([$this->form]);
226  }

◆ getTypeGroups()

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

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

References Vendor\Package\$f, and repository().

Referenced by initForm().

232  : array
233  {
234  $type_groups = [];
235  $type_informations = $this->repository->getPossibleTopItemTypesWithInformation($new);
236  foreach ($type_informations as $classname => $information) {
237  if ($this->item_facade->isEmpty()
238  || (!$this->item_facade->isEmpty() && $classname === $this->item_facade->getType() && $this->item_facade->isCustom())
239  ) { // https://mantis.ilias.de/view.php?id=24152
240  $inputs = $this->repository->getTypeHandlerForType($classname)->getAdditionalFieldsForSubForm($this->item_facade->identification());
241  $type_groups[$this->hash($classname)] = $f()->field()->group($inputs,
242  $information->getTypeNameForPresentation());
243  }
244  }
245 
246  return $type_groups;
247  }
repository()
Definition: repository.php:5
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initForm()

ilMMTopItemFormGUI::initForm ( )
private

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

References Vendor\Package\$f, $section, $txt, $type, ilMMTopItemGUI\CMD_ADD, ilMMTopItemGUI\CMD_CREATE, ilMMTopItemGUI\CMD_EDIT, ilMMTopItemGUI\CMD_UPDATE, getTypeGroups(), ilMimeTypeUtil\IMAGE__SVG_XML, and ilMMUploadHandlerGUI\MAX_FILE_SIZE.

Referenced by __construct().

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

◆ save()

ilMMTopItemFormGUI::save ( )

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

References $data, $type, ILIAS\FileDelivery\http(), and repository().

178  {
179  $this->form = $this->form->withRequest($this->http->request());
180  $data = $this->form->getData();
181  if (is_null($data)) {
182  return false;
183  }
184 
185  $this->item_facade->setAction((string) $data[0]['action']);
186  $this->item_facade->setDefaultTitle((string) $data[0][self::F_TITLE]);
187  $this->item_facade->setActiveStatus((bool) $data[0][self::F_ACTIVE]);
188  if ($this->item_facade->supportsRoleBasedVisibility()) {
189  $this->item_facade->setRoleBasedVisibility((bool) $data[0][self::F_ROLE_BASED_VISIBILITY]);
190  if ((bool) $data[0][self::F_ROLE_BASED_VISIBILITY] and (bool) !empty($data[0][self::F_ROLE_BASED_VISIBILITY])) {
191  $this->item_facade->setGlobalRoleIDs((array) $data[0][self::F_ROLE_BASED_VISIBILITY][0]);
192  }
193  }
194 
195  $this->item_facade->setIsTopItm(true);
196 
197  if ($this->item_facade->isEmpty()) {
198  $type = $this->unhash((string) ($data[0][self::F_TYPE][0]));
199  $this->item_facade->setType($type);
200  $this->repository->createItem($this->item_facade);
201  }
202 
203  if ($this->item_facade->supportsCustomIcon()) {
204  $icon = (string) $data[0][self::F_ICON][0];
205  $this->item_facade->setIconID($icon);
206  }
207 
208  if ($this->item_facade->isCustom()) {
209  $type = $this->item_facade->getType();
210  $type_specific_data = (array) $data[0][self::F_TYPE][1];
211  $type_handler = $this->repository->getTypeHandlerForType($type);
212  $type_handler->saveFormFields($this->item_facade->identification(), $type_specific_data);
213  }
214 
215  $this->repository->updateItem($this->item_facade);
216 
217  return true;
218  }
$data
Definition: storeScorm.php:23
$type
static http()
Fetches the global http state from ILIAS.
repository()
Definition: repository.php:5
+ Here is the call graph for this function:

Field Documentation

◆ $ctrl

ilMMTopItemFormGUI::$ctrl
protected

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

Referenced by __construct().

◆ $form

ilMMTopItemFormGUI::$form
private

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

◆ $http

ilMMTopItemFormGUI::$http
private

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

Referenced by __construct().

◆ $item_facade

ilMMTopItemFormGUI::$item_facade
private

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

◆ $lng

ilMMTopItemFormGUI::$lng
protected

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

Referenced by __construct().

◆ $repository

ilMMTopItemFormGUI::$repository
private

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

Referenced by __construct().

◆ $ui_fa

ilMMTopItemFormGUI::$ui_fa
protected

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

Referenced by __construct().

◆ $ui_re

ilMMTopItemFormGUI::$ui_re
protected

Definition at line 50 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 57 of file class.ilMMTopItemFormGUI.php.

◆ F_ICON

const ilMMTopItemFormGUI::F_ICON = 'icon'
private

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

◆ F_ROLE_BASED_VISIBILITY

const ilMMTopItemFormGUI::F_ROLE_BASED_VISIBILITY = "role_based_visibility"

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

◆ F_TITLE

const ilMMTopItemFormGUI::F_TITLE = 'title'

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

◆ F_TYPE

const ilMMTopItemFormGUI::F_TYPE = 'type'

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


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