ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilCalendarHeaderNavigationGUI.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24include_once('Services/Calendar/classes/class.ilCalendarUtil.php');
25
37{
38 protected $cmdClass = null;
39 protected $cmd = null;
40 protected $seed = null;
41 protected $increment = '';
42
43 protected $html;
44
48 protected $lng;
49
50
51 protected $tpl;
52
61 public function __construct($cmdClass, ilDate $seed, $a_increment, $cmd = '')
62 {
63 global $DIC;
64
65 $this->lng = $DIC->language();
66
67 $this->ctrl = $DIC->ctrl();
68 $this->cmdClass = $cmdClass;
69 $this->seed = clone $seed;
70 $this->increment = $a_increment;
71 $this->cmd = $cmd;
72 $this->toolbar = $DIC->toolbar();
73 $this->ui = $DIC->ui();
74 $this->user = $DIC->user();
75
76 $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($this->user->getId());
77 }
78
85 public function getHTML()
86 {
88 $ui = $this->ui;
89 $toolbar = $this->toolbar;
90
91 $today = new ilDateTime(time(), IL_CAL_UNIX, $this->user->getTimeZone());
92
93 $tpl = new ilTemplate("tpl.navigation_header.html", true, true, "Services/Calendar");
94
95 // previous button
96 $contains_today = false;
97 $this->incrementDate(-1);
98 $this->ctrl->setParameterByClass(get_class($this->cmdClass), 'seed', $this->seed->get(IL_CAL_DATE));
99 $b1 = $ui->factory()->button()->standard($lng->txt("previous"), $this->ctrl->getLinkTarget($this->cmdClass, $this->cmd));
100
101 // today button
102 $this->incrementDate(1);
104 switch ($this->increment) {
105 case ilDateTime::DAY:
106 $tpl->setVariable("TXT_TITLE", ilCalendarUtil::_numericDayToString($this->seed->get(IL_CAL_FKT_DATE, 'w')) .
107 ", " . ilDatePresentation::formatDate($this->seed));
108 if (date("Y-m-d") === $this->seed->get(IL_CAL_FKT_DATE, 'Y-m-d')) {
109 $contains_today = true;
110 }
111 break;
112
113 case ilDateTime::WEEK:
114 $weekday_list = ilCalendarUtil::_buildWeekDayList($this->seed, $this->user_settings->getWeekStart())->get();
115 $start = current($weekday_list);
116 $end = end($weekday_list);
117 $tpl->setVariable("TXT_TITLE", $this->lng->txt('week') . ' ' . $this->seed->get(IL_CAL_FKT_DATE, 'W') .
118 ", " . ilDatePresentation::formatDate($start) . " - " .
120 $il_date_now = new ilDateTime(ilUtil::now(), IL_CAL_DATETIME);
121 if (ilDate::_within($il_date_now, $start, $end)) {
122 $contains_today = true;
123 }
124 break;
125
127 $tpl->setVariable("TXT_TITLE", $this->lng->txt('month_' . $this->seed->get(IL_CAL_FKT_DATE, 'm') . '_long') .
128 ' ' . $this->seed->get(IL_CAL_FKT_DATE, 'Y'));
129 if ($this->seed->get(IL_CAL_FKT_DATE, 'Y-m') == date("Y-m")) {
130 $contains_today = true;
131 }
132 break;
133 }
135 $this->ctrl->setParameterByClass(
136 get_class($this->cmdClass),
137 'seed',
138 $today->get(IL_CAL_DATE)
139 );
140 if ($contains_today) {
141 $b2 = $ui->factory()->button()->standard(
142 $lng->txt("today"),
143 $this->ctrl->getLinkTarget($this->cmdClass, $this->cmd)
144 )->withEngagedState(true);
145 } else {
146 $b2 = $ui->factory()->button()->standard(
147 $lng->txt("today"),
148 $this->ctrl->getLinkTarget($this->cmdClass, $this->cmd)
149 );
150 }
151 // next button
152 $this->incrementDate(1);
153 $this->ctrl->setParameterByClass(get_class($this->cmdClass), 'seed', $this->seed->get(IL_CAL_DATE));
154 $b3 = $ui->factory()->button()->standard($lng->txt("next"), $this->ctrl->getLinkTarget($this->cmdClass, $this->cmd));
155 $this->ctrl->setParameterByClass(get_class($this->cmdClass), 'seed', '');
156
157 //$toolbar->addComponent($ui->factory()->viewControl()->section($b1,$b2,$b3));
158 $toolbar->addStickyItem($ui->factory()->viewControl()->section($b1, $b2, $b3));
159 $toolbar->addSeparator();
160
161 return $tpl->get();
162 }
163
164 protected function incrementDate($a_count)
165 {
166 switch ($this->increment) {
168
169 $day = $this->seed->get(IL_CAL_FKT_DATE, 'j');
170 if ($day > 28) {
171 $this->seed->increment(IL_CAL_DAY, (31 - $day) * -1);
172 }
173 // no break
174 default:
175 $this->seed->increment($this->increment, $a_count);
176 break;
177 }
178 }
179}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_DATETIME
const IL_CAL_FKT_DATE
const IL_CAL_DAY
__construct($cmdClass, ilDate $seed, $a_increment, $cmd='')
Constructor.
static _getInstanceByUserId($a_user_id)
get singleton instance
static _numericDayToString($a_day, $a_long=true)
get
static _buildWeekDayList($a_day, $a_weekstart)
build week day list
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
static setUseRelativeDates($a_status)
set use relative dates
@classDescription Date and time handling
static _within(ilDateTime $dt, ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
Check whether an date is within a date duration given by start and end.
Class for single dates.
special template class to simplify handling of ITX/PEAR
static now()
Return current timestamp in Y-m-d H:i:s format.
global $DIC
Definition: goto.php:24
ui()
Definition: ui.php:5