| 1: | <?php |
| 2: | declare(strict_types=1); |
| 3: | |
| 4: | namespace om\ICal; |
| 5: | |
| 6: | use DateInterval; |
| 7: | use DateTimeInterface; |
| 8: | use InvalidArgumentException; |
| 9: | use om\ICal\Value\CalAddress; |
| 10: | use om\ICal\Value\Classification; |
| 11: | use om\ICal\Value\Conference; |
| 12: | use om\ICal\Value\DateTimeValue; |
| 13: | use om\ICal\Value\Image; |
| 14: | use om\ICal\Value\Link; |
| 15: | use om\ICal\Value\Period; |
| 16: | use om\ICal\Value\PropertyFactory; |
| 17: | use om\ICal\Value\Relation; |
| 18: | use om\ICal\Value\Status; |
| 19: | use om\RRule\Rule; |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | final class Todo extends Item { |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | public static function new( |
| 57: | ?string $uid = null, |
| 58: | DateTimeInterface|DateTimeValue|string|null $stamp = null, |
| 59: | DateTimeInterface|DateTimeValue|string|null $start = null, |
| 60: | DateTimeInterface|DateTimeValue|string|null $due = null, |
| 61: | DateInterval|string|null $duration = null, |
| 62: | DateTimeInterface|DateTimeValue|string|null $completed = null, |
| 63: | ?int $percentComplete = null, |
| 64: | ?string $summary = null, |
| 65: | ?string $description = null, |
| 66: | ?string $location = null, |
| 67: | ?string $url = null, |
| 68: | Status|string|null $status = null, |
| 69: | Classification|string|null $classification = null, |
| 70: | ?int $priority = null, |
| 71: | ?int $sequence = null, |
| 72: | iterable $categories = [], |
| 73: | CalAddress|string|null $organizer = null, |
| 74: | iterable $attendees = [], |
| 75: | Rule|string|null $rrule = null, |
| 76: | iterable $rdates = [], |
| 77: | iterable $exdates = [], |
| 78: | DateTimeInterface|DateTimeValue|string|null $recurrenceId = null, |
| 79: | ?array $geo = null, |
| 80: | ?string $color = null, |
| 81: | iterable $images = [], |
| 82: | iterable $conferences = [], |
| 83: | iterable $links = [], |
| 84: | iterable $relatedTo = [], |
| 85: | iterable $alarms = [], |
| 86: | iterable $locations = [], |
| 87: | array $properties = [], |
| 88: | ): self { |
| 89: | $builder = ComponentBuilder::item('VTODO', $uid, $stamp); |
| 90: | $startValue = $builder->start($start); |
| 91: | $dueValue = $builder->end('DUE', $due, $duration, $startValue); |
| 92: | $builder->recurrence($startValue, $rrule, $rdates, $exdates, $recurrenceId) |
| 93: | ->add($completed === null ? null : PropertyFactory::dateTime('COMPLETED', $completed)) |
| 94: | ->integer('PERCENT-COMPLETE', $percentComplete, 0, 100) |
| 95: | ->descriptive($summary, $description, $location, $url, $classification, $priority, $sequence, $categories, $organizer, $attendees, $geo, $color, $images, $conferences, $links, $relatedTo) |
| 96: | ->status($status) |
| 97: | ->alarms($alarms, $startValue !== null, $dueValue !== null, 'DUE') |
| 98: | ->locations($locations); |
| 99: | return new self($builder->build($properties), new Calendar()); |
| 100: | } |
| 101: | |
| 102: | |
| 103: | |
| 104: | |
| 105: | public function due(): ?DateTimeValue { |
| 106: | return $this->date('DUE') ?? ($this->has('DURATION') ? parent::end() : null); |
| 107: | } |
| 108: | |
| 109: | public function end(): ?DateTimeValue { |
| 110: | return $this->due() ?? $this->start(); |
| 111: | } |
| 112: | |
| 113: | public function duration(): DateInterval { |
| 114: | $start = $this->start(); |
| 115: | $due = $this->date('DUE'); |
| 116: | if ($start !== null && $due !== null) { |
| 117: | return self::between($start, $due); |
| 118: | } |
| 119: | $duration = $this->property('DURATION'); |
| 120: | return ($duration === null ? null : $this->calendar->values()->duration($duration)) ?? new DateInterval('PT0S'); |
| 121: | } |
| 122: | |
| 123: | public function completed(): ?DateTimeValue { |
| 124: | return $this->date('COMPLETED'); |
| 125: | } |
| 126: | |
| 127: | public function percentComplete(): ?int { |
| 128: | return $this->integer('PERCENT-COMPLETE'); |
| 129: | } |
| 130: | |
| 131: | public function isCompleted(): bool { |
| 132: | return $this->status() === 'COMPLETED' || $this->has('COMPLETED'); |
| 133: | } |
| 134: | } |
| 135: | |