ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilContainerSessionsContentGUI.php
Go to the documentation of this file.
1<?php
2
25{
26 protected array $visible_sessions = [];
27 protected bool $session_link_next = false;
28 protected bool $session_link_prev = false;
29 protected bool $session_limitation_initialised = false;
30
31 protected function initRenderer(): void
32 {
33 parent::initRenderer();
34 $this->renderer->setBlockPostfixClosure(function (string $type) {
35 return $this->getBlockPostfix($type);
36 });
37 $this->renderer->setBlockPrefixClosure(function (string $type) {
38 return $this->getBlockPrefix($type);
39 });
40 $this->renderer->setItemHiddenClosure(function (string $type, int $ref_id) {
41 return $this->isItemHidden($type, $ref_id);
42 });
43 }
44
45 protected function getBlockPostfix(string $type): string
46 {
47 if ($type === "sess") {
49 if ($this->session_link_next) {
50 return (string) $this->renderSessionLimitLink(false);
51 }
52 }
53 return "";
54 }
55
56 protected function getBlockPrefix(string $type): string
57 {
58 if ($type === "sess") {
60 if ($this->session_link_prev) {
61 return (string) $this->renderSessionLimitLink(true);
62 }
63 }
64 return "";
65 }
66
67 public function renderItemList(): string
68 {
69 $this->initRenderer();
70 return $this->renderer->renderItemBlockSequence($this->item_presentation->getItemBlockSequence());
71 }
72
73 protected function renderSessionLimitLink(
74 bool $a_previous = true
75 ): string {
76 $lng = $this->lng;
77 $ilUser = $this->user;
78 $ilCtrl = $this->ctrl;
79
81
82 $tpl = new ilTemplate(
83 'tpl.container_list_item.html',
84 true,
85 true,
86 "components/ILIAS/Container"
87 );
88 $tpl->setVariable('DIV_CLASS', 'ilContainerListItemOuter');
89 $tpl->setCurrentBlock('item_title_linked');
90
91 if ($a_previous) {
92 $prefp = $ilUser->getPref('crs_sess_show_prev_' . $this->getContainerObject()->getId());
93
94 if ($prefp) {
95 $tpl->setVariable('TXT_TITLE_LINKED', $lng->txt('crs_link_hide_prev_sessions'));
96 $ilCtrl->setParameterByClass(get_class($this->getContainerGUI()), 'crs_prev_sess', (int) !$prefp);
97 $tpl->setVariable('HREF_TITLE_LINKED', $ilCtrl->getLinkTargetByClass(get_class($this->getContainerGUI()), 'view'));
98 } else {
99 $tpl->setVariable('TXT_TITLE_LINKED', $lng->txt('crs_link_show_all_prev_sessions'));
100 $ilCtrl->setParameterByClass(get_class($this->getContainerGUI()), 'crs_prev_sess', (int) !$prefp);
101 $tpl->setVariable('HREF_TITLE_LINKED', $ilCtrl->getLinkTargetByClass(get_class($this->getContainerGUI()), 'view'));
102 }
103 $ilCtrl->clearParametersByClass(get_class($this->getContainerGUI()));
104 } else {
105 $prefn = $ilUser->getPref('crs_sess_show_next_' . $this->getContainerObject()->getId());
106
107 if ($prefn) {
108 $tpl->setVariable('TXT_TITLE_LINKED', $lng->txt('crs_link_hide_next_sessions'));
109 } else {
110 $tpl->setVariable('TXT_TITLE_LINKED', $lng->txt('crs_link_show_all_next_sessions'));
111 }
112 $ilCtrl->setParameterByClass(get_class($this->getContainerGUI()), 'crs_next_sess', (int) !$prefn);
113 $tpl->setVariable('HREF_TITLE_LINKED', $ilCtrl->getLinkTargetByClass(get_class($this->getContainerGUI()), 'view'));
114 $ilCtrl->clearParametersByClass(get_class($this->getContainerGUI()));
115 }
117
118 return $tpl->get();
119 }
120
121
122 protected function initSessionPresentationLimitation(): void
123 {
124 global $DIC;
125 if ($this->session_limitation_initialised) {
126 return;
127 }
128 $this->session_limitation_initialised = true;
129
130
131 $container = $this->container_obj;
132
133
134 $mode_manager = $DIC->container()->internal()->domain()->content()->mode($container);
135 $session_ref_ids = $this->item_presentation->getRefIdsOfType("sess");
136
137 // see #38780
138 if (!in_array($container->getType(), ["grp", "crs"])) {
139 $this->visible_sessions = $session_ref_ids;
140 return;
141 }
142
143 $user = $DIC->user();
144 $access = $DIC->access();
145 $tree = $DIC->repositoryTree();
146 $request = $DIC->container()
147 ->internal()
148 ->gui()
149 ->standardRequest();
150
151 $limit_sessions = false;
152 if (!$mode_manager->isAdminMode() &&
153 count($session_ref_ids) > 0 &&
154 $container->isSessionLimitEnabled()) {
155 $limit_sessions = true;
156 }
157
158 if ($container->getViewMode() === ilContainer::VIEW_INHERIT) {
159 $parent = $tree->checkForParentType($container->getRefId(), 'crs');
160 $crs = ilObjectFactory::getInstanceByRefId($parent, false);
161 if (!$crs instanceof ilObjCourse) {
162 return;
163 }
164
165 if (!$container->isSessionLimitEnabled()) {
166 $limit_sessions = false;
167 }
168 $limit_next = $crs->getNumberOfNextSessions();
169 $limit_prev = $crs->getNumberOfPreviousSessions();
170 } else {
171 $limit_next = $container->getNumberOfNextSessions();
172 $limit_prev = $container->getNumberOfPreviousSessions();
173 }
174
175 if (!$limit_sessions) {
176 $this->visible_sessions = $session_ref_ids;
177 return;
178 }
179
180 // do session limit
181 if ($request->getPreviousSession() !== null) {
182 $user->writePref(
183 'crs_sess_show_prev_' . $container->getId(),
184 (string) $request->getPreviousSession()
185 );
186 }
187 if ($request->getNextSession() !== null) {
188 $user->writePref(
189 'crs_sess_show_next_' . $container->getId(),
190 (string) $request->getNextSession()
191 );
192 }
193
194 $sessions = array_map(function ($ref_id) {
195 return $this->item_presentation->getRawDataByRefId($ref_id);
196 }, $session_ref_ids);
197 $sessions = ilArrayUtil::sortArray($sessions, 'start', 'ASC', true, false);
198 //$sessions = ilUtil::sortArray($this->items['sess'],'start','ASC',true,false);
199 $today = new ilDate(date('Ymd'), IL_CAL_DATE);
200 $previous = $current = $next = [];
201 foreach ($sessions as $key => $item) {
202 $start = new ilDateTime($item['start'], IL_CAL_UNIX);
203 $end = new ilDateTime($item['end'], IL_CAL_UNIX);
204
205 if (ilDateTime::_within($today, $start, $end, IL_CAL_DAY)) {
206 $current[] = $item;
207 } elseif (ilDateTime::_before($start, $today, IL_CAL_DAY)) {
208 $previous[] = $item;
209 } elseif (ilDateTime::_after($start, $today, IL_CAL_DAY)) {
210 $next[] = $item;
211 }
212 }
213
214 $num_previous_remove = max(
215 count($previous) - $limit_prev,
216 0
217 );
218 while ($num_previous_remove--) {
219 if (!$user->getPref('crs_sess_show_prev_' . $container->getId())) {
220 array_shift($previous);
221 }
222 $this->session_link_prev = true;
223 }
224
225 $num_next_remove = max(
226 count($next) - $limit_next,
227 0
228 );
229 while ($num_next_remove--) {
230 if (!$user->getPref('crs_sess_show_next_' . $container->getId())) {
231 array_pop($next);
232 }
233 // @fixme
234 $this->session_link_next = true;
235 }
236
237 $sessions = array_merge($previous, $current, $next);
238 $this->visible_sessions = array_map(static function ($item) {
239 return (int) $item["ref_id"];
240 }, $sessions);
241 }
242
243 protected function isItemHidden(string $type, int $ref_id): bool
244 {
245 if ($type === "sess") {
246 $this->initSessionPresentationLimitation();
247 return !in_array($ref_id, $this->visible_sessions, true);
248 }
249 return false;
250 }
251
252}
renderer()
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.
ilGlobalTemplateInterface $tpl
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
special template class to simplify handling of ITX/PEAR
setVariable(string $variable, $value='')
Sets the given variable to the given value.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
$ref_id
Definition: ltiauth.php:66
global $DIC
Definition: shib_login.php:26
$container
@noRector
Definition: wac.php:37