ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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'
 

Protected Attributes

 $lng
 
 $ctrl
 
 $ui_fa
 
 $ui_re
 

Private Member Functions

 initForm ()
 

Private Attributes

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

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

62  {
63  $this->repository = $repository;
64  $this->http = $http;
65  $this->ctrl = $ctrl;
66  $this->ui_fa = $ui_fa;
67  $this->ui_re = $ui_re;
68  $this->lng = $lng;
69  $this->item_facade = $item;
70  if (!$this->item_facade->isEmpty()) {
71  $this->ctrl->saveParameterByClass(ilMMTopItemGUI::class, ilMMTopItemGUI::IDENTIFIER);
72  }
73 
74  $this->initForm();
75  }
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 174 of file class.ilMMTopItemFormGUI.php.

174  : string
175  {
176  return $this->ui_re->render([$this->form]);
177  }

◆ initForm()

ilMMTopItemFormGUI::initForm ( )
private

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

References $f, $key, $section, $title, $txt, $type, ilMMTopItemGUI\CMD_ADD, ilMMTopItemGUI\CMD_CREATE, ilMMTopItemGUI\CMD_EDIT, ilMMTopItemGUI\CMD_UPDATE, GuzzleHttp\Psr7\hash(), and repository().

Referenced by __construct().

79  {
80  $txt = function ($key) {
81  return $this->lng->txt($key);
82  };
83  $f = function () : InputFactory {
84  return $this->ui_fa->input();
85  };
86 
87  // TITLE
88  $title = $f()->field()->text($txt('topitem_title_default'), $txt('topitem_title_default_byline'))
89  ->withRequired(true);
90  if (!$this->item_facade->isEmpty()) {
91  $title = $title->withValue($this->item_facade->getDefaultTitle());
92  }
93 
94  $items[self::F_TITLE] = $title;
95 
96  // TYPE
97  $type = $f()->field()->radio($txt('topitem_type'), $txt('topitem_type_byline'))->withRequired(true);
98  $type_informations = $this->repository->getPossibleTopItemTypesWithInformation();
99 
100  $type_i = 0;
101  foreach ($type_informations as $classname => $information) {
102  if ($this->item_facade->isEmpty()
103  || (!$this->item_facade->isEmpty() && $classname === $this->item_facade->getType() && $this->item_facade->isCustom())
104  ) { // https://mantis.ilias.de/view.php?id=24152
105  $inputs = $this->repository->getTypeHandlerForType($classname)->getAdditionalFieldsForSubForm($this->item_facade->identification());
106  $type = $type->withOption($this->hash($classname), $information->getTypeNameForPresentation(), $information->getTypeBylineForPresentation(), $inputs);
107  $type_i++;
108  }
109  }
110 
111  if (!$this->item_facade->isEmpty() && $this->item_facade->isCustom()) {
112  $type = $type->withValue($this->hash($this->item_facade->getType()));
113  } elseif ($this->item_facade->isCustom()) {
114  $type = $type->withValue($this->hash(reset(array_keys($type_informations))));
115  }
116 
117  if (($this->item_facade->isEmpty() || $this->item_facade->isCustom()) && $type_i > 0) {
118  $items[self::F_TYPE] = $type;
119  }
120 
121  // ACTIVE
122  $active = $f()->field()->checkbox($txt('topitem_active'), $txt('topitem_active_byline'));
123  if (!$this->item_facade->isEmpty()) {
124  $active = $active->withValue($this->item_facade->isAvailable());
125  }
126  $items[self::F_ACTIVE] = $active;
127 
128  // RETURN FORM
129  if ($this->item_facade->isEmpty()) {
130  $section = $f()->field()->section($items, $txt(ilMMTopItemGUI::CMD_ADD), "");
131  $this->form = $f()->container()->form()->standard($this->ctrl->getLinkTargetByClass(ilMMTopItemGUI::class, ilMMTopItemGUI::CMD_CREATE), [$section]);
132  } else {
133  $section = $f()->field()->section($items, $txt(ilMMTopItemGUI::CMD_EDIT), "");
134  $this->form = $f()->container()->form()->standard($this->ctrl->getLinkTargetByClass(ilMMTopItemGUI::class, ilMMTopItemGUI::CMD_UPDATE), [$section]);
135  }
136  }
$type
$section
Definition: Utf8Test.php:83
repository()
Definition: repository.php:5
$txt
Definition: error.php:11
hash(StreamInterface $stream, $algo, $rawOutput=false)
Calculate a hash of a Stream.
Definition: functions.php:406
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ save()

ilMMTopItemFormGUI::save ( )

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

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

140  {
141  $this->form = $this->form->withRequest($this->http->request());
142  $data = $this->form->getData();
143  if (is_null($data)) {
144  return false;
145  }
146 
147  $this->item_facade->setAction((string) $data[0]['action']);
148  $this->item_facade->setDefaultTitle((string) $data[0][self::F_TITLE]);
149  $this->item_facade->setActiveStatus((bool) $data[0][self::F_ACTIVE]);
150  $this->item_facade->setIsTopItm(true);
151 
152  if ($this->item_facade->isEmpty()) {
153  $type = $this->unhash((string) ($data[0][self::F_TYPE]['value']));
154  $this->item_facade->setType($type);
155  $this->repository->createItem($this->item_facade);
156  }
157 
158  if ($this->item_facade->isCustom()) {
159  $type = $this->item_facade->getType();
160  $type_specific_data = (array) $data[0][self::F_TYPE]['group_values'];
161  $type_handler = $this->repository->getTypeHandlerForType($type);
162  $type_handler->saveFormFields($this->item_facade->identification(), $type_specific_data);
163  }
164 
165  $this->repository->updateItem($this->item_facade);
166 
167  return true;
168  }
$type
static http()
Fetches the global http state from ILIAS.
repository()
Definition: repository.php:5
$data
Definition: bench.php:6
+ Here is the call graph for this function:

Field Documentation

◆ $ctrl

ilMMTopItemFormGUI::$ctrl
protected

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

Referenced by __construct().

◆ $form

ilMMTopItemFormGUI::$form
private

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

◆ $http

ilMMTopItemFormGUI::$http
private

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

Referenced by __construct().

◆ $item_facade

ilMMTopItemFormGUI::$item_facade
private

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

◆ $lng

ilMMTopItemFormGUI::$lng
protected

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

Referenced by __construct().

◆ $repository

ilMMTopItemFormGUI::$repository
private

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

Referenced by __construct().

◆ $ui_fa

ilMMTopItemFormGUI::$ui_fa
protected

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

Referenced by __construct().

◆ $ui_re

ilMMTopItemFormGUI::$ui_re
protected

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

◆ F_TITLE

const ilMMTopItemFormGUI::F_TITLE = 'title'

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

◆ F_TYPE

const ilMMTopItemFormGUI::F_TYPE = 'type'

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


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