ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilCalendarHeaderNavigationGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 /*
5  +-----------------------------------------------------------------------------+
6  | ILIAS open source |
7  +-----------------------------------------------------------------------------+
8  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
9  | |
10  | This program is free software; you can redistribute it and/or |
11  | modify it under the terms of the GNU General Public License |
12  | as published by the Free Software Foundation; either version 2 |
13  | of the License, or (at your option) any later version. |
14  | |
15  | This program is distributed in the hope that it will be useful, |
16  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18  | GNU General Public License for more details. |
19  | |
20  | You should have received a copy of the GNU General Public License |
21  | along with this program; if not, write to the Free Software |
22  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23  +-----------------------------------------------------------------------------+
24 */
25 
31 {
32  protected object $cmdClass;
33  protected string $cmd;
34  protected ilDate $seed;
35  protected string $increment = '';
36 
37  protected string $html;
38 
39  protected ilLanguage $lng;
43  protected ilObjUser $user;
45  protected \ILIAS\DI\UIServices $ui;
46 
47  public function __construct(object $cmdClass, ilDate $seed, string $a_increment, string $cmd = '')
48  {
49  global $DIC;
50 
51  $this->lng = $DIC->language();
52 
53  $this->ctrl = $DIC->ctrl();
54  $this->cmdClass = $cmdClass;
55  $this->seed = clone $seed;
56  $this->increment = $a_increment;
57  $this->cmd = $cmd;
58  $this->toolbar = $DIC->toolbar();
59  $this->ui = $DIC->ui();
60  $this->user = $DIC->user();
61  $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($this->user->getId());
62  }
63 
64  public function getHTML(): string
65  {
66  $today = new ilDateTime(time(), IL_CAL_UNIX, $this->user->getTimeZone());
67  $tpl = new ilTemplate("tpl.navigation_header.html", true, true, "Services/Calendar");
68 
69  // previous button
70  $contains_today = false;
71  $this->incrementDate(-1);
72  $this->ctrl->setParameterByClass(get_class($this->cmdClass), 'seed', $this->seed->get(IL_CAL_DATE));
73  $b1 = $this->ui->factory()->button()->standard(
74  $this->lng->txt("previous"),
75  $this->ctrl->getLinkTarget($this->cmdClass, $this->cmd)
76  );
77 
78  // today button
79  $this->incrementDate(1);
81  switch ($this->increment) {
82  case ilDateTime::DAY:
83  $tpl->setVariable(
84  "TXT_TITLE",
85  ilCalendarUtil::_numericDayToString((int) $this->seed->get(IL_CAL_FKT_DATE, 'w')) .
86  ", " . ilDatePresentation::formatDate($this->seed)
87  );
88  if (date("Y-m-d") === $this->seed->get(IL_CAL_FKT_DATE, 'Y-m-d')) {
89  $contains_today = true;
90  }
91  break;
92 
93  case ilDateTime::WEEK:
94  $weekday_list = ilCalendarUtil::_buildWeekDayList(
95  $this->seed,
96  $this->user_settings->getWeekStart()
97  )->get();
98  $start = current($weekday_list);
99  $end = end($weekday_list);
100  $tpl->setVariable("TXT_TITLE", $this->lng->txt('week') . ' ' . $this->seed->get(IL_CAL_FKT_DATE, 'W') .
101  ", " . ilDatePresentation::formatDate($start) . " - " .
103  $il_date_now = new ilDateTime(ilUtil::now(), IL_CAL_DATETIME);
104  if (ilDate::_within($il_date_now, $start, $end)) {
105  $contains_today = true;
106  }
107  break;
108 
109  case ilDateTime::MONTH:
110  $tpl->setVariable(
111  "TXT_TITLE",
112  $this->lng->txt('month_' . $this->seed->get(IL_CAL_FKT_DATE, 'm') . '_long') .
113  ' ' . $this->seed->get(IL_CAL_FKT_DATE, 'Y')
114  );
115  if ($this->seed->get(IL_CAL_FKT_DATE, 'Y-m') == date("Y-m")) {
116  $contains_today = true;
117  }
118  break;
119  }
121  $this->ctrl->setParameterByClass(
122  get_class($this->cmdClass),
123  'seed',
124  $today->get(IL_CAL_DATE)
125  );
126  if ($contains_today) {
127  $b2 = $this->ui->factory()->button()->standard(
128  $this->lng->txt("today"),
129  $this->ctrl->getLinkTarget($this->cmdClass, $this->cmd)
130  )->withEngagedState(true);
131  } else {
132  $b2 = $this->ui->factory()->button()->standard(
133  $this->lng->txt("today"),
134  $this->ctrl->getLinkTarget($this->cmdClass, $this->cmd)
135  );
136  }
137  // next button
138  $this->incrementDate(1);
139  $this->ctrl->setParameterByClass(get_class($this->cmdClass), 'seed', $this->seed->get(IL_CAL_DATE));
140  $b3 = $this->ui->factory()->button()->standard(
141  $this->lng->txt("next"),
142  $this->ctrl->getLinkTarget($this->cmdClass, $this->cmd)
143  );
144  $this->ctrl->setParameterByClass(get_class($this->cmdClass), 'seed', '');
145  $this->toolbar->addStickyItem($this->ui->factory()->viewControl()->section($b1, $b2, $b3));
146  $this->toolbar->addSeparator();
147 
148  return $tpl->get();
149  }
150 
151  protected function incrementDate(int $a_count): void
152  {
153  switch ($this->increment) {
154  case ilDateTime::MONTH:
155  $day = $this->seed->get(IL_CAL_FKT_DATE, 'j');
156  if ($day > 28) {
157  $this->seed->increment(IL_CAL_DAY, (31 - $day) * -1);
158  }
159  // no break
160  default:
161  $this->seed->increment($this->increment, $a_count);
162  break;
163  }
164  }
165 }
get(int $a_format, string $a_format_str='', string $a_tz='')
get formatted date
__construct(object $cmdClass, ilDate $seed, string $a_increment, string $cmd='')
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
static _buildWeekDayList(ilDate $a_day, int $a_weekstart)
build week day list public
const IL_CAL_UNIX
static now()
Return current timestamp in Y-m-d H:i:s format.
static _getInstanceByUserId(int $a_user_id)
global $DIC
Definition: feed.php:28
const IL_CAL_DAY
const IL_CAL_FKT_DATE
static _numericDayToString(int $a_day, bool $a_long=true)
const IL_CAL_DATE
static setUseRelativeDates(bool $a_status)
set use relative dates
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.