ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilCalendarAgendaListGUI.php
Go to the documentation of this file.
1 <?php
2 include_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;
17  const PERIOD_HALF_YEAR = 4;
18 
22  protected $ctrl;
23 
27  protected $user;
28 
32  protected $lng;
33 
37  protected $period = self::PERIOD_WEEK;
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  $this->initPeriod();
59 
60  $this->ctrl->setParameterByClass("ilcalendarinboxgui", "seed", $this->seed->get(IL_CAL_DATE));
61 
62  $this->initEndPeriod();
63  }
64 
68  protected function initPeriod()
69  {
70  global $DIC;
71 
72  $cal_setting = ilCalendarSettings::_getInstance();
73 
74  $qp = $DIC->http()->request()->getQueryParams();
75  if ((int) $qp["cal_agenda_per"] > 0 && (int) $qp["cal_agenda_per"] <= 4) {
76  $this->period = $qp["cal_agenda_per"];
77  } elseif (!empty($this->user->getPref('cal_list_view'))) {
78  $this->period = intval($this->user->getPref('cal_list_view'));
79  } else {
80  $this->period = $cal_setting->getDefaultPeriod();
81  }
82 
83  $this->user->writePref('cal_list_view', $this->period);
84  }
85 
89  protected function initEndPeriod()
90  {
91  $end_date = clone $this->seed;
92 
93  switch ($this->period) {
94  case self::PERIOD_DAY:
95  $end_date->increment(IL_CAL_DAY, 1);
96  break;
97 
98  case self::PERIOD_WEEK:
99  $end_date->increment(IL_CAL_WEEK, 1);
100  break;
101 
102  case self::PERIOD_MONTH:
103  $end_date->increment(IL_CAL_MONTH, 1);
104  break;
105 
106  case self::PERIOD_HALF_YEAR:
107  $end_date->increment(IL_CAL_MONTH, 6);
108  break;
109  }
110  $this->period_end_day = $end_date->get(IL_CAL_DATE);
111  }
112 
116  public function executeCommand()
117  {
118  $next_class = $this->ctrl->getNextClass($this);
119  $cmd = $this->ctrl->getCmd("getHTML");
120 
121  switch ($next_class) {
122  case "ilcalendarappointmentpresentationgui":
123  $this->ctrl->setReturn($this, "");
124  include_once("./Services/Calendar/classes/class.ilCalendarAppointmentPresentationGUI.php");
126  $this->ctrl->forwardCommand($gui);
127  break;
128 
129  default:
130  $this->ctrl->setReturn($this, "");
131  if (in_array($cmd, array("getHTML", "getModalForApp"))) {
132  return $this->$cmd();
133  }
134  }
135  }
136 
143  public function getHTML()
144  {
145  $navigation = new ilCalendarHeaderNavigationGUI($this, new ilDate($this->seed->get(IL_CAL_DATE), IL_CAL_DATE), ilDateTime::DAY);
146  $navigation->getHTML();
147 
148  // set return now (after header navigation) to the list (e.g. for profile links)
149  $this->ctrl->setReturn($this, "");
150 
151  // get events
152  $events = $this->getEvents();
153  $events = ilUtil::sortArray($events, "dstart", "asc", true);
154 
155  $df = new \ILIAS\Data\Factory();
156  $items = array();
157  $groups = array();
158  $modals = array();
159  $group_date = new ilDate(0, IL_CAL_UNIX);
160  $end_day = new ilDate($this->period_end_day, IL_CAL_DATE);
161  $end_day->increment(ilDateTime::DAY, -1);
162  foreach ($events as $e) {
163  if ($e['event']->isFullDay()) {
164  // begin/end is Date (without timzone)
165  $begin = new ilDate($e['dstart'], IL_CAL_UNIX);
166  $end = new ilDate($e['dend'], IL_CAL_UNIX);
167  } else {
168  // begin/end is DateTime (with timezone conversion)
169  $begin = new ilDateTime($e['dstart'], IL_CAL_UNIX);
170  $end = new ilDateTime($e['dend'], IL_CAL_UNIX);
171  }
172 
173  // if the begin is before seed date (due to timezone conversion) => continue
175  $begin,
176  $this->seed,
178  $GLOBALS['DIC']->user()->getTimezone()
179  )) {
180  continue;
181  }
182 
183  if (ilDateTime::_after(
184  $begin,
185  $end_day,
187  $GLOBALS['DIC']->user()->getTimezone()
188  )
189  ) {
190  break;
191  }
192 
193 
194  // initialize group date for first iteration
195  if ($group_date->isNull()) {
196  $group_date = new ilDate(
197  $begin->get(IL_CAL_DATE, '', $GLOBALS['DIC']->user()->getTimezone()),
199  );
200  }
201 
202  if (!ilDateTime::_equals($group_date, $begin, IL_CAL_DAY, $GLOBALS['DIC']->user()->getTimezone())) {
203  // create new group
204  $groups[] = $this->ui_factory->item()->group(
205  ilDatePresentation::formatDate($group_date, false, true),
206  $items
207  );
208 
209  $group_date = new ilDate(
210  $begin->get(IL_CAL_DATE, '', $GLOBALS['DIC']->user()->getTimezone()),
212  );
213  $items = [];
214  }
215 
216  // get calendar
217  $cat_id = ilCalendarCategoryAssignments::_lookupCategory($e["event"]->getEntryId());
218  $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat_id);
219 
220  $properties = array();
221 
222  /*TODO:
223  * All this code related with the ctrl and shy button can be centralized in
224  * ilCalendarViewGUI refactoring the method getAppointmentShyButton or
225  * if we want extend this class from ilCalendarInboxGUI we can just keep it here.
226  */
227 
228  // shy button for title
229  $this->ctrl->setParameter($this, 'app_id', $e["event"]->getEntryId());
230  $this->ctrl->setParameter($this, 'dt', $e['dstart']);
231  $this->ctrl->setParameter($this, 'seed', $this->seed->get(IL_CAL_DATE));
232 
233  $url = $this->ctrl->getLinkTarget($this, "getModalForApp", "", true, false);
234  $this->ctrl->setParameter($this, "app_id", $_GET["app_id"]);
235  $this->ctrl->setParameter($this, "dt", $_GET["dt"]);
236  $this->ctrl->setParameter($this, 'modal_title', $_GET["modal_title"]);
237  $modal = $this->ui_factory->modal()->roundtrip('', [])->withAsyncRenderUrl($url);
238  $shy = $this->ui_factory->button()->shy($e["event"]->getPresentationTitle(false), "")->withOnClick($modal->getShowSignal());
239 
240  $modals[] = $modal;
241  if ($e['event']->isFullDay()) {
242  $lead_text = $this->lng->txt("cal_all_day");
243  } else {
244  $lead_text = ilDatePresentation::formatPeriod($begin, $end, true);
245  }
246  $li = $this->ui_factory->item()->standard($shy)
247  ->withDescription("" . nl2br(strip_tags($e["event"]->getDescription())))
248  ->withLeadText($lead_text)
249  ->withProperties($properties)
250  ->withColor($df->color('#' . $cat_info["color"]));
251 
252  if ($li_edited_by_plugin = $this->getPluginAgendaItem($li, $e['event'])) {
253  $li = $li_edited_by_plugin;
254  }
255 
256  // add type specific actions/properties
257  include_once("./Services/Calendar/classes/class.ilCalendarAppointmentPresentationGUI.php");
259  $app_gui->setListItemMode($li);
260  $this->ctrl->getHTML($app_gui);
261  $items[] = $app_gui->getListItem();
262  }
263  // terminate last group
264  if (!$group_date->isNull()) {
265  $groups[] = $this->ui_factory->item()->group(
266  ilDatePresentation::formatDate($group_date, false, true),
267  $items
268  );
269  }
270 
271  // list actions
272  $images = array_fill(1, 4, "<span class=\"ilAdvNoImg\"></span>");
273  if ($cal_agenda_per = (int) $_GET['cal_agenda_per']) {
274  $images[$cal_agenda_per] = "<img src='./templates/default/images/icon_checked.svg' alt='Month'>";
275  } else {
276  $images[$this->period] = "<img src='./templates/default/images/icon_checked.svg' alt='Month'>";
277  }
278 
279  #21479 Set seed if the view does not contain any event.
280  $this->ctrl->setParameter($this, 'seed', $this->seed->get(IL_CAL_DATE));
281 
282  $items = array();
283  $this->ctrl->setParameter($this, "cal_agenda_per", self::PERIOD_DAY);
284  $items[] = $this->ui_factory->button()->shy($images[1] . "1 " . $this->lng->txt("day"), $this->ctrl->getLinkTarget($this, "getHTML"));
285  $this->ctrl->setParameter($this, "cal_agenda_per", self::PERIOD_WEEK);
286  $items[] = $this->ui_factory->button()->shy($images[2] . "1 " . $this->lng->txt("week"), $this->ctrl->getLinkTarget($this, "getHTML"));
287  $this->ctrl->setParameter($this, "cal_agenda_per", self::PERIOD_MONTH);
288  $items[] = $this->ui_factory->button()->shy($images[3] . "1 " . $this->lng->txt("month"), $this->ctrl->getLinkTarget($this, "getHTML"));
289  $this->ctrl->setParameter($this, "cal_agenda_per", self::PERIOD_HALF_YEAR);
290  $items[] = $this->ui_factory->button()->shy($images[4] . "6 " . $this->lng->txt("months"), $this->ctrl->getLinkTarget($this, "getHTML"));
291  $this->ctrl->setParameter($this, "cal_agenda_per", $this->period);
292 
293 
294  $actions = $this->ui_factory->dropdown()->standard($items)->withLabel($this->lng->txt("cal_period"));
295 
296  $list_title =
297  $this->lng->txt("cal_agenda") . ": " . ilDatePresentation::formatDate(new ilDate($this->seed->get(IL_CAL_DATE), IL_CAL_DATE));
298  if ($this->period != self::PERIOD_DAY) {
299  $end_day = new ilDate($this->period_end_day, IL_CAL_DATE);
300  $end_day->increment(ilDateTime::DAY, -1);
301  $list_title .= " - " . ilDatePresentation::formatDate($end_day);
302  }
303 
304  $list = $this->ui_factory->panel()->listing()->standard($list_title, $groups)
305  ->withActions($actions);
306 
307 
308  $comps = array_merge($modals, array($list));
309 
310  $html = $this->ui_renderer->render($comps);
311 
312  if (count($groups) == 0) {
313  $html .= ilUtil::getSystemMessageHTML($this->lng->txt("cal_no_events_info"));
314  }
315 
316  return $html;
317  }
318 
324  public function getPluginAgendaItem($a_item, $appointment)
325  {
326  //"capg" is the plugin slot id for AppointmentCustomGrid
327  foreach ($this->getActivePlugins("capg") as $plugin) {
328  $plugin->setAppointment($appointment, $appointment->getStart());
329  $li = $plugin->editAgendaItem($a_item);
330  }
331  return $li;
332  }
333 
339  public static function getPeriod()
340  {
341  global $DIC;
342 
343  $settings = ilCalendarSettings::_getInstance();
344  $ilUser = $DIC->user();
345 
346  $qp = $DIC->http()->request()->getQueryParams();
347  if ((int) $qp["cal_agenda_per"] > 0 && (int) $qp["cal_agenda_per"] <= 4) {
348  return $qp["cal_agenda_per"];
349  } elseif ($period = $ilUser->getPref('cal_list_view')) {
350  return $period;
351  } else {
352  return $settings->getDefaultPeriod();
353  }
354  }
355 }
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
static _lookupCategory($a_cal_id)
Lookup category id.
static _getInstance()
get singleton instance
__construct(ilDate $seed)
Constructor.
$_GET["client_id"]
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 getSystemMessageHTML($a_txt, $a_type="info")
Get HTML for a system message.
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.
static _getInstance(ilDate $seed, $a_app)
get singleton instance
const IL_CAL_MONTH
getCurrentApp()
Get app for id.
const IL_CAL_UNIX
const IL_CAL_WEEK
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
user()
Definition: user.php:4
const IL_CAL_DAY
static _equals(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
Check if two date are equal.
static getPeriod()
needed in CalendarInboxGUI to get events using a proper period.
Class for single dates.
global $DIC
Definition: goto.php:24
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
static _getInstance($a_usr_id=0)
get singleton instance
initPeriod()
Initialises time Period for calendar list view.
getPluginAgendaItem($a_item, $appointment)
const IL_CAL_DATE
static formatPeriod(ilDateTime $start, ilDateTime $end, $a_skip_starting_day=false)
Format a period of two date Shows: 14.
__construct(Container $dic, ilPlugin $plugin)
$url
$ilUser
Definition: imgupload.php:18
initEndPeriod()
Initialises end date for calendar list view.