ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
FullEditor.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
32 use ILIAS\MetaData\Editor\Full\Services\Services as FullEditorServices;
37 
39 {
40  public const string TABLE = 'table';
41  public const string PANEL = 'panel';
42  public const string ROOT = 'root';
43  public const string FORM = 'form';
44 
47  protected FullEditorServices $services;
52 
53  public function __construct(
54  EditorDictionaryInterface $editor_dictionary,
55  NavigatorFactoryInterface $navigator_factory,
56  FullEditorServices $services,
57  FormContent $form_content,
58  TableContent $table_content,
59  PanelContent $panel_content,
60  RootContent $root_content
61  ) {
62  $this->editor_dictionary = $editor_dictionary;
63  $this->navigator_factory = $navigator_factory;
64  $this->services = $services;
65  $this->form_content = $form_content;
66  $this->table_content = $table_content;
67  $this->panel_content = $panel_content;
68  $this->root_content = $root_content;
69  }
70 
71  public function manipulateMD(): ManipulatorAdapter
72  {
73  return $this->services->manipulatorAdapter();
74  }
75 
79  public function getContent(
80  SetInterface $set,
81  PathInterface $base_path,
82  ?RequestForFormInterface $request = null
83  ): \Generator {
84  $elements = $this->getElements($set, $base_path);
85  switch ($this->decideContentType(...$elements)) {
86  case self::FORM:
87  yield from $this->form_content->content(
88  $base_path,
89  $elements[0],
90  $request
91  );
92  return;
93 
94  case self::TABLE:
95  yield from $this->table_content->content(
96  $base_path,
97  $request,
98  ...$elements
99  );
100  return;
101 
102  case self::PANEL:
103  yield from $this->panel_content->content(
104  $base_path,
105  $elements[0],
106  false,
107  $request,
108  );
109  return;
110 
111  case self::ROOT:
112  yield from $this->root_content->content(
113  $base_path,
114  $elements[0],
115  $request
116  );
117  return;
118 
119  default:
120  throw new \ilMDEditorException(
121  'Invalid content type.'
122  );
123  }
124  }
125 
126  protected function decideContentType(
127  ElementInterface ...$elements
128  ): string {
129  if ($elements[0]->isRoot()) {
130  return self::ROOT;
131  }
132  $tag = $this->editor_dictionary->tagForElement($elements[0]);
133  if (!$tag?->isLastInTree()) {
134  return self::PANEL;
135  }
136  if ($tag?->isCollected()) {
137  return self::TABLE;
138  }
139  return self::FORM;
140  }
141 
145  protected function getElements(SetInterface $set, PathInterface $path): array
146  {
147  $res = $this->navigator_factory->navigator(
148  $path,
149  $set->getRoot()
150  )->elementsAtFinalStep();
151  return iterator_to_array($res);
152  }
153 }
$res
Definition: ltiservices.php:66
EditorDictionaryInterface $editor_dictionary
Definition: FullEditor.php:45
decideContentType(ElementInterface ... $elements)
Definition: FullEditor.php:126
NavigatorFactoryInterface $navigator_factory
Definition: FullEditor.php:46
$path
Definition: ltiservices.php:29
getRoot()
Returns the root element of the metadata set.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getContent(SetInterface $set, PathInterface $base_path, ?RequestForFormInterface $request=null)
Definition: FullEditor.php:79
__construct(EditorDictionaryInterface $editor_dictionary, NavigatorFactoryInterface $navigator_factory, FullEditorServices $services, FormContent $form_content, TableContent $table_content, PanelContent $panel_content, RootContent $root_content)
Definition: FullEditor.php:53
getElements(SetInterface $set, PathInterface $path)
Definition: FullEditor.php:145