19 declare(strict_types=1);
42 protected const string RULE =
'rule';
43 protected const string END =
'end';
47 protected const string DAILY =
'daily';
48 protected const string WEEKLY =
'weekly';
56 protected const string MONTH =
'month';
57 protected const string WEEK =
'week';
58 protected const string DAY =
'day';
64 protected const string COUNT =
'count';
87 $clone->unlimited_recurrences = !$without;
94 $clone->daily = !$without;
100 $clone = clone $this;
101 $clone->weekly = !$without;
107 $clone = clone $this;
108 $clone->monthly = !$without;
114 $clone = clone $this;
115 $clone->yearly = !$without;
146 return $this->ui_factory->input()->field()->group([
154 $groups[self::NO_RECURRENCE] = $this->ui_factory->input()->field()->group(
156 $this->
lng->txt(
'cal_no_recurrence')
173 $value = match ($this->recurrence->getFrequenceType()) {
178 default => self::NO_RECURRENCE
180 return $this->ui_factory->input()->field()->switchableGroup(
182 $this->
lng->txt(
'cal_recurrences')
188 return $this->ui_factory->input()->field()->group(
193 $this->
lng->txt(
'cal_daily')
199 return $this->ui_factory->input()->field()->group(
201 self::INTERVAL => $this->
getIntervalInput($this->
lng->txt(
'cal_recurrence_week_interval')),
205 $this->
lng->txt(
'cal_weekly')
211 return $this->ui_factory->input()->field()->group(
213 self::INTERVAL => $this->
getIntervalInput($this->
lng->txt(
'cal_recurrence_month_interval')),
218 $this->
lng->txt(
'cal_monthly_by_day')
224 return $this->ui_factory->input()->field()->group(
226 self::INTERVAL => $this->
getIntervalInput($this->
lng->txt(
'cal_recurrence_month_interval')),
230 $this->
lng->txt(
'cal_monthly_by_date')
236 return $this->ui_factory->input()->field()->group(
238 self::INTERVAL => $this->
getIntervalInput($this->
lng->txt(
'cal_recurrence_year_interval')),
244 $this->
lng->txt(
'cal_yearly_by_day')
250 return $this->ui_factory->input()->field()->group(
252 self::INTERVAL => $this->
getIntervalInput($this->
lng->txt(
'cal_recurrence_year_interval')),
257 $this->
lng->txt(
'cal_yearly_by_date')
265 if ($this->unlimited_recurrences) {
266 $groups[self::NO_UNTIL] = $this->ui_factory->input()->field()->group(
268 $this->
lng->txt(
'cal_no_ending')
272 $count_value = $this->recurrence->getFrequenceUntilCount();
273 if ($count_value < 1 || $count_value > 100) {
276 $count = $this->ui_factory->input()->field()->numeric($this->
lng->txt(
'cal_recurrence_count'))
279 ->withAdditionalTransformation(
281 $this->
refinery->int()->isGreaterThanOrEqual(1),
282 $this->
refinery->int()->isLessThanOrEqual(100),
285 $groups[self::UNTIL_COUNT] = $this->ui_factory->input()->field()->group(
286 [self::COUNT => $count],
287 $this->
lng->txt(
'cal_recurrence_until_count')
290 $end_date = $this->ui_factory->input()->field()->dateTime(
291 $this->
lng->txt(
'cal_recurrence_end_date'),
292 $this->
lng->txt(
'cal_recurrence_end_date_info')
293 )->withTimezone(
'UTC')
295 ->withRequired(
true);
296 if ($this->recurrence->getFrequenceUntilDate()) {
297 $end_date = $end_date->withValue(
298 new DateTimeImmutable(
'@' . $this->recurrence->getFrequenceUntilDate()->getUnixTime())
301 $groups[self::UNTIL_END_DATE] = $this->ui_factory->input()->field()->group(
302 [self::END_DATE => $end_date],
303 $this->
lng->txt(
'cal_recurrence_until_end_date')
306 $value = self::NO_UNTIL;
307 if ($this->recurrence->getFrequenceUntilDate()) {
308 $value = self::UNTIL_END_DATE;
310 if ($this->recurrence->getFrequenceUntilCount()) {
311 $value = self::UNTIL_COUNT;
313 return $this->ui_factory->input()->field()->switchableGroup(
315 $this->
lng->txt(
'cal_recurrence_until')
321 return $this->ui_factory->input()->field()->numeric($label)
322 ->
withValue($this->recurrence->getInterval())
324 ->withAdditionalTransformation(
325 $this->
refinery->int()->isGreaterThanOrEqual(1)
332 0 => Weekday::SUNDAY->value,
333 1 => Weekday::MONDAY->value,
334 2 => Weekday::TUESDAY->value,
335 3 => Weekday::WEDNESDAY->value,
336 4 => Weekday::THURSDAY->value,
337 5 => Weekday::FRIDAY->value,
339 7 => Weekday::SUNDAY->value
342 for ($i = $this->user_settings->getWeekStart(); $i < 7 + $this->user_settings->getWeekStart(); $i++) {
347 foreach ($this->recurrence->getBYDAYList() as $byday) {
349 $v = substr($byday, -2);
350 if (in_array($v, $days)) {
355 return $this->ui_factory->input()->field()->multiSelect(
356 $this->
lng->txt(
'cal_day_s'),
358 )->
withValue($values)->withRequired(
true);
364 Ordinal::FIRST->value => $this->
lng->txt(
'cal_first'),
365 Ordinal::SECOND->value => $this->
lng->txt(
'cal_second'),
366 Ordinal::THIRD->value => $this->
lng->txt(
'cal_third'),
367 Ordinal::FOURTH->value => $this->
lng->txt(
'cal_fourth'),
368 Ordinal::FIFTH->value => $this->
lng->txt(
'cal_fifth'),
373 $value = substr($this->recurrence->getBYDAYList()[0] ??
'', 0, -2);
375 $value = Ordinal::FIRST->value;
378 return $this->ui_factory->input()->field()->select(
379 $this->
lng->txt(
'week'),
381 )->
withValue($value)->withRequired(
true);
386 $value = (
int) $this->recurrence->getBYMONTHDAY();
387 if ($value < 1 || $value > 31) {
390 return $this->ui_factory->input()->field()->numeric($this->
lng->txt(
'cal_day_of_month'))
393 ->withAdditionalTransformation(
395 $this->
refinery->int()->isGreaterThanOrEqual(1),
396 $this->
refinery->int()->isLessThanOrEqual(31),
404 1 => Month::JANUARY->value,
405 2 => Month::FEBRUARY->value,
406 3 => Month::MARCH->value,
407 4 => Month::APRIL->value,
408 5 => Month::MAY->value,
409 6 => Month::JUNE->value,
410 7 => Month::JULY->value,
411 8 => Month::AUGUST->value,
412 9 => Month::SEPTEMBER->value,
413 10 => Month::OCTOBER->value,
414 11 => Month::NOVEMBER->value,
418 foreach ($months as $month => $key) {
422 $value = $this->recurrence->getBYMONTH();
423 if (!in_array($value, $options)) {
424 $value = Month::JANUARY->value;
426 return $this->ui_factory->input()->field()->select(
427 $this->
lng->txt(
'month'),
429 )->
withValue($value)->withRequired(
true);
434 $recurrence = clone $this->recurrence;
441 return $this->
refinery->custom()->transformation(
function ($values) use (
449 $recurrence->reset();
451 $rule_data = $values[self::RULE];
452 switch ($rule_data[0]) {
455 $recurrence->setInterval((
int) $rule_data[1][self::INTERVAL]);
460 $recurrence->setInterval((
int) $rule_data[1][self::INTERVAL]);
461 if (is_array($rule_data[1][self::DAY]) && $rule_data[1][self::DAY] !== []) {
462 $recurrence->setBYDAY(implode(
',', $rule_data[1][self::DAY]));
466 case self::MONTHLY_BY_DAY:
468 $recurrence->setInterval((
int) $rule_data[1][self::INTERVAL]);
469 if (is_array($rule_data[1][self::DAY]) && $rule_data[1][self::DAY] !== []) {
470 $index = $rule_data[1][self::WEEK];
471 $recurrence->setBYDAY($index . implode(
',' . $index, $rule_data[1][self::DAY]));
475 case self::MONTHLY_BY_DATE:
477 $recurrence->setInterval((
int) $rule_data[1][self::INTERVAL]);
478 $recurrence->setBYMONTHDAY((
string) $rule_data[1][self::DAY_OF_MONTH]);
481 case self::YEARLY_BY_DAY:
483 $recurrence->setInterval((
int) $rule_data[1][self::INTERVAL]);
484 $recurrence->setBYMONTH((
string) $rule_data[1][self::MONTH]);
485 if (is_array($rule_data[1][self::DAY]) && $rule_data[1][self::DAY] !== []) {
486 $index = $rule_data[1][self::WEEK];
487 $recurrence->setBYDAY($index . implode(
',' . $index, $rule_data[1][self::DAY]));
491 case self::YEARLY_BY_DATE:
493 $recurrence->setInterval((
int) $rule_data[1][self::INTERVAL]);
494 $recurrence->setBYMONTH((
string) $rule_data[1][self::MONTH]);
495 $recurrence->setBYMONTHDAY((
string) $rule_data[1][self::DAY_OF_MONTH]);
499 case self::NO_RECURRENCE:
503 $end_data = $rule_data[1][self::END];
504 if ($end_data[0] === self::UNTIL_COUNT) {
505 $recurrence->setFrequenceUntilCount($end_data[1][self::COUNT]);
507 if ($end_data[0] === self::UNTIL_END_DATE) {
508 $recurrence->setFrequenceUntilDate(
new ilDate(
509 $end_data[1][self::END_DATE]->getTimestamp(),
static _numericMonthToString(int $a_month, bool $a_long=true, ?ilLanguage $lng=null)
numeric month to string
static _numericDayToString(int $a_day, bool $a_long=true, ?ilLanguage $lng=null)
Ordinal
Technically these also include the sign...
const string FREQ_MONTHLY