19declare(strict_types=1);
60 public function __construct(
ilDate $seed,
int $a_type, ?
int $a_user_id =
null,
bool $a_strict_period =
false)
64 $this->
logger = $DIC->logger()->cal();
65 $this->db =
$DIC->database();
66 $this->type = $a_type;
71 $this->strict_period = $a_strict_period;
73 $this->
user = $DIC->user();
74 if ($a_user_id !==
null && $a_user_id !==
$DIC->user()->getId()) {
78 $this->weekstart = $this->user_settings->getWeekStart();
79 if ($this->
user->getTimeZone()) {
80 $this->timezone = $this->
user->getTimeZone();
115 return $this->limit_events != -1;
125 $this->limit_events = $a_limit;
130 $this->subitems_enabled = $a_status;
140 $this->filters[] = $a_filter;
147 $fend = clone $fstart;
160 $tmp_schedule = array();
161 $tmp_schedule_fullday = array();
164 if (($f_unix_start ==
$schedule[
'dstart']) or
169 } elseif ((
$schedule[
'dstart'] == $unix_start) or
177 usort($tmp_schedule,
function (
$a,
$b) {
178 return $a[
'dstart'] <=>
$b[
'dstart'];
182 return array_merge($tmp_schedule_fullday, $tmp_schedule);
191 foreach ($events as $event) {
192 $ids[] = $event->getEntryId();
196 $cat_types = array();
197 foreach (array_unique($cat_map) as $cat_id) {
199 $cat_types[$cat_id] = $cat->getType();
203 foreach ($events as $event) {
207 foreach ($recs as $rec) {
209 foreach ($calc->calculateDateList($this->start, $this->end)->get() as $rec_date) {
210 if ($this->type == self::TYPE_PD_UPCOMING &&
215 $this->schedule[
$counter][
'event'] = $event;
218 $this->schedule[
$counter][
'fullday'] = $event->isFullday();
219 $this->schedule[
$counter][
'category_id'] = $cat_map[$event->getEntryId()];
220 $this->schedule[
$counter][
'category_type'] = $cat_types[$cat_map[$event->getEntryId()]];
222 switch ($this->type) {
227 $this->schedule[
$counter][
'dstart'],
231 $this->schedule[
$counter][
'start_info'] = $tmp_date->get(
242 $this->schedule[
$counter][
'end_info'] = $tmp_date->get(
253 if ($this->type != self::TYPE_PD_UPCOMING &&
260 $this->schedule[
$counter][
'event'] = $event;
263 $this->schedule[
$counter][
'fullday'] = $event->isFullday();
264 $this->schedule[
$counter][
'category_id'] = $cat_map[$event->getEntryId()];
265 $this->schedule[
$counter][
'category_type'] = $cat_types[$cat_map[$event->getEntryId()]];
267 if (!$event->isFullday()) {
268 switch ($this->type) {
273 $this->schedule[
$counter][
'dstart'],
277 $this->schedule[
$counter][
'start_info'] = $tmp_date->get(
284 $this->schedule[
$counter][
'end_info'] = $tmp_date->get(
296 if ($this->type != self::TYPE_PD_UPCOMING &&
303 if ($this->type == self::TYPE_PD_UPCOMING) {
306 $this->schedule = array_slice($this->schedule, 0, $this->
getEventsLimit());
318 if (!count($a_cats)) {
321 foreach ($this->filters as $filter) {
322 $a_cats = $filter->filterCategories($a_cats);
329 foreach ($this->filters as $filter) {
330 $res = $filter->modifyEvent($event);
331 if (
$res ===
false) {
332 $this->
logger->notice(
'filtering failed for ' . get_class($filter));
345 $new_events = array();
346 foreach ($this->filters as $filter) {
347 $events_by_filter = $filter->addCustomEvents(
$start,
$end, $categories);
348 if ($events_by_filter) {
349 $new_events = array_merge($new_events, $events_by_filter);
374 $query =
"SELECT ce.cal_id cal_id FROM cal_entries ce " .
375 "JOIN cal_cat_assignments ca ON ca.cal_id = ce.cal_id " .
377 "AND " . $this->db->in(
'ca.cat_id', $cats,
false,
'integer') .
' ' .
378 "ORDER BY last_update";
379 $res = $this->db->query($query);
386 $events[] = $valid_event;
390 foreach ($this->
addCustomEvents($this->start, $this->end, $cats) as $event) {
410 $query =
"SELECT ce.cal_id cal_id" .
411 " FROM cal_entries ce" .
412 " LEFT JOIN cal_recurrence_rules crr ON (ce.cal_id = crr.cal_id)" .
413 " JOIN cal_cat_assignments ca ON (ca.cal_id = ce.cal_id)";
415 if ($this->type != self::TYPE_INBOX) {
416 $query .=
" WHERE ((starta <= " . $this->db->quote(
420 " AND enda >= " . $this->db->quote($this->start->get(
IL_CAL_DATETIME,
'',
'UTC'),
'timestamp') .
")" .
421 " OR (starta <= " . $this->db->quote($this->end->get(
IL_CAL_DATETIME,
'',
'UTC'),
'timestamp') .
422 " AND NOT rule_id IS NULL))";
425 $query .=
" WHERE starta >= " . $this->db->quote($date->get(
IL_CAL_DATETIME,
'',
'UTC'),
'timestamp');
428 $query .=
" AND " . $this->db->in(
'ca.cat_id', $cats,
false,
'integer') .
431 $res = $this->db->query($query);
438 $events[] = $valid_event;
441 foreach ($this->
addCustomEvents($this->start, $this->end, $cats) as $event) {
449 switch ($this->type) {
451 $this->start = clone $seed;
452 $this->end = clone $seed;
454 if (!$this->strict_period) {
464 $this->start = clone $seed;
466 $day_diff = $this->weekstart - $start_info[
'isoday'];
468 if (abs($day_diff) === 7) {
473 if ($this->strict_period) {
474 $this->start->increment(
IL_CAL_DAY, $day_diff);
478 $this->start->increment(
IL_CAL_DAY, $day_diff);
486 if ($this->strict_period) {
487 $this->start = clone $seed;
488 $this->end = clone $seed;
492 list($year, $month) = explode(
'-', $year_month);
494 $month = (
int) $month;
499 $start_unix_time = $this->start->getUnixTime();
501 $start_day_of_week = (
int) date(
'w', $start_unix_time);
503 $number_days_previous_month = 0;
506 $number_days_previous_month = 6;
507 } elseif ($start_day_of_week > 0) {
508 $number_days_previous_month = $start_day_of_week;
511 $number_days_previous_month = $start_day_of_week - 1;
515 $this->start->increment(
IL_CAL_DAY, -$number_days_previous_month);
523 $end_unix_time = $this->end->getUnixTime();
525 $end_day_of_week = (
int) date(
'w', $end_unix_time);
527 if ($end_day_of_week > 0) {
528 $number_days_next_month = 7 - $end_day_of_week;
531 $number_days_next_month = $number_days_next_month - 1;
534 $this->end->increment(
IL_CAL_DAY, $number_days_next_month);
541 $this->start = clone $seed;
548 $this->start = $seed;
557 $this->start = $a_start;
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
const MODE_PERSONAL_DESKTOP_MEMBERSHIP
const MODE_PORTFOLIO_CONSULTATION
static _getInstance($a_usr_id=0)
get singleton instance
static _getAppointmentCalendars(array $a_cal_ids)
Stores calendar categories.
Model for a calendar entry.
Calculates an ilDateList for a given calendar entry and recurrence rule.
static _getRecurrences(int $a_cal_id)
get all recurrences of an appointment
Calendar schedule filter for booking pool reservations.
Calendar schedule filter for consultation hour bookings.
Calendar schedule filter for exercises.
Calendar schedule filter for hidden categories.
Calendar schedule filter for individual timings.
Represents a list of calendar appointments (including recurring events) for a specific user in a give...
enabledSubitemCalendars()
areEventsLimited()
Check if events are limited.
getByDay(ilDate $a_start, string $a_timezone)
modifyEventByFilters(ilCalendarEntry $event)
ilCalendarUserSettings $user_settings
getEvents()
Read events (will be moved to another class, since only active and/or visible calendars are shown)
addCustomEvents(ilDate $start, ilDate $end, array $categories)
addFilter(ilCalendarScheduleFilter $a_filter)
setPeriod(ilDate $a_start, ilDate $a_end)
__construct(ilDate $seed, int $a_type, ?int $a_user_id=null, bool $a_strict_period=false)
filterCategories(array $a_cats)
getChangedEvents(bool $a_include_subitem_calendars=false)
get new/changed events
setEventsLimit(int $a_limit)
addSubitemCalendars(bool $a_status)
static _getInstanceByUserId(int $a_user_id)
static _getMaxDayOfMonth(int $a_year, int $a_month)
get max day of month 2008,2 => 29
@classDescription Date and time handling
increment(string $a_type, int $a_count=1)
get(int $a_format, string $a_format_str='', string $a_tz='')
get formatted date
Component logger with individual log levels by component id.
Calendar schedule filter interface.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples