ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilMMSubitemFormGUI Class Reference

Class ilMMSubitemFormGUI. More...

+ Collaboration diagram for ilMMSubitemFormGUI:

Public Member Functions

 __construct (ilCtrl $ctrl, Factory $ui_fa, Renderer $ui_re, ilLanguage $lng, ilMMItemFacadeInterface $item, ilMMItemRepository $repository)
 ilMMSubitemFormGUI constructor. More...
 
 save ()
 
 getHTML ()
 

Data Fields

const F_TITLE = "title"
 
const F_TYPE = "type"
 
const F_PARENT = "parent"
 
const F_ACTIVE = "active"
 

Protected Attributes

 $lng
 
 $ctrl
 
 $ui_fa
 
 $ui_re
 

Private Member Functions

 initForm ()
 

Private Attributes

 $repository
 
 $form
 
 $item_facade
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

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

ilMMSubitemFormGUI constructor.

Parameters
ilCtrl$ctrl
Factory$ui_fa
Renderer$ui_re
ilLanguage$lng
ilMMItemFacadeInterface$item
ilMMItemRepository$repository

Definition at line 61 of file class.ilMMSubitemFormGUI.php.

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

62  {
63  $this->ctrl = $ctrl;
64  $this->ui_fa = $ui_fa;
65  $this->ui_re = $ui_re;
66  $this->lng = $lng;
67  $this->item_facade = $item;
68  $this->repository = $repository;
69  if (!$this->item_facade->isEmpty()) {
70  $this->ctrl->saveParameterByClass(ilMMSubItemGUI::class, ilMMSubItemGUI::IDENTIFIER);
71  }
72 
73  $this->initForm();
74  }
repository()
Definition: repository.php:5
+ Here is the call graph for this function:

Member Function Documentation

◆ getHTML()

ilMMSubitemFormGUI::getHTML ( )

Definition at line 183 of file class.ilMMSubitemFormGUI.php.

184  {
185  return $this->ui_re->render([$this->form]);
186  }

◆ initForm()

ilMMSubitemFormGUI::initForm ( )
private

Definition at line 77 of file class.ilMMSubitemFormGUI.php.

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

Referenced by __construct().

78  {
79  // TITLE
80  $txt = function ($id) : string {
81  return $this->lng->txt($id);
82  };
83  $f = function () : InputFactory {
84  return $this->ui_fa->input();
85  };
86 
87  $title = $f()->field()->text($txt('sub_title_default'), $txt('sub_title_default_byline'));
88  if (!$this->item_facade->isEmpty()) {
89  $title = $title->withValue($this->item_facade->getDefaultTitle());
90  }
91  $items[self::F_TITLE] = $title;
92 
93  // TYPE
94  $type = $f()->field()->radio($txt('sub_type'), $txt('sub_type_byline'))->withRequired(true);
95  $type_informations = $this->repository->getPossibleSubItemTypesWithInformation();
96 
97  foreach ($type_informations as $classname => $information) {
98  if ($this->item_facade->isEmpty()
99  || (!$this->item_facade->isEmpty() && $classname === $this->item_facade->getType() && $this->item_facade->isCustom())
100  ) { // https://mantis.ilias.de/view.php?id=24152
101  $inputs = $this->repository->getTypeHandlerForType($classname)->getAdditionalFieldsForSubForm($this->item_facade->identification());
102  $type = $type->withOption($this->hash($classname), $information->getTypeNameForPresentation(), $information->getTypeBylineForPresentation(), $inputs);
103  }
104  }
105 
106  if (!$this->item_facade->isEmpty() && $this->item_facade->isCustom()) {
107  $type = $type->withValue($this->hash($this->item_facade->getType()));
108  } elseif ($this->item_facade->isCustom()) {
109  $type = $type->withValue($this->hash(reset(array_keys($type_informations))));
110  }
111 
112  if ($this->item_facade->isEmpty() || $this->item_facade->isCustom()) {
113  $items[self::F_TYPE] = $type;
114  }
115 
116  // PARENT
117  $parent = $f()->field()->select($txt('sub_parent'), $this->repository->getPossibleParentsForFormAndTable())
118  ->withRequired(true);
119  if (!$this->item_facade->isEmpty() && !$this->item_facade->isInLostItem()) {
120  $parent = $parent->withValue($this->item_facade->getParentIdentificationString());
121  } else {
122  $parent = $parent->withValue(reset(array_keys($this->repository->getPossibleParentsForFormAndTable())));
123  }
124  $items[self::F_PARENT] = $parent;
125 
126  // ACTIVE
127  $active = $f()->field()->checkbox($txt('sub_active'), $txt('sub_active_byline'));
128  if (!$this->item_facade->isEmpty()) {
129  $active = $active->withValue($this->item_facade->isAvailable());
130  }
131  $items[self::F_ACTIVE] = $active;
132 
133  // RETURN FORM
134  if ($this->item_facade->isEmpty()) {
135  $section = $f()->field()->section($items, $txt(ilMMSubItemGUI::CMD_ADD), "");
136  $this->form = $f()->container()->form()
137  ->standard($this->ctrl->getLinkTargetByClass(ilMMSubItemGUI::class, ilMMSubItemGUI::CMD_CREATE), [$section]);
138  } else {
139  $section = $f()->field()->section($items, $txt(ilMMSubItemGUI::CMD_EDIT), "");
140  $this->form = $f()->container()->form()
141  ->standard($this->ctrl->getLinkTargetByClass(ilMMSubItemGUI::class, ilMMSubItemGUI::CMD_UPDATE), [$section]);
142  }
143  }
$type
if(!array_key_exists('StateId', $_REQUEST)) $id
$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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ save()

ilMMSubitemFormGUI::save ( )

Definition at line 146 of file class.ilMMSubitemFormGUI.php.

References $data, $DIC, $r, $type, and repository().

146  : bool
147  {
148  global $DIC;
149  $r = new ilMMItemRepository();
150  $this->form = $this->form->withRequest($DIC->http()->request());
151  $data = $this->form->getData();
152 
153  if (is_null($data)) {
154  return false;
155  }
156 
157  $this->item_facade->setAction((string) $data[0]['action']);
158  $this->item_facade->setDefaultTitle((string) $data[0][self::F_TITLE]);
159  $this->item_facade->setActiveStatus((bool) $data[0][self::F_ACTIVE]);
160  if ((string) $data[0][self::F_PARENT]) {
161  $this->item_facade->setParent((string) $data[0][self::F_PARENT]);
162  }
163  $this->item_facade->setIsTopItm(false);
164 
165  if ($this->item_facade->isEmpty()) {
166  $type = $this->unhash((string) ($data[0][self::F_TYPE]['value']));
167  $this->item_facade->setType($type);
168  $r->createItem($this->item_facade);
169  }
170  if ($this->item_facade->isCustom()) {
171  $type = $this->item_facade->getType();
172  $type_specific_data = (array) $data[0][self::F_TYPE]['group_values'];
173  $type_handler = $this->repository->getTypeHandlerForType($type);
174  $type_handler->saveFormFields($this->item_facade->identification(), $type_specific_data);
175  }
176 
177  $r->updateItem($this->item_facade);
178 
179  return true;
180  }
$type
global $DIC
Definition: saml.php:7
Class ilMMItemRepository.
$r
Definition: example_031.php:79
repository()
Definition: repository.php:5
$data
Definition: bench.php:6
+ Here is the call graph for this function:

Field Documentation

◆ $ctrl

ilMMSubitemFormGUI::$ctrl
protected

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

Referenced by __construct().

◆ $form

ilMMSubitemFormGUI::$form
private

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

◆ $item_facade

ilMMSubitemFormGUI::$item_facade
private

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

◆ $lng

ilMMSubitemFormGUI::$lng
protected

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

Referenced by __construct().

◆ $repository

ilMMSubitemFormGUI::$repository
private

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

Referenced by __construct().

◆ $ui_fa

ilMMSubitemFormGUI::$ui_fa
protected

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

Referenced by __construct().

◆ $ui_re

ilMMSubitemFormGUI::$ui_re
protected

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

Referenced by __construct().

◆ F_ACTIVE

const ilMMSubitemFormGUI::F_ACTIVE = "active"

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

◆ F_PARENT

const ilMMSubitemFormGUI::F_PARENT = "parent"

Definition at line 19 of file class.ilMMSubitemFormGUI.php.

◆ F_TITLE

const ilMMSubitemFormGUI::F_TITLE = "title"

Definition at line 17 of file class.ilMMSubitemFormGUI.php.

◆ F_TYPE

const ilMMSubitemFormGUI::F_TYPE = "type"

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


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