ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilCalendarUtil Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilCalendarUtil:

Static Public Member Functions

static convertDateToUtcDBTimestamp (\ilDateTime $date=null)
 
static _isToday (ilDateTime $date)
 
static _numericMonthToString (int $a_month, bool $a_long=true)
 numeric month to string More...
 
static _numericDayToString (int $a_day, bool $a_long=true)
 
static _buildWeekDayList (ilDate $a_day, int $a_weekstart)
 build week day list public More...
 
static _buildMonthDayList (int $a_month, int $a_year, int $weekstart)
 Build a month day list. More...
 
static initJSCalendar ()
 
static getZoneInfoFile ($a_tz)
 
static _getShortTimeZoneList ()
 get short timezone list More...
 
static _isLeapYear (int $a_year)
 check if a given year is a leap year More...
 
static _getMaxDayOfMonth (int $a_year, int $a_month)
 get max day of month 2008,2 => 29 More...
 
static calculateFontColor (string $a_html_color_code)
 Calculate best font color from html hex color code. More...
 
static getHourSelection (int $a_format)
 Get hour selection depending on user specific hour format. More...
 
static initDefaultCalendarByType (int $a_type_id, int $a_usr_id, string $a_title, bool $a_create=false)
 Init the default calendar for given type and user. More...
 
static getUserDateFormat (int $a_add_time=0, bool $a_for_parsing=false)
 Parse current user setting into date/time format. More...
 
static initDateTimePicker ()
 
static addDateTimePicker (string $a_id, ?int $a_add_time=null, ?array $a_custom_config=null, ?string $a_id2=null, ?array $a_custom_config2=null, ?string $a_toggle_id=null, ?string $a_subform_id=null)
 Add date time picker to element. More...
 
static getCodeForPicker (string $a_id, ?int $a_add_time=null, ?array $a_custom_config=null, ?string $a_id2=null, ?array $a_custom_config2=null, ?string $a_toggle_id=null, ?string $a_subform_id=null)
 Add date time picker to element. More...
 
static parseDateString (string $a_date, bool $a_add_time=false, bool $a_use_generic_format=false)
 Parse (incoming) string to date/time object. More...
 
static parseIncomingDate ($a_value, bool $a_add_time=false)
 Try to parse incoming value to date object. More...
 

Static Public Attributes

static string $init_done
 

Static Protected Attributes

static bool $init_datetimepicker = false
 

Static Private Attributes

static ilDateTime $today = null
 
static array $default_calendar = array()
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class ilCalendarUtil

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m

Definition at line 23 of file class.ilCalendarUtil.php.

Member Function Documentation

◆ _buildMonthDayList()

static ilCalendarUtil::_buildMonthDayList ( int  $a_month,
int  $a_year,
int  $weekstart 
)
static

Build a month day list.

Parameters
intmonth
intyear
intweekstart (0 => Sunday,1 => Monday)
Returns
ilDateList

Definition at line 114 of file class.ilCalendarUtil.php.

References IL_CAL_FKT_DATE, IL_CAL_FKT_GETDATE, IL_CAL_UNIX, and ilDateList\TYPE_DATE.

Referenced by ilMiniCalendarGUI\addMiniMonth(), ilCalendarBlockGUI\addMiniMonth(), and ilCalendarMonthGUI\show().

114  : ilDateList
115  {
116  $day_list = new ilDateList(ilDateList::TYPE_DATE);
117 
118  $prev_month = ($a_month == 1) ? 12 : $a_month - 1;
119  $prev_year = ($prev_month == 12) ? $a_year - 1 : $a_year;
120  $next_month = $a_month == 12 ? 1 : $a_month + 1;
121  $next_year = $a_month == 12 ? $a_year + 1 : $a_year;
122 
123  $days_in_month = self::_getMaxDayOfMonth($a_year, $a_month);
124  $days_in_prev_month = self::_getMaxDayOfMonth($a_year, $prev_month);
125 
126  $week_day['year'] = $a_year;
127  $week_day['mon'] = $a_month;
128  $week_day['mday'] = 1;
129  $week_day['hours'] = 0;
130  $week_day['minutes'] = 0;
131  $week_day = new ilDate($week_day, IL_CAL_FKT_GETDATE);
132 
133  $weekday = $week_day->get(IL_CAL_FKT_DATE, 'w');
134  $first_day_offset = (($weekday - $weekstart) < 0) ? 6 : $weekday - $weekstart;
135 
136  for ($i = 0; $i < 42; $i++) {
137  if ($i < $first_day_offset) {
138  $day = $days_in_prev_month - $first_day_offset + $i + 1;
139 
140  $day_list->add(new ilDate(
141  gmmktime(
142  0,
143  0,
144  0,
145  $prev_month,
146  $days_in_prev_month - $first_day_offset + $i + 1,
147  $prev_year
148  ),
150  ));
151  } elseif ($i < $days_in_month + $first_day_offset) {
152  $day = $i - $first_day_offset + 1;
153 
154  $day_list->add(new ilDate(
155  gmmktime(
156  0,
157  0,
158  0,
159  $a_month,
160  $i - $first_day_offset + 1,
161  $a_year
162  ),
164  ));
165  } else {
166  $day = $i - $days_in_month - $first_day_offset + 1;
167  $day_list->add(new ilDate(
168  gmmktime(
169  0,
170  0,
171  0,
172  $next_month,
173  $i - $days_in_month - $first_day_offset + 1,
174  $next_year
175  ),
177  ));
178  }
179  if ($i == 34 and ($day < 15 or $day == $days_in_month)) {
180  break;
181  }
182  }
183  return $day_list;
184  }
const IL_CAL_UNIX
List of dates.
const IL_CAL_FKT_DATE
const IL_CAL_FKT_GETDATE
+ Here is the caller graph for this function:

◆ _buildWeekDayList()

static ilCalendarUtil::_buildWeekDayList ( ilDate  $a_day,
int  $a_weekstart 
)
static

build week day list public

Parameters
ilDatea day in a week
intweekstart
Returns
ilDateList

Definition at line 88 of file class.ilCalendarUtil.php.

References ilDate\get(), IL_CAL_DAY, IL_CAL_FKT_GETDATE, and ilDateList\TYPE_DATE.

Referenced by ilCalendarViewGUI\getBucketTitle(), ILIAS\BookingManager\BookingProcess\WeekGridGUI\getHoursOfDay(), ilCalendarHeaderNavigationGUI\getHTML(), ILIAS\BookingManager\BookingProcess\WeekGUI\getHTML(), and ilCalendarWeekGUI\show().

88  : ilDateList
89  {
90  $day_list = new ilDateList(ilDateList::TYPE_DATE);
91 
92  $start = clone $a_day;
93  $start_info = $start->get(IL_CAL_FKT_GETDATE, '', 'UTC');
94  $day_diff = $a_weekstart - $start_info['isoday'];
95  if (abs($day_diff) === 7) {
96  $day_diff = 0;
97  }
98  $start->increment(IL_CAL_DAY, $day_diff);
99  $day_list->add($start);
100  for ($i = 1; $i < 7; $i++) {
101  $start->increment(IL_CAL_DAY, 1);
102  $day_list->add($start);
103  }
104  return $day_list;
105  }
get(int $a_format, string $a_format_str='', string $a_tz='')
const IL_CAL_DAY
List of dates.
const IL_CAL_FKT_GETDATE
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getMaxDayOfMonth()

static ilCalendarUtil::_getMaxDayOfMonth ( int  $a_year,
int  $a_month 
)
static

get max day of month 2008,2 => 29

Definition at line 381 of file class.ilCalendarUtil.php.

Referenced by ilCalendarRecurrenceCalculator\applyBYMONTHDAYRules(), ilCalendarRecurrenceCalculator\getMonthWeekDays(), and ilCalendarSchedule\initPeriod().

381  : int
382  {
383  if (function_exists('cal_days_in_month')) {
384  return cal_days_in_month(CAL_GREGORIAN, $a_month, $a_year);
385  }
386  return (int) date('t', mktime(0, 0, 0, $a_month, 1, $a_year));
387  }
+ Here is the caller graph for this function:

◆ _getShortTimeZoneList()

static ilCalendarUtil::_getShortTimeZoneList ( )
static

get short timezone list

Definition at line 284 of file class.ilCalendarUtil.php.

Referenced by ilObjCalendarSettingsGUI\initFormSettings(), ilPersonalSettingsGUI\initGeneralSettingsForm(), and ilCalendarUserSettingsGUI\initSettingsForm().

284  : array
285  {
286  return array(
287  'Pacific/Samoa' => 'GMT-11: Midway Islands, Samoa',
288  'US/Hawaii' => 'GMT-10:00: Hawaii, Polynesia',
289  'US/Alaska' => 'GMT-9:00: Alaska',
290  'America/Los_Angeles' => 'GMT-8:00: Tijuana, Los Angeles, Seattle, Vancouver',
291  'US/Arizona' => 'GMT-7:00: Arizona',
292  'America/Chihuahua' => 'GMT-7:00: Chihuahua, La Paz, Mazatlan',
293  'America/Denver' => 'GMT-7:00: Arizona, Denver, Salt Lake City, Calgary',
294  'America/Chicago' => 'GMT-6:00: Chicago, Dallas, Kansas City, Winnipeg',
295  'America/Monterrey' => 'GMT-6:00: Guadalajara, Mexico City, Monterrey',
296  'Canada/Saskatchewan' => 'GMT-6:00: Saskatchewan',
297  'US/Central' => 'GMT-6:00: Central America',
298  'America/Bogota' => 'GMT-5:00: Bogota, Lima, Quito',
299  'US/East-Indiana' => 'GMT-5:00: East-Indiana',
300  'America/New_York' => 'GMT-5:00: New York, Miami, Atlanta, Detroit, Toronto',
301  'Canada/Atlantic' => 'GMT-4:00: Atlantic (Canada)',
302  'America/La_Paz' => 'GMT-4:00: Carcas, La Paz',
303  'America/Santiago' => 'GMT-4:00: Santiago',
304  'Canada/Newfoundland' => 'GMT-3:00: Newfoundland',
305  'Brazil/East' => 'GMT-3:00: Sao Paulo',
306  'America/Argentina/Buenos_Aires' => 'GMT-3:00: Buenes Aires, Georgtown',
307  'Etc/GMT+3' => 'GMT-3:00: Greenland, Uruguay, Surinam',
308  'Atlantic/Cape_Verde' => 'GMT-2:00: Cape Verde, Greenland, South Georgia',
309  'Atlantic/Azores' => 'GMT-1:00: Azores',
310  'Africa/Casablanca' => 'GMT+0:00: Casablanca, Monrovia',
311  'Europe/London' => 'GMT+0:00: Dublin, Edinburgh, Lisbon, London',
312  'Europe/Berlin' => 'GMT+1:00: Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna',
313  'Europe/Belgrade' => 'GMT+1:00: Belgrade, Bratislava, Budapest, Ljubljana, Prague',
314  'Europe/Paris' => 'GMT+1:00: Brussels, Copenhagen, Paris, Madrid',
315  'Europe/Sarajevo' => 'GMT+1:00: Sarajevo, Skopje, Warsaw, Zagreb',
316  'Africa/Lagos' => 'GMT+1:00: West-Central Africa',
317  'Europe/Athens' => 'GMT+2:00: Athens, Beirut, Istanbul, Minsk',
318  'Europe/Bucharest' => 'GMT+2:00: Bucharest',
319  'Africa/Harare' => 'GMT+2:00: Harare, Pratoria',
320  'Europe/Helsinki' => 'GMT+2:00: Helsinki, Kiev, Riga, Sofia, Tallinn, Vilnius',
321  'Asia/Jerusalem' => 'GMT+2:00: Jerusalem',
322  'Africa/Cairo' => 'GMT+2:00: Cairo',
323  'Asia/Baghdad' => 'GMT+3:00: Baghdad',
324  'Asia/Kuwait' => 'GMT+3:00: Kuwait, Riyadh',
325  'Europe/Moscow' => 'GMT+3:00: Moscow, Saint Petersburg',
326  'Africa/Nairobi' => 'GMT+3:00: Nairobi',
327  'Asia/Tehran' => 'GMT+3:30: Tehran',
328  'Asia/Muscat' => 'GMT+4:00: Abu Dhabi, Muscat',
329  'Asia/Baku' => 'GMT+4:00: Baku, Tbilisi, Erivan',
330  'Asia/Kabul' => 'GMT+4:00: Kabul',
331  'Asia/Karachi' => 'GMT+5:00: Islamabad, Karachi, Taschkent',
332  'Asia/Yekaterinburg' => 'GMT+5:00: Yekaterinburg',
333  'Asia/Calcutta' => 'GMT+5:30: New Dehli',
334  'Asia/Katmandu' => 'GMT+5:45: Katmandu',
335  'Asia/Novosibirsk' => 'GMT+6:00: Almaty, Novosibirsk',
336  'Asia/Dhaka' => 'GMT+6:00: Astana, Dhaka',
337  'Asia/Rangoon' => 'GMT+6:00: Sri Jayawardenepura, Rangoon',
338  'Asia/Jakarta' => 'GMT+7:00: Bangkok, Hanoi, Jakarta',
339  'Asia/Krasnoyarsk' => 'GMT+7:00: Krasnoyarsk',
340  'Asia/Irkutsk' => 'GMT+8:00: Irkutsk, Ulan Bator',
341  'Asia/Singapore' => 'GMT+8:00: Kuala Lumpour, Singapore',
342  'Asia/Hong_Kong' => 'GMT+8:00: Beijing, Chongqing, Hong kong, Urumchi',
343  'Australia/Perth' => 'GMT+8:00: Perth',
344  'Asia/Taipei' => 'GMT+8:00: Taipei',
345  'Asia/Yakutsk' => 'GMT+9:00: Yakutsk',
346  'Asia/Tokyo' => 'GMT+9:00: Osaka, Sapporo, Tokyo',
347  'Asia/Seoul' => 'GMT+9:00: Seoul, Darwin, Adelaide',
348  'Australia/Brisbane' => 'GMT+10:00: Brisbane',
349  'Australia/Sydney' => 'GMT+10:00: Canberra, Melbourne, Sydney',
350  'Pacific/Guam' => 'GMT+10:00: Guam, Port Moresby',
351  'Australia/Hobart' => 'GMT+10:00: Hobart',
352  'Asia/Vladivostok' => 'GMT+10:00: Vladivostok',
353  'Asia/Magadan' => 'GMT+11:00: Salomon Islands, New Caledonia, Magadan',
354  'Pacific/Auckland' => 'GMT+12:00: Auckland, Wellington',
355  'Pacific/Fiji' => 'GMT+12:00: Fiji, Kamchatka, Marshall-Islands'
356  );
357  }
+ Here is the caller graph for this function:

◆ _isLeapYear()

static ilCalendarUtil::_isLeapYear ( int  $a_year)
static

check if a given year is a leap year

Definition at line 362 of file class.ilCalendarUtil.php.

Referenced by ilCalendarRecurrenceCalculator\getYearWeekDays().

362  : bool
363  {
364  $is_leap = false;
365  if ($a_year % 4 == 0) {
366  $is_leap = true;
367  if ($a_year % 100 == 0) {
368  $is_leap = false;
369  if ($a_year % 400) {
370  return true;
371  }
372  }
373  }
374  return $is_leap;
375  }
+ Here is the caller graph for this function:

◆ _isToday()

static ilCalendarUtil::_isToday ( ilDateTime  $date)
static

Definition at line 41 of file class.ilCalendarUtil.php.

References $DIC, ilDateTime\_equals(), IL_CAL_DAY, and IL_CAL_UNIX.

Referenced by ilMiniCalendarGUI\addMiniMonth(), ilCalendarBlockGUI\addMiniMonth(), and ilCalendarMonthGUI\show().

41  : bool
42  {
43  global $DIC;
44 
45  $ilUser = $DIC['ilUser'];
46  if (!is_object(self::$today)) {
47  self::$today = new ilDateTime(time(), IL_CAL_UNIX, $ilUser->getTimeZone());
48  }
49  return ilDateTime::_equals(self::$today, $date, IL_CAL_DAY, $ilUser->getTimeZone());
50  }
const IL_CAL_UNIX
global $DIC
Definition: feed.php:28
const IL_CAL_DAY
static _equals(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
Check if two date are equal.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _numericDayToString()

static ilCalendarUtil::_numericDayToString ( int  $a_day,
bool  $a_long = true 
)
static
Parameters
intday of week (0 for sunday, 1 for monday)
boolshort or long day translation

Definition at line 70 of file class.ilCalendarUtil.php.

References $DIC, and $lng.

Referenced by ilCalendarWeekGUI\addHeaderDate(), ilMiniCalendarGUI\addMiniMonth(), ilCalendarBlockGUI\addMiniMonth(), ilRecurrenceInputGUI\buildMonthlyByDaySelection(), ilRecurrenceInputGUI\buildWeekDaySelection(), ilRecurrenceInputGUI\buildYearlyByDaySelection(), ilSessionStatisticsGUI\exportCSV(), ilBookingReservationsTableGUI\fillRow(), ilBookingReservationsTableGUI\fillRowCSV(), ilBookingReservationsTableGUI\fillRowExcel(), ilSessionStatisticsGUI\getChart(), ILIAS\BookingManager\BookingProcess\WeekGridGUI\getHoursOfDay(), ilCalendarHeaderNavigationGUI\getHTML(), ilBookingReservationsTableGUI\initFilter(), ilCalendarDayGUI\show(), and ilCalendarMonthGUI\show().

70  : string
71  {
72  global $DIC;
73 
74  $lng = $DIC['lng'];
75  $lng->loadLanguageModule('dateplaner');
76  static $days = array('Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su');
77 
78  return $a_long ? $lng->txt($days[$a_day] . '_long') : $lng->txt($days[$a_day] . '_short');
79  }
global $DIC
Definition: feed.php:28
$lng
+ Here is the caller graph for this function:

◆ _numericMonthToString()

static ilCalendarUtil::_numericMonthToString ( int  $a_month,
bool  $a_long = true 
)
static

numeric month to string

Parameters
intmonth (1-12)
boolshort or long month translation

Definition at line 57 of file class.ilCalendarUtil.php.

References $DIC, and $lng.

Referenced by ilRecurrenceInputGUI\buildYearlyByDaySelection(), ilRecurrenceInputGUI\buildYearlyByMonthDaySelection(), ilDatePresentation\formatDate(), ILIAS\BookingManager\BookingProcess\WeekGridGUI\getHoursOfDay(), ilObjBlogGUI\renderNavigationByDate(), ilCalendarDayGUI\show(), ilCalendarMonthGUI\show(), and ilWikiStatGUI\viewToolbar().

57  : string
58  {
59  global $DIC;
60 
61  $lng = $DIC['lng'];
62  $month = $a_month < 10 ? '0' . $a_month : $a_month;
63  return $a_long ? $lng->txt('month_' . $month . '_long') : $lng->txt('month_' . $month . '_short');
64  }
global $DIC
Definition: feed.php:28
$lng
+ Here is the caller graph for this function:

◆ addDateTimePicker()

static ilCalendarUtil::addDateTimePicker ( string  $a_id,
?int  $a_add_time = null,
?array  $a_custom_config = null,
?string  $a_id2 = null,
?array  $a_custom_config2 = null,
?string  $a_toggle_id = null,
?string  $a_subform_id = null 
)
static

Add date time picker to element.

Parameters
string$a_id
int$a_add_time1=hh:mm, 2=hh:mm:ss
array$a_custom_config
string$a_id2
array$a_custom_config2
string$a_toggle_id
string$a_subform_id

Definition at line 530 of file class.ilCalendarUtil.php.

References $DIC.

Referenced by ilDateTimeInputGUI\render(), and ilDateDurationInputGUI\render().

538  : void {
539  global $DIC;
540 
541  $tpl = $DIC->ui()->mainTemplate();
542  foreach (self::getCodeForPicker(
543  $a_id,
544  $a_add_time,
545  $a_custom_config,
546  $a_id2,
547  $a_custom_config2,
548  $a_toggle_id,
549  $a_subform_id
550  ) as $code) {
551  $tpl->addOnLoadCode($code);
552  }
553  }
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ calculateFontColor()

static ilCalendarUtil::calculateFontColor ( string  $a_html_color_code)
static

Calculate best font color from html hex color code.

Parameters
stringhex value of color
Returns
string #ffffff or #000000

Definition at line 394 of file class.ilCalendarUtil.php.

Referenced by ilCalendarWeekGUI\showAppointment(), ilCalendarDayGUI\showAppointment(), ilCalendarMonthGUI\showEvents(), ilCalendarWeekGUI\showFulldayAppointment(), and ilCalendarDayGUI\showFulldayAppointment().

394  : string
395  {
396  if (strpos($a_html_color_code, '#') !== 0 or strlen($a_html_color_code) != 7) {
397  return '#000000';
398  }
399 
400  // http://en.wikipedia.org/wiki/Luminance_(relative)
401  $lum = round(hexdec(substr($a_html_color_code, 1, 2)) * 0.2126 +
402  hexdec(substr($a_html_color_code, 3, 2)) * 0.7152 +
403  hexdec(substr($a_html_color_code, 5, 2)) * 0.0722);
404  return ($lum <= 128) ? "#FFFFFF" : "#000000";
405  }
+ Here is the caller graph for this function:

◆ convertDateToUtcDBTimestamp()

static ilCalendarUtil::convertDateToUtcDBTimestamp ( \ilDateTime  $date = null)
static

Definition at line 30 of file class.ilCalendarUtil.php.

References IL_CAL_DATE, IL_CAL_DATETIME, and ilTimeZone\UTC.

Referenced by ilObjGroup\update(), and ilObjCourse\updateSettings().

30  : ?string
31  {
32  if (is_null($date)) {
33  return null;
34  }
35  if ($date instanceof \ilDate) {
36  return $date->get(IL_CAL_DATE);
37  }
38  return $date->get(IL_CAL_DATETIME, '', ilTimeZone::UTC);
39  }
const IL_CAL_DATETIME
const IL_CAL_DATE
+ Here is the caller graph for this function:

◆ getCodeForPicker()

static ilCalendarUtil::getCodeForPicker ( string  $a_id,
?int  $a_add_time = null,
?array  $a_custom_config = null,
?string  $a_id2 = null,
?array  $a_custom_config2 = null,
?string  $a_toggle_id = null,
?string  $a_subform_id = null 
)
static

Add date time picker to element.

Parameters
string$a_id
int$a_add_time1=hh:mm, 2=hh:mm:ss
array$a_custom_config
string$a_id2
array$a_custom_config2
string$a_toggle_id
string$a_subform_id
Returns
string

Whether the start of the week in the picker is Sunday or Monday should depend on the user calendar settings (#21666). Unfortunately this is not a direct config of the picker, but is inherent in the locale, so it needs to be shoehorned into there.

0 for Sunday, 1 for Monday

Definition at line 566 of file class.ilCalendarUtil.php.

References $DIC, and ilCalendarUserSettings\_getInstanceByUserId().

Referenced by ilDateTimeInputGUI\getOnloadCode().

574  : array {
575  global $DIC;
576 
577  $ilUser = $DIC['ilUser'];
578  self::initDateTimePicker();
579 
580  // fix for mantis 22994 => default to english language
581  $language = 'en';
582  if ($ilUser->getLanguage() != 'ar') {
583  $language = $ilUser->getLanguage();
584  }
585  $default = array(
586  'locale' => $language,
587  'stepping' => 5,
588  'useCurrent' => false,
589  'calendarWeeks' => true,
590  'toolbarPlacement' => 'top',
591  //'showTodayButton' => true,
592  'showClear' => true,
593  //'showClose' => true,
594  'keepInvalid' => true,
595  'sideBySide' => true,
596  //'collapse' => false,
597  'format' => self::getUserDateFormat((bool) $a_add_time)
598  );
599 
600  $config = (!$a_custom_config)
601  ? $default
602  : array_merge($default, $a_custom_config);
603 
604  $code = [];
605 
614  $start_of_week = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId())->getWeekStart();
615  $code[] =
616  'if (moment) {
617  moment.updateLocale("' . $language . '", {week: {dow: ' . $start_of_week . '}});
618  }';
619 
620  $code[] = '$("#' . $a_id . '").datetimepicker(' . json_encode($config) . ')';
621 
622  // optional 2nd picker aka duration
623  if ($a_id2) {
624  $config2 = (!$a_custom_config2)
625  ? $default
626  : array_merge($default, $a_custom_config2);
627 
628  $config2["useCurrent"] = false; //Important! See issue #1075
629 
630  $code[] = '$("#' . $a_id2 . '").datetimepicker(' . json_encode($config2) . ')';
631 
632  // duration limits, diff and subform handling
633  $code[] = 'il.Form.initDateDurationPicker("' . $a_id . '","' . $a_id2 . '","' . $a_toggle_id . '","' . $a_subform_id . '");';
634  } elseif ($a_subform_id) {
635  // subform handling
636  $code[] = 'il.Form.initDatePicker("' . $a_id . '","' . $a_subform_id . '");';
637  }
638  return $code;
639  }
static _getInstanceByUserId(int $a_user_id)
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getHourSelection()

static ilCalendarUtil::getHourSelection ( int  $a_format)
static

Get hour selection depending on user specific hour format.

Definition at line 410 of file class.ilCalendarUtil.php.

References ilCalendarSettings\TIME_FORMAT_12, and ilCalendarSettings\TIME_FORMAT_24.

Referenced by ilObjCalendarSettingsGUI\initFormSettings(), and ilCalendarUserSettingsGUI\initSettingsForm().

410  : array
411  {
412  $options = [];
413  switch ($a_format) {
415  for ($i = 0; $i < 24; $i++) {
416  $options[$i] = sprintf('%02d:00', $i);
417  }
418  break;
419 
421  for ($i = 0; $i < 24; $i++) {
422  $options[$i] = date('h a', mktime($i, 0, 0, 1, 1, 2000));
423  }
424  break;
425  }
426  return $options;
427  }
+ Here is the caller graph for this function:

◆ getUserDateFormat()

static ilCalendarUtil::getUserDateFormat ( int  $a_add_time = 0,
bool  $a_for_parsing = false 
)
static

Parse current user setting into date/time format.

Parameters
?int$a_add_time 1=hh:mm, 2=hh:mm:ss
bool$a_for_parsing
Returns
string

Definition at line 474 of file class.ilCalendarUtil.php.

References $DIC, and ilCalendarSettings\TIME_FORMAT_24.

Referenced by ilPRGActionNoteBuilder\getUserDateFormat(), ilStudyProgrammeUserTable\getUserDateFormat(), ilDateTimeInputGUI\render(), ilDateDurationInputGUI\render(), and ILIAS\EmployeeTalk\Notification\NotificationHandler\send().

474  : string
475  {
476  global $DIC;
477 
478  $ilUser = $DIC['ilUser'];
479 
480  $format = (string) $ilUser->getDateFormat();
481 
482  if ($a_add_time) {
483  $format .= " " . (($ilUser->getTimeFormat() == ilCalendarSettings::TIME_FORMAT_24)
484  ? "H:i"
485  : "h:ia");
486  if ($a_add_time == 2) {
487  $format .= ":s";
488  }
489  }
490 
491  // translate datepicker format to PHP format
492  if (!$a_for_parsing) {
493  $format = str_replace("d", "DD", $format);
494  $format = str_replace("m", "MM", $format);
495  $format = str_replace("i", "mm", $format);
496  $format = str_replace("Y", "YYYY", $format);
497  $format = str_replace("H", "HH", $format);
498  $format = str_replace("h", "hh", $format);
499  $format = str_replace("s", "ss", $format);
500  }
501 
502  return $format;
503  }
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ getZoneInfoFile()

static ilCalendarUtil::getZoneInfoFile (   $a_tz)
static

Definition at line 271 of file class.ilCalendarUtil.php.

Referenced by ilCalendarExport\createTimezones().

271  : string
272  {
273  if (!array_key_exists($a_tz, self::_getShortTimeZoneList())) {
274  return '';
275  }
276  $timezone_filename = str_replace('/', '_', $a_tz);
277  $timezone_filename .= '.ics';
278  return './Services/Calendar/zoneinfo/' . $timezone_filename;
279  }
+ Here is the caller graph for this function:

◆ initDateTimePicker()

static ilCalendarUtil::initDateTimePicker ( )
static

Definition at line 505 of file class.ilCalendarUtil.php.

References $DIC.

Referenced by ilPageObjectGUI\initEditing(), and ilExerciseManagementGUI\initIndividualDeadlineModal().

505  : void
506  {
507  global $DIC;
508  $tpl = $DIC->ui()->mainTemplate();
509 
510  if (!self::$init_datetimepicker) {
511  $tpl->addJavaScript("./node_modules/moment/min/moment-with-locales.min.js");
512  // unminified version does not work with jQuery 3.0
513  // https://github.com/Eonasdan/bootstrap-datetimepicker/issues/1684
514  $tpl->addJavaScript("./node_modules/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js");
515  $tpl->addJavaScript("Services/Form/js/Form.js"); // see ilPropertyFormGUI
516  self::$init_datetimepicker = true;
517  }
518  }
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ initDefaultCalendarByType()

static ilCalendarUtil::initDefaultCalendarByType ( int  $a_type_id,
int  $a_usr_id,
string  $a_title,
bool  $a_create = false 
)
static

Init the default calendar for given type and user.

Definition at line 432 of file class.ilCalendarUtil.php.

References $DIC, $ilDB, $res, ilCalendarCategory\DEFAULT_COLOR, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by ilConsultationHourUtils\bookAppointment(), ILIAS\BookingManager\BookingProcess\BookingProcessManager\bookSingle(), and ilConsultationHoursGUI\createAppointments().

437  : ?ilCalendarCategory {
438  global $DIC;
439 
440  $ilDB = $DIC['ilDB'];
441  if (isset(self::$default_calendar[$a_usr_id]) and isset(self::$default_calendar[$a_usr_id][$a_type_id])) {
442  return self::$default_calendar[$a_usr_id][$a_type_id];
443  }
444 
445  $query = "SELECT cat_id FROM cal_categories " .
446  "WHERE obj_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
447  "AND type = " . $ilDB->quote($a_type_id, 'integer');
448  $res = $ilDB->query($query);
449  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
450  return self::$default_calendar[$a_usr_id][$a_type_id] = new ilCalendarCategory($row->cat_id);
451  }
452 
453  if (!$a_create) {
454  return null;
455  }
456 
457  // Create default calendar
458  self::$default_calendar[$a_usr_id][$a_type_id] = new ilCalendarCategory();
459  self::$default_calendar[$a_usr_id][$a_type_id]->setType($a_type_id);
460  self::$default_calendar[$a_usr_id][$a_type_id]->setColor(ilCalendarCategory::DEFAULT_COLOR);
461  self::$default_calendar[$a_usr_id][$a_type_id]->setTitle($a_title);
462  self::$default_calendar[$a_usr_id][$a_type_id]->setObjId($a_usr_id);
463  self::$default_calendar[$a_usr_id][$a_type_id]->add();
464 
465  return self::$default_calendar[$a_usr_id][$a_type_id];
466  }
$res
Definition: ltiservices.php:69
Stores calendar categories.
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ initJSCalendar()

static ilCalendarUtil::initJSCalendar ( )
static

Definition at line 186 of file class.ilCalendarUtil.php.

References $DIC, and $lng.

186  : void
187  {
188  global $DIC;
189 
190  $tpl = $DIC['tpl'];
191  $lng = $DIC['lng'];
192 
193  if (self::$init_done == "done") {
194  return;
195  }
196 
197  $lng->loadLanguageModule("jscalendar");
198  $tpl->addBlockFile(
199  "CALENDAR_LANG_JAVASCRIPT",
200  "calendar_javascript",
201  "tpl.calendar.html",
202  "Services/Calendar"
203  );
204  $tpl->setCurrentBlock("calendar_javascript");
205  $tpl->setVariable("FULL_SUNDAY", $lng->txt("l_su"));
206  $tpl->setVariable("FULL_MONDAY", $lng->txt("l_mo"));
207  $tpl->setVariable("FULL_TUESDAY", $lng->txt("l_tu"));
208  $tpl->setVariable("FULL_WEDNESDAY", $lng->txt("l_we"));
209  $tpl->setVariable("FULL_THURSDAY", $lng->txt("l_th"));
210  $tpl->setVariable("FULL_FRIDAY", $lng->txt("l_fr"));
211  $tpl->setVariable("FULL_SATURDAY", $lng->txt("l_sa"));
212  $tpl->setVariable("SHORT_SUNDAY", $lng->txt("s_su"));
213  $tpl->setVariable("SHORT_MONDAY", $lng->txt("s_mo"));
214  $tpl->setVariable("SHORT_TUESDAY", $lng->txt("s_tu"));
215  $tpl->setVariable("SHORT_WEDNESDAY", $lng->txt("s_we"));
216  $tpl->setVariable("SHORT_THURSDAY", $lng->txt("s_th"));
217  $tpl->setVariable("SHORT_FRIDAY", $lng->txt("s_fr"));
218  $tpl->setVariable("SHORT_SATURDAY", $lng->txt("s_sa"));
219  $tpl->setVariable("FULL_JANUARY", $lng->txt("l_01"));
220  $tpl->setVariable("FULL_FEBRUARY", $lng->txt("l_02"));
221  $tpl->setVariable("FULL_MARCH", $lng->txt("l_03"));
222  $tpl->setVariable("FULL_APRIL", $lng->txt("l_04"));
223  $tpl->setVariable("FULL_MAY", $lng->txt("l_05"));
224  $tpl->setVariable("FULL_JUNE", $lng->txt("l_06"));
225  $tpl->setVariable("FULL_JULY", $lng->txt("l_07"));
226  $tpl->setVariable("FULL_AUGUST", $lng->txt("l_08"));
227  $tpl->setVariable("FULL_SEPTEMBER", $lng->txt("l_09"));
228  $tpl->setVariable("FULL_OCTOBER", $lng->txt("l_10"));
229  $tpl->setVariable("FULL_NOVEMBER", $lng->txt("l_11"));
230  $tpl->setVariable("FULL_DECEMBER", $lng->txt("l_12"));
231  $tpl->setVariable("SHORT_JANUARY", $lng->txt("s_01"));
232  $tpl->setVariable("SHORT_FEBRUARY", $lng->txt("s_02"));
233  $tpl->setVariable("SHORT_MARCH", $lng->txt("s_03"));
234  $tpl->setVariable("SHORT_APRIL", $lng->txt("s_04"));
235  $tpl->setVariable("SHORT_MAY", $lng->txt("s_05"));
236  $tpl->setVariable("SHORT_JUNE", $lng->txt("s_06"));
237  $tpl->setVariable("SHORT_JULY", $lng->txt("s_07"));
238  $tpl->setVariable("SHORT_AUGUST", $lng->txt("s_08"));
239  $tpl->setVariable("SHORT_SEPTEMBER", $lng->txt("s_09"));
240  $tpl->setVariable("SHORT_OCTOBER", $lng->txt("s_10"));
241  $tpl->setVariable("SHORT_NOVEMBER", $lng->txt("s_11"));
242  $tpl->setVariable("SHORT_DECEMBER", $lng->txt("s_12"));
243  $tpl->setVariable("ABOUT_CALENDAR", $lng->txt("about_calendar"));
244  $tpl->setVariable("ABOUT_CALENDAR_LONG", $lng->txt("about_calendar_long"));
245  $tpl->setVariable("ABOUT_TIME_LONG", $lng->txt("about_time"));
246  $tpl->setVariable("PREV_YEAR", $lng->txt("prev_year"));
247  $tpl->setVariable("PREV_MONTH", $lng->txt("prev_month"));
248  $tpl->setVariable("GO_TODAY", $lng->txt("go_today"));
249  $tpl->setVariable("NEXT_MONTH", $lng->txt("next_month"));
250  $tpl->setVariable("NEXT_YEAR", $lng->txt("next_year"));
251  $tpl->setVariable("SEL_DATE", $lng->txt("select_date"));
252  $tpl->setVariable("DRAG_TO_MOVE", $lng->txt("drag_to_move"));
253  $tpl->setVariable("PART_TODAY", $lng->txt("part_today"));
254  $tpl->setVariable("DAY_FIRST", $lng->txt("day_first"));
255  $tpl->setVariable("CLOSE", $lng->txt("close"));
256  $tpl->setVariable("TODAY", $lng->txt("today"));
257  $tpl->setVariable("TIME_PART", $lng->txt("time_part"));
258  $tpl->setVariable("DEF_DATE_FORMAT", $lng->txt("def_date_format"));
259  $tpl->setVariable("TT_DATE_FORMAT", $lng->txt("tt_date_format"));
260  $tpl->setVariable("WK", $lng->txt("wk"));
261  $tpl->setVariable("TIME", $lng->txt("time"));
262  $tpl->parseCurrentBlock();
263  $tpl->setCurrentBlock("CalendarJS");
264  $tpl->setVariable("LOCATION_JAVASCRIPT_CALENDAR", "./Services/Calendar/js/calendar.js");
265  $tpl->setVariable("LOCATION_JAVASCRIPT_CALENDAR_SETUP", "./Services/Calendar/js/calendar-setup.js");
266  $tpl->parseCurrentBlock();
267 
268  self::$init_done = "done";
269  }
global $DIC
Definition: feed.php:28
$lng

◆ parseDateString()

static ilCalendarUtil::parseDateString ( string  $a_date,
bool  $a_add_time = false,
bool  $a_use_generic_format = false 
)
static

Parse (incoming) string to date/time object.

Parameters
string$a_date
bool$a_add_time1=hh:mm, 2=hh:mm:ss
bool$a_use_generic_format
Returns
array date, warnings, errors
Exceptions
ilDateTimeException

Definition at line 649 of file class.ilCalendarUtil.php.

References $DIC, IL_CAL_DATE, and IL_CAL_DATETIME.

649  : array
650  {
651  global $DIC;
652 
653  $ilUser = $DIC['ilUser'];
654  if (!$a_use_generic_format) {
655  $out_format = self::getUserDateFormat($a_add_time, true);
656  } else {
657  $out_format = $a_add_time
658  ? "Y-m-d H:i:s"
659  : "Y-m-d";
660  }
661  $tmp = date_parse_from_format($out_format, $a_date);
662  $date = null;
663 
664  if (!$tmp["error_count"] &&
665  !$tmp["warning_count"]) {
666  $format = $tmp["year"] . "-" .
667  str_pad($tmp["month"], 2, "0", STR_PAD_LEFT) . "-" .
668  str_pad($tmp["day"], 2, "0", STR_PAD_LEFT);
669 
670  if ($a_add_time) {
671  $format .= " " .
672  str_pad($tmp["hour"], 2, "0", STR_PAD_LEFT) . ":" .
673  str_pad($tmp["minute"], 2, "0", STR_PAD_LEFT) . ":" .
674  str_pad($tmp["second"], 2, "0", STR_PAD_LEFT);
675 
676  $date = new ilDateTime($format, IL_CAL_DATETIME, $ilUser->getTimeZone());
677  } else {
678  $date = new ilDate($format, IL_CAL_DATE);
679  }
680  }
681 
682  return array(
683  "date" => $date
684  ,
685  "warnings" => sizeof($tmp["warnings"])
686  ? $tmp["warnings"]
687  : null
688  ,
689  "errors" => sizeof($tmp["errors"])
690  ? $tmp["errors"]
691  : null
692  );
693  }
const IL_CAL_DATETIME
global $DIC
Definition: feed.php:28
const IL_CAL_DATE

◆ parseIncomingDate()

static ilCalendarUtil::parseIncomingDate (   $a_value,
bool  $a_add_time = false 
)
static

Try to parse incoming value to date object.

Parameters
string | ilDateTime$a_value
int$a_add_time
Returns
ilDateTime|ilDate

Definition at line 701 of file class.ilCalendarUtil.php.

Referenced by ilDateTimeInputGUI\checkInput(), ilDateDurationInputGUI\checkInput(), ilAdvancedMDFieldDefinitionDate\getLuceneSearchString(), ilAdvancedMDFieldDefinitionDateTime\getLuceneSearchString(), ilSessionStatisticsGUI\importDate(), ilADTDateSearchBridgeSingle\importFromPost(), ilADTDateTimeSearchBridgeSingle\importFromPost(), ilADTDateSearchBridgeRange\importFromPost(), ilADTDateTimeSearchBridgeRange\importFromPost(), ilDateTimeInputGUI\setValueByArray(), ilDateDurationInputGUI\setValueByArray(), ilCourseContentGUI\updateManagedTimings(), and ilCourseContentGUI\updatePersonalTimings().

701  : ?ilDateTime
702  {
703  // already datetime object?
704  if ($a_value instanceof ilDateTime) {
705  return $a_value;
706  } elseif (trim($a_value)) {
707  // try user-specific format
708  $parsed = self::parseDateString($a_value, $a_add_time);
709  if (is_object($parsed["date"])) {
710  return $parsed["date"];
711  } else {
712  // try generic format
713  $parsed = self::parseDateString($a_value, $a_add_time, true);
714  if (is_object($parsed["date"])) {
715  return $parsed["date"];
716  }
717  }
718  }
719  return null;
720  }
+ Here is the caller graph for this function:

Field Documentation

◆ $default_calendar

array ilCalendarUtil::$default_calendar = array()
staticprivate

Definition at line 26 of file class.ilCalendarUtil.php.

◆ $init_datetimepicker

bool ilCalendarUtil::$init_datetimepicker = false
staticprotected

Definition at line 28 of file class.ilCalendarUtil.php.

◆ $init_done

string ilCalendarUtil::$init_done
static

Definition at line 27 of file class.ilCalendarUtil.php.

◆ $today

ilDateTime ilCalendarUtil::$today = null
staticprivate

Definition at line 25 of file class.ilCalendarUtil.php.


The documentation for this class was generated from the following file: