ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilCalendarAgendaListGUI.php
Go to the documentation of this file.
1<?php
2include_once './Services/Calendar/classes/class.ilCalendarViewGUI.php';
3/* Copyright (c) 1998-2017 ILIAS open source, Extended GPL, see docs/LICENSE */
4
13{
14 const PERIOD_DAY = 1;
15 const PERIOD_WEEK = 2;
16 const PERIOD_MONTH = 3;
18
22 protected $ctrl;
23
27 protected $user;
28
32 protected $lng;
33
38
42 protected $period_end_day = null;
43
44
45
52 public function __construct(ilDate $seed)
53 {
55
56 $this->ctrl->saveParameter($this, "cal_agenda_per");
57
58 //$qp = $DIC->http()->request()->getQueryParams();
59 #21479
60 $qp = $_GET;
61 if ((int) $qp["cal_agenda_per"] > 0 && (int) $qp["cal_agenda_per"] <= 4) {
62 $this->period = $qp["cal_agenda_per"];
63 } elseif ($period = ilSession::get('cal_list_view')) {
64 $this->period = $period;
65 }
66
67 $get_seed = $qp["seed"];
68 $this->ctrl->setParameterByClass("ilcalendarinboxgui", "seed", $this->seed->get(IL_CAL_DATE));
69 $end_date = clone $this->seed;
70 switch ($this->period) {
72 $end_date->increment(IL_CAL_DAY, 1);
73 break;
74
76 $end_date->increment(IL_CAL_WEEK, 1);
77 break;
78
80 $end_date->increment(IL_CAL_MONTH, 1);
81 break;
82
84 $end_date->increment(IL_CAL_MONTH, 6);
85 break;
86 }
87 $this->period_end_day = $end_date->get(IL_CAL_DATE);
88 }
89
93 public function executeCommand()
94 {
95 $next_class = $this->ctrl->getNextClass($this);
96 $cmd = $this->ctrl->getCmd("getHTML");
97
98 switch ($next_class) {
99 case "ilcalendarappointmentpresentationgui":
100 $this->ctrl->setReturn($this, "");
101 include_once("./Services/Calendar/classes/class.ilCalendarAppointmentPresentationGUI.php");
102 $gui = ilCalendarAppointmentPresentationGUI::_getInstance(new ilDate($this->seed->get(IL_CAL_DATE), IL_CAL_DATE), $this->getCurrentApp());
103 $this->ctrl->forwardCommand($gui);
104 break;
105
106 default:
107 $this->ctrl->setReturn($this, "");
108 if (in_array($cmd, array("getHTML", "getModalForApp"))) {
109 return $this->$cmd();
110 }
111 }
112 }
113
120 public function getHTML()
121 {
122 $navigation = new ilCalendarHeaderNavigationGUI($this, new ilDate($this->seed->get(IL_CAL_DATE), IL_CAL_DATE), ilDateTime::DAY);
123 $navigation->getHTML();
124
125 // set return now (after header navigation) to the list (e.g. for profile links)
126 $this->ctrl->setReturn($this, "");
127
128 // get events
129 $events = $this->getEvents();
130 $events = ilUtil::sortArray($events, "dstart", "asc", true);
131
132 $df = new \ILIAS\Data\Factory();
133 $items = array();
134 $groups = array();
135 $modals = array();
136 $group_date = new ilDate(0, IL_CAL_UNIX);
137 $end_day = new ilDate($this->period_end_day, IL_CAL_DATE);
138 $end_day->increment(ilDateTime::DAY, -1);
139 foreach ($events as $e) {
140 if ($e['event']->isFullDay()) {
141 // begin/end is Date (without timzone)
142 $begin = new ilDate($e['dstart'], IL_CAL_UNIX);
143 $end = new ilDate($e['dend'], IL_CAL_UNIX);
144 } else {
145 // begin/end is DateTime (with timezone conversion)
146 $begin = new ilDateTime($e['dstart'], IL_CAL_UNIX);
147 $end = new ilDateTime($e['dend'], IL_CAL_UNIX);
148 }
149
150 // if the begin is before seed date (due to timezone conversion) => continue
152 $begin,
153 $this->seed,
155 $GLOBALS['DIC']->user()->getTimezone()
156 )) {
157 continue;
158 }
159
161 $begin,
162 $end_day,
164 $GLOBALS['DIC']->user()->getTimezone()
165 )
166 ) {
167 break;
168 }
169
170
171 // initialize group date for first iteration
172 if ($group_date->isNull()) {
173 $group_date = new ilDate(
174 $begin->get(IL_CAL_DATE, '', $GLOBALS['DIC']->user()->getTimezone()),
176 );
177 }
178
179 if (!ilDateTime::_equals($group_date, $begin, IL_CAL_DAY, $GLOBALS['DIC']->user()->getTimezone())) {
180 // create new group
181 $groups[] = $this->ui_factory->item()->group(
182 ilDatePresentation::formatDate($group_date, false, true),
183 $items
184 );
185
186 $group_date = new ilDate(
187 $begin->get(IL_CAL_DATE, '', $GLOBALS['DIC']->user()->getTimezone()),
189 );
190 $items = [];
191 }
192
193 // get calendar
194 $cat_id = ilCalendarCategoryAssignments::_lookupCategory($e["event"]->getEntryId());
195 $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
196
197 $properties = array();
198
199 /*TODO:
200 * All this code related with the ctrl and shy button can be centralized in
201 * ilCalendarViewGUI refactoring the method getAppointmentShyButton or
202 * if we want extend this class from ilCalendarInboxGUI we can just keep it here.
203 */
204
205 // shy button for title
206 $this->ctrl->setParameter($this, 'app_id', $e["event"]->getEntryId());
207 $this->ctrl->setParameter($this, 'dt', $e['dstart']);
208 $this->ctrl->setParameter($this, 'seed', $this->seed->get(IL_CAL_DATE));
209
210 $url = $this->ctrl->getLinkTarget($this, "getModalForApp", "", true, false);
211 $this->ctrl->setParameter($this, "app_id", $_GET["app_id"]);
212 $this->ctrl->setParameter($this, "dt", $_GET["dt"]);
213 $this->ctrl->setParameter($this, 'modal_title', $_GET["modal_title"]);
214 $modal = $this->ui_factory->modal()->roundtrip('', [])->withAsyncRenderUrl($url);
215 $shy = $this->ui_factory->button()->shy($e["event"]->getPresentationTitle(false), "")->withOnClick($modal->getShowSignal());
216
217 $modals[] = $modal;
218 if ($e['event']->isFullDay()) {
219 $lead_text = $this->lng->txt("cal_all_day");
220 } else {
221 $lead_text = ilDatePresentation::formatPeriod($begin, $end, true);
222 }
223 $li = $this->ui_factory->item()->standard($shy)
224 ->withDescription("" . nl2br(strip_tags($e["event"]->getDescription())))
225 ->withLeadText($lead_text)
226 ->withProperties($properties)
227 ->withColor($df->color('#' . $cat_info["color"]));
228
229 if ($li_edited_by_plugin = $this->getPluginAgendaItem($li, $e['event'])) {
230 $li = $li_edited_by_plugin;
231 }
232
233 // add type specific actions/properties
234 include_once("./Services/Calendar/classes/class.ilCalendarAppointmentPresentationGUI.php");
236 $app_gui->setListItemMode($li);
237 $this->ctrl->getHTML($app_gui);
238 $items[] = $app_gui->getListItem();
239 }
240 // terminate last group
241 if (!$group_date->isNull()) {
242 $groups[] = $this->ui_factory->item()->group(
243 ilDatePresentation::formatDate($group_date, false, true),
244 $items
245 );
246 }
247
248 // list actions
249 $images = array_fill(1, 4, "<span class=\"ilAdvNoImg\"></span>");
250 if ($cal_agenda_per = (int) $_GET['cal_agenda_per']) {
251 $images[$cal_agenda_per] = "<img src='./templates/default/images/icon_checked.svg' alt='Month'>";
252 } else {
253 $images[$this->period] = "<img src='./templates/default/images/icon_checked.svg' alt='Month'>";
254 }
255
256 #21479 Set seed if the view does not contain any event.
257 $this->ctrl->setParameter($this, 'seed', $this->seed->get(IL_CAL_DATE));
258
259 $items = array();
260 $this->ctrl->setParameter($this, "cal_agenda_per", self::PERIOD_DAY);
261 $items[] = $this->ui_factory->button()->shy($images[1] . "1 " . $this->lng->txt("day"), $this->ctrl->getLinkTarget($this, "getHTML"));
262 $this->ctrl->setParameter($this, "cal_agenda_per", self::PERIOD_WEEK);
263 $items[] = $this->ui_factory->button()->shy($images[2] . "1 " . $this->lng->txt("week"), $this->ctrl->getLinkTarget($this, "getHTML"));
264 $this->ctrl->setParameter($this, "cal_agenda_per", self::PERIOD_MONTH);
265 $items[] = $this->ui_factory->button()->shy($images[3] . "1 " . $this->lng->txt("month"), $this->ctrl->getLinkTarget($this, "getHTML"));
266 $this->ctrl->setParameter($this, "cal_agenda_per", self::PERIOD_HALF_YEAR);
267 $items[] = $this->ui_factory->button()->shy($images[4] . "6 " . $this->lng->txt("months"), $this->ctrl->getLinkTarget($this, "getHTML"));
268 $this->ctrl->setParameter($this, "cal_agenda_per", $this->period);
269
270
271 $actions = $this->ui_factory->dropdown()->standard($items)->withLabel($this->lng->txt("days"));
272
273 $list_title =
274 $this->lng->txt("cal_agenda") . ": " . ilDatePresentation::formatDate(new ilDate($this->seed->get(IL_CAL_DATE), IL_CAL_DATE));
275 if ($this->period != self::PERIOD_DAY) {
276 $end_day = new ilDate($this->period_end_day, IL_CAL_DATE);
277 $end_day->increment(ilDateTime::DAY, -1);
278 $list_title .= " - " . ilDatePresentation::formatDate($end_day);
279 }
280
281 $list = $this->ui_factory->panel()->listing()->standard($list_title, $groups)
282 ->withActions($actions);
283
284
285 $comps = array_merge($modals, array($list));
286
287 $html = $this->ui_renderer->render($comps);
288
289 if (count($groups) == 0) {
290 $tpl = $this->ui->mainTemplate();
291 $html .= $tpl->getMessageHTML($this->lng->txt("cal_no_events_info"));
292 }
293
294 return $html;
295 }
296
302 public function getPluginAgendaItem($a_item, $appointment)
303 {
304 //"capg" is the plugin slot id for AppointmentCustomGrid
305 foreach ($this->getActivePlugins("capg") as $plugin) {
306 $plugin->setAppointment($appointment, $appointment->getStart());
307 $li = $plugin->editAgendaItem($a_item);
308 }
309 return $li;
310 }
311
317 public static function getPeriod()
318 {
319 #21479
320 $qp = $_GET;
321 if ((int) $qp["cal_agenda_per"] > 0 && (int) $qp["cal_agenda_per"] <= 4) {
322 return $qp["cal_agenda_per"];
323 } elseif ($period = ilSession::get('cal_list_view')) {
324 return $period;
325 } else {
326 return self::PERIOD_WEEK;
327 }
328 }
329}
user()
Definition: user.php:4
$tpl
Definition: ilias.php:10
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATE
const IL_CAL_WEEK
const IL_CAL_UNIX
const IL_CAL_MONTH
const IL_CAL_DAY
getPluginAgendaItem($a_item, $appointment)
__construct(ilDate $seed)
Constructor.
static getPeriod()
needed in CalendarInboxGUI to get events using a proper period.
static _getInstance(ilDate $seed, $a_app)
get singleton instance
static _getInstance($a_usr_id=0)
get singleton instance
static _lookupCategory($a_cal_id)
Lookup category id.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
static formatPeriod(ilDateTime $start, ilDateTime $end, $a_skip_starting_day=false)
Format a period of two date Shows: 14.
@classDescription Date and time handling
static _equals(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
Check if two date are equal.
static _after(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
static _before(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
Class for single dates.
static get($a_var)
Get a value.
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
$html
Definition: example_001.php:87
if($argc< 2) $events
$li
Definition: langwiz.php:233
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
static getDescription()
Definition: Php.php:51
$url
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41