ILIAS  release_8 Revision v8.24
class.ilContainerSessionsContentGUI.php
Go to the documentation of this file.
1<?php
2
25{
26 protected ilTabsGUI $tabs;
27 protected array $force_details = [];
28
29 public function __construct(ilContainerGUI $container_gui_obj)
30 {
31 global $DIC;
32
33 $this->tabs = $DIC->tabs();
34 $this->user = $DIC->user();
35 $this->ctrl = $DIC->ctrl();
36 $lng = $DIC->language();
37 parent::__construct($container_gui_obj);
38 $this->lng = $lng;
39 $this->initDetails();
40 }
41
42
43 protected function getDetailsLevel(int $a_item_id): int
44 {
45 if ($this->getContainerGUI()->isActiveAdministrationPanel()) {
47 }
48 if ($this->item_manager->getExpanded($a_item_id) !== null) {
49 return $this->item_manager->getExpanded($a_item_id);
50 }
51 if (in_array($a_item_id, $this->force_details)) {
52 return self::DETAILS_ALL;
53 }
54
56 }
57
58 public function getMainContent(): string
59 {
60 // see bug #7452
61 // $ilTabs->setSubTabActive($this->getContainerObject()->getType().'_content');
62
63 $tpl = new ilTemplate(
64 "tpl.container_page.html",
65 true,
66 true,
67 "Services/Container"
68 );
69
70 $this->showMaterials($tpl);
71
72 return $tpl->get();
73 }
74
75 private function showMaterials(ilTemplate $a_tpl): void
76 {
78
79 $this->items = $this->getContainerObject()->getSubItems($this->getContainerGUI()->isActiveAdministrationPanel());
81
82 $this->initRenderer();
83
84 $output_html = $this->getContainerGUI()->getContainerPageHTML();
85
86 // get embedded blocks
87 if ($output_html != "") {
88 $output_html = $this->insertPageEmbeddedBlocks($output_html);
89 }
90
91 if (isset($this->items["sess"]) ||
92 isset($this->items['sess_link']['prev']['value']) ||
93 isset($this->items['sess_link']['next']['value'])) {
94 $this->items['sess'] = ilArrayUtil::sortArray($this->items['sess'], 'start', 'asc', true, false);
95
96 $prefix = $postfix = "";
97 if (isset($this->items['sess_link']['prev']['value'])) {
98 $prefix = $this->renderSessionLimitLink(true);
99 }
100 if (isset($this->items['sess_link']['next']['value'])) {
101 $postfix = $this->renderSessionLimitLink(false);
102 }
103
104 $this->renderer->addTypeBlock("sess", $prefix, $postfix);
105 $this->renderer->setBlockPosition("sess", 1);
106
107 $position = 1;
108
109 foreach ($this->items["sess"] as $item_data) {
110 if (!$this->renderer->hasItem($item_data["child"])) {
111 $html = $this->renderItem($item_data, $position++, true);
112 if ($html != "") {
113 $this->renderer->addItemToBlock("sess", $item_data["type"], $item_data["child"], $html);
114 }
115 }
116 }
117 #22328 render session block if previous or next session link is available
118 if (
119 !count($this->items['sess'] ?? []) &&
120 ($prefix !== '' || $postfix !== '')
121 ) {
122 $this->renderer->addItemToBlock('sess', '', 0, '&nbsp;');
123 }
124 }
125
126 $pos = $this->getItemGroupsHTML(1);
127
128 if (isset($this->items["_all"])) {
129 $this->renderer->addCustomBlock("_all", $lng->txt("content"));
130 $this->renderer->setBlockPosition("_all", ++$pos);
131
132 $position = 1;
133
134 foreach ($this->items["_all"] as $item_data) {
135 // #14599
136 if ($item_data["type"] === "sess" || $item_data["type"] === "itgr") {
137 continue;
138 }
139
140 if (!$this->renderer->hasItem($item_data["child"])) {
141 $html = $this->renderItem($item_data, $position++, true);
142 if ($html != "") {
143 $this->renderer->addItemToBlock("_all", $item_data["type"], $item_data["child"], $html);
144 }
145 }
146 }
147 }
148
149 $output_html .= $this->renderer->getHTML();
150
151 $a_tpl->setVariable("CONTAINER_PAGE_CONTENT", $output_html);
152 }
153
154 protected function renderSessionLimitLink(
155 bool $a_previous = true
156 ): string {
157 $lng = $this->lng;
159 $ilCtrl = $this->ctrl;
160
161 $lng->loadLanguageModule('crs');
162
163 $tpl = new ilTemplate(
164 'tpl.container_list_item.html',
165 true,
166 true,
167 "Services/Container"
168 );
169 $tpl->setVariable('DIV_CLASS', 'ilContainerListItemOuter');
170 $tpl->setCurrentBlock('item_title_linked');
171
172 if ($a_previous) {
173 $prefp = $ilUser->getPref('crs_sess_show_prev_' . $this->getContainerObject()->getId());
174
175 if ($prefp) {
176 $tpl->setVariable('TXT_TITLE_LINKED', $lng->txt('crs_link_hide_prev_sessions'));
177 $ilCtrl->setParameterByClass(get_class($this->getContainerGUI()), 'crs_prev_sess', (int) !$prefp);
178 $tpl->setVariable('HREF_TITLE_LINKED', $ilCtrl->getLinkTargetByClass(get_class($this->getContainerGUI()), 'view'));
179 } else {
180 $tpl->setVariable('TXT_TITLE_LINKED', $lng->txt('crs_link_show_all_prev_sessions'));
181 $ilCtrl->setParameterByClass(get_class($this->getContainerGUI()), 'crs_prev_sess', (int) !$prefp);
182 $tpl->setVariable('HREF_TITLE_LINKED', $ilCtrl->getLinkTargetByClass(get_class($this->getContainerGUI()), 'view'));
183 }
184 $ilCtrl->clearParametersByClass(get_class($this->getContainerGUI()));
185 } else {
186 $prefn = $ilUser->getPref('crs_sess_show_next_' . $this->getContainerObject()->getId());
187
188 if ($prefn) {
189 $tpl->setVariable('TXT_TITLE_LINKED', $lng->txt('crs_link_hide_next_sessions'));
190 } else {
191 $tpl->setVariable('TXT_TITLE_LINKED', $lng->txt('crs_link_show_all_next_sessions'));
192 }
193 $ilCtrl->setParameterByClass(get_class($this->getContainerGUI()), 'crs_next_sess', (int) !$prefn);
194 $tpl->setVariable('HREF_TITLE_LINKED', $ilCtrl->getLinkTargetByClass(get_class($this->getContainerGUI()), 'view'));
195 $ilCtrl->clearParametersByClass(get_class($this->getContainerGUI()));
196 }
198
199 return $tpl->get();
200 }
201
202
203 public function addFooterRow(
205 ): void {
206 $ilCtrl = $this->ctrl;
207
208 $ilCtrl->setParameterByClass(
209 "ilrepositorygui",
210 "ref_id",
211 $this->request->getRefId()
212 );
213
214 $tpl->setCurrentBlock('container_details_row');
215 $tpl->setVariable('TXT_DETAILS', $this->lng->txt('details'));
216 $tpl->parseCurrentBlock();
217 }
218
219 protected function initDetails(): void
220 {
221 $this->handleSessionExpand();
222
223 if ($session = ilSessionAppointment::lookupNextSessionByCourse($this->getContainerObject()->getRefId())) {
224 $this->force_details = $session;
225 } elseif ($session = ilSessionAppointment::lookupLastSessionByCourse($this->getContainerObject()->getRefId())) {
226 $this->force_details = [$session];
227 }
228 }
229
230 public static function prepareSessionPresentationLimitation(
231 array $items,
233 bool $admin_panel_enabled = false,
234 bool $include_side_block = false
235 ): array {
237 global $DIC;
238
239 $user = $DIC->user();
240 $access = $DIC->access();
241 $tree = $DIC->repositoryTree();
242 $request = $DIC->container()
243 ->internal()
244 ->gui()
245 ->standardRequest();
246
247 $limit_sessions = false;
248 if (
249 !$admin_panel_enabled &&
250 !$include_side_block &&
251 isset($items['sess']) &&
252 $container->isSessionLimitEnabled() &&
253 ($container->getViewMode() === ilContainer::VIEW_SESSIONS || $container->getViewMode() === ilContainer::VIEW_INHERIT)
254 ) {
255 $limit_sessions = true;
256 }
257
258 if ($container->getViewMode() === ilContainer::VIEW_INHERIT) {
259 $parent = $tree->checkForParentType($container->getRefId(), 'crs');
260 $crs = ilObjectFactory::getInstanceByRefId($parent, false);
261 if (!$crs instanceof ilObjCourse) {
262 return $items;
263 }
264
265 if (!$container->isSessionLimitEnabled()) {
266 $limit_sessions = false;
267 }
268 $limit_next = $crs->getNumberOfNextSessions();
269 $limit_prev = $crs->getNumberOfPreviousSessions();
270 } else {
271 $limit_next = $container->getNumberOfNextSessions();
272 $limit_prev = $container->getNumberOfPreviousSessions();
273 }
274
275 if (!$limit_sessions) {
276 return $items;
277 }
278
279
280
281 // do session limit
282 if ($request->getPreviousSession() !== null) {
283 $user->writePref(
284 'crs_sess_show_prev_' . $container->getId(),
285 (string) $request->getPreviousSession()
286 );
287 }
288 if ($request->getNextSession() !== null) {
289 $user->writePref(
290 'crs_sess_show_next_' . $container->getId(),
291 (string) $request->getNextSession()
292 );
293 }
294
295 $session_rbac_checked = [];
296 foreach ($items['sess'] as $session_tree_info) {
297 if ($access->checkAccess('visible', '', $session_tree_info['ref_id'])) {
298 $session_rbac_checked[] = $session_tree_info;
299 }
300 }
301 $sessions = ilArrayUtil::sortArray($session_rbac_checked, 'start', 'ASC', true, false);
302 //$sessions = ilUtil::sortArray($this->items['sess'],'start','ASC',true,false);
303 $today = new ilDate(date('Ymd'), IL_CAL_DATE);
304 $previous = $current = $next = [];
305 foreach ($sessions as $key => $item) {
306 $start = new ilDateTime($item['start'], IL_CAL_UNIX);
307 $end = new ilDateTime($item['end'], IL_CAL_UNIX);
308
309 if (ilDateTime::_within($today, $start, $end, IL_CAL_DAY)) {
310 $current[] = $item;
311 } elseif (ilDateTime::_before($start, $today, IL_CAL_DAY)) {
312 $previous[] = $item;
313 } elseif (ilDateTime::_after($start, $today, IL_CAL_DAY)) {
314 $next[] = $item;
315 }
316 }
317 $num_previous_remove = max(
318 count($previous) - $limit_prev,
319 0
320 );
321 while ($num_previous_remove--) {
322 if (!$user->getPref('crs_sess_show_prev_' . $container->getId())) {
323 array_shift($previous);
324 }
325 $items['sess_link']['prev']['value'] = 1;
326 }
327
328 $num_next_remove = max(
329 count($next) - $limit_next,
330 0
331 );
332 while ($num_next_remove--) {
333 if (!$user->getPref('crs_sess_show_next_' . $container->getId())) {
334 array_pop($next);
335 }
336 // @fixme
337 $items['sess_link']['next']['value'] = 1;
338 }
339
340 $sessions = array_merge($previous, $current, $next);
341 $items['sess'] = $sessions;
342
343 // #15389 - see ilContainer::getSubItems()
345 $items[(int) $admin_panel_enabled][(int) $include_side_block] = $sort->sortItems($items);
346 return $items;
347 }
348}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_DAY
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
Parent class of all container content GUIs.
renderItem(array $a_item_data, int $a_position=0, bool $a_force_icon=false, string $a_pos_prefix="", string $item_group_list_presentation="")
Render an item.
initRenderer()
Init container renderer.
insertPageEmbeddedBlocks(string $a_output_html)
Insert blocks into container page.
ilGlobalTemplateInterface $tpl
Class ilContainerGUI This is a base GUI class for all container objects in ILIAS: root folder,...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getMainContent()
Get content HTML for main column, this one must be overwritten in derived classes.
__construct(ilContainerGUI $container_gui_obj)
static _getInstance(int $a_obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
@classDescription Date and time handling
static _after(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
static _within(ilDateTime $dt, ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
Check whether an date is within a date duration given by start and end.
static _before(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
Class for single dates.
loadLanguageModule(string $a_module)
Load language module.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static lookupNextSessionByCourse(int $a_ref_id)
static lookupLastSessionByCourse(int $a_ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setVariable(string $variable, $value='')
Sets the given variable to the given value.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
string $key
Consumer key/client ID value.
Definition: System.php:193
$session
$container
@noRector
Definition: wac.php:14