1<?php
2
3namespace Sabre\VObject\Component;
4
5use DateTimeInterface;
6use Sabre\VObject;
7
8/**
9 * VJournal component.
10 *
11 * This component contains some additional functionality specific for VJOURNALs.
12 *
13 * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
14 * @author Evert Pot (http://evertpot.com/)
15 * @license http://sabre.io/license/ Modified BSD License
16 */
17class VJournal extends VObject\Component
18{
19    /**
20     * Returns true or false depending on if the event falls in the specified
21     * time-range. This is used for filtering purposes.
22     *
23     * The rules used to determine if an event falls within the specified
24     * time-range is based on the CalDAV specification.
25     *
26     * @param DateTimeInterface $start
27     * @param DateTimeInterface $end
28     *
29     * @return bool
30     */
31    public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end)
32    {
33        $dtstart = isset($this->DTSTART) ? $this->DTSTART->getDateTime() : null;
34        if ($dtstart) {
35            $effectiveEnd = $dtstart;
36            if (!$this->DTSTART->hasTime()) {
37                $effectiveEnd = $effectiveEnd->modify('+1 day');
38            }
39
40            return $start <= $effectiveEnd && $end > $dtstart;
41        }
42
43        return false;
44    }
45
46    /**
47     * A simple list of validation rules.
48     *
49     * This is simply a list of properties, and how many times they either
50     * must or must not appear.
51     *
52     * Possible values per property:
53     *   * 0 - Must not appear.
54     *   * 1 - Must appear exactly once.
55     *   * + - Must appear at least once.
56     *   * * - Can appear any number of times.
57     *   * ? - May appear, but not more than once.
58     *
59     * @var array
60     */
61    public function getValidationRules()
62    {
63        return [
64            'UID' => 1,
65            'DTSTAMP' => 1,
66
67            'CLASS' => '?',
68            'CREATED' => '?',
69            'DTSTART' => '?',
70            'LAST-MODIFIED' => '?',
71            'ORGANIZER' => '?',
72            'RECURRENCE-ID' => '?',
73            'SEQUENCE' => '?',
74            'STATUS' => '?',
75            'SUMMARY' => '?',
76            'URL' => '?',
77
78            'RRULE' => '?',
79
80            'ATTACH' => '*',
81            'ATTENDEE' => '*',
82            'CATEGORIES' => '*',
83            'COMMENT' => '*',
84            'CONTACT' => '*',
85            'DESCRIPTION' => '*',
86            'EXDATE' => '*',
87            'RELATED-TO' => '*',
88            'RDATE' => '*',
89        ];
90    }
91
92    /**
93     * This method should return a list of default property values.
94     *
95     * @return array
96     */
97    protected function getDefaults()
98    {
99        return [
100            'UID' => 'sabre-vobject-'.VObject\UUIDUtil::getUUID(),
101            'DTSTAMP' => gmdate('Ymd\\THis\\Z'),
102        ];
103    }
104}
105