ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilPresentationFullGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
21 use ILIAS\UI;
23 
28 {
29  protected \ILIAS\Style\Content\Service $content_style;
30  protected ilObjUser $user;
31  protected ilCtrl $ctrl;
32  protected ilLanguage $lng;
34  protected ilTabsGUI $tabs_gui;
36  protected UI\Factory $ui_fac;
37  protected UI\Renderer $ui_ren;
38  protected $parent_obj;
40  protected bool $offline = false;
41  protected int $tax_node = 0;
42  protected Presentation\PresentationGUIRequest $request;
43  protected Presentation\PresentationManager $manager;
44  protected \ilUIFilterService $filter_service;
45  protected ?array $filter_data = null;
46 
47  public function __construct(
48  $parent_object,
49  ilObjGlossary $glossary,
50  bool $offline,
51  int $tax_node = 0,
52  ) {
53  global $DIC;
54 
55  $this->ctrl = $DIC->ctrl();
56  $this->user = $DIC->user();
57  $this->lng = $DIC->language();
58  $this->tpl = $DIC->ui()->mainTemplate();
59  $this->tabs_gui = $DIC->tabs();
60  $this->nav_history = $DIC["ilNavigationHistory"];
61  $this->ui_fac = $DIC->ui()->factory();
62  $this->ui_ren = $DIC->ui()->renderer();
63  $this->parent_obj = $parent_object;
64  $this->glossary = $glossary;
65  $this->offline = $offline;
66  $this->tax_node = $tax_node;
67  $this->request = $DIC->glossary()
68  ->internal()
69  ->gui()
70  ->presentation()
71  ->request();
72  $this->manager = $DIC->glossary()
73  ->internal()
74  ->domain()
75  ->presentation($this->glossary);
76  $this->filter_service = $DIC->uiService()->filter();
77  $this->content_style = $DIC->contentStyle();
78  }
79 
80  public function executeCommand(): void
81  {
82  $next_class = $this->ctrl->getNextClass($this);
83  $cmd = $this->ctrl->getCmd();
84 
85  switch ($next_class) {
86  default:
87  $cmd = $this->ctrl->getCmd("show");
88  $ret = $this->$cmd();
89  break;
90  }
91  }
92 
93  protected function determinePageLength(): int
94  {
95  if ($this->request->getPageLength() === -1) {
96  $page_length = (int) $this->user->getPref("hits_per_page") ?: 9999;
97  $this->manager->setSessionPageLength($page_length);
98  } elseif ($this->request->getPageLength() > 0) {
99  $page_length = $this->request->getPageLength();
100  $this->manager->setSessionPageLength($page_length);
101  } elseif ($this->manager->getSessionPageLength() > 0) {
102  $page_length = $this->manager->getSessionPageLength();
103  } else {
104  $page_length = (int) $this->user->getPref("hits_per_page") ?: 9999;
105  }
106 
107  return $page_length;
108  }
109 
110  public function show(): void
111  {
112  $this->ctrl->setParameter($this, "term_id", "");
113  $this->tabs_gui->activateTab("terms");
114 
115  $this->nav_history->addItem(
116  $this->glossary->getRefId(),
117  $this->ctrl->getLinkTargetByClass("ilGlossaryPresentationGUI", "listTerms"),
118  "glo"
119  );
120 
121  $this->content_style->gui()->addCss(
122  $this->tpl,
123  $this->glossary->getRefId()
124  );
125 
126  $filter = $this->initFilter();
127  $this->filter_data = $this->filter_service->getData($filter);
128  $this->manager->setSessionLetter($this->filter_data["letter"] ?? "");
129 
130  $panel = $this->initPanel();
131 
132  $this->tpl->setContent($this->ui_ren->render([$filter, $panel]));
133  $this->tpl->setPermanentLink("glo", $this->glossary->getRefId());
134  }
135 
136  protected function initFilter(): UI\Component\Input\Container\Filter\Standard
137  {
138  $first_letters = $this->glossary->getFirstLetters($this->tax_node);
139  $session_letter = ilUtil::stripSlashes($this->manager->getSessionLetter());
140  if (!empty($session_letter) && !in_array($session_letter, $first_letters)) {
141  $first_letters[$session_letter] = $session_letter;
142  }
143 
144  $filter = $this->filter_service->standard(
145  self::class . "_filter_" . $this->glossary->getRefId(),
146  $this->ctrl->getLinkTarget($this, "show"),
147  [
148  "letter" => $this->ui_fac->input()->field()->select(
149  $this->lng->txt("glo_term_letter"),
150  $first_letters
151  ),
152  "term" => $this->ui_fac->input()->field()->text($this->lng->txt("cont_term")),
153  "definition" => $this->ui_fac->input()->field()->text($this->lng->txt("cont_definition"))
154  ],
155  [true, true, true],
156  true,
157  true
158  );
159 
160  return $filter;
161  }
162 
163  protected function initPanel(int $page_length = 0): UI\Component\Panel\Panel
164  {
165  if (!$page_length) {
166  $page_length = $this->determinePageLength();
167  }
168 
169  $terms = $this->glossary->getTermList(
170  $this->filter_data["term"] ?? "",
171  $this->filter_data["letter"] ?? "",
172  $this->filter_data["definition"] ?? "",
173  $this->tax_node,
174  false,
175  false,
176  null,
177  false,
178  true
179  );
180 
181  $terms_sliced = array_slice(
182  $terms,
183  $this->request->getCurrentPage() * $page_length,
184  $page_length
185  );
186 
187  $subs = [];
188  foreach ($terms_sliced as $term) {
189  $subs[] = $this->ui_fac->panel()->sub(
190  $term["term"],
191  $this->ui_fac->legacy($this->parent_obj->listDefinitions(
192  $this->request->getRefId(),
193  (int) $term["id"],
194  true,
195  false,
197  false
198  ))
199  );
200  }
201 
202  $panel = $this->ui_fac->panel()->standard($this->lng->txt("cont_terms"), $subs);
203  if (!$this->offline) {
204  $pagination = $this->ui_fac->viewControl()->pagination()
205  ->withTargetURL(
206  $this->ctrl->getLinkTarget($this, "show"),
207  "current_page"
208  )
209  ->withTotalEntries(count($terms))
210  ->withPageSize($page_length)
211  ->withMaxPaginationButtons(5)
212  ->withCurrentPage($this->request->getCurrentPage());
213 
214  $dropdown = $this->initDropdown($page_length);
215 
216  $panel = $panel
217  ->withViewControls([$pagination])
218  ->withActions($dropdown);
219  }
220 
221  return $panel;
222  }
223 
224  protected function initDropdown(int $page_length): UI\Component\Dropdown\Dropdown
225  {
226  $hpp = ($this->user->getPref("hits_per_page") != 9999)
227  ? $this->user->getPref("hits_per_page")
228  : $this->lng->txt("no_limit");
229 
230  $terms_per_page_sel = [-1 => $this->lng->txt("default") . " (" . $hpp . ")", 5 => "5", 10 => "10",
231  15 => "15", 20 => "20", 30 => "30", 40 => "40", 50 => "50", 100 => "100"];
232 
233  foreach ($terms_per_page_sel as $count => $count_text) {
234  $this->ctrl->setParameter($this->parent_obj, "page_length", $count);
235  $items[] = $this->ui_fac->button()->shy($count_text, $this->ctrl->getLinkTarget($this, "show"));
236  $this->ctrl->setParameter($this->parent_obj, "page_length", "");
237  }
238  $dropdown = $this->ui_fac->dropdown()->standard($items)
239  ->withLabel($page_length . " " . $this->lng->txt("glo_terms_per_page"));
240 
241  return $dropdown;
242  }
243 
244  public function renderPanelForOffline(): string
245  {
246  $panel = $this->initPanel(9999);
247  $panel_html = $this->ui_ren->render($panel);
248  //$this->tpl->setVariable("ADM_CONTENT", $panel_html);
249  //return $this->tpl->printToString();
250  return $panel_html;
251  }
252 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilGlobalTemplateInterface $tpl
Presentation PresentationManager $manager
ILIAS Style Content Service $content_style
global $DIC
Definition: feed.php:28
__construct( $parent_object, ilObjGlossary $glossary, bool $offline, int $tax_node=0,)
Last visited history for repository items.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Presentation PresentationGUIRequest $request
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...