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    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    /**
48     * A simple list of validation rules.
49     *
50     * This is simply a list of properties, and how many times they either
51     * must or must not appear.
52     *
53     * Possible values per property:
54     *   * 0 - Must not appear.
55     *   * 1 - Must appear exactly once.
56     *   * + - Must appear at least once.
57     *   * * - Can appear any number of times.
58     *   * ? - May appear, but not more than once.
59     *
60     * @var array
61     */
62    function getValidationRules() {
63
64        return [
65            'UID'     => 1,
66            'DTSTAMP' => 1,
67
68            'CLASS'         => '?',
69            'CREATED'       => '?',
70            'DTSTART'       => '?',
71            'LAST-MODIFIED' => '?',
72            'ORGANIZER'     => '?',
73            'RECURRENCE-ID' => '?',
74            'SEQUENCE'      => '?',
75            'STATUS'        => '?',
76            'SUMMARY'       => '?',
77            'URL'           => '?',
78
79            'RRULE' => '?',
80
81            'ATTACH'      => '*',
82            'ATTENDEE'    => '*',
83            'CATEGORIES'  => '*',
84            'COMMENT'     => '*',
85            'CONTACT'     => '*',
86            'DESCRIPTION' => '*',
87            'EXDATE'      => '*',
88            'RELATED-TO'  => '*',
89            'RDATE'       => '*',
90        ];
91
92    }
93
94    /**
95     * This method should return a list of default property values.
96     *
97     * @return array
98     */
99    protected function getDefaults() {
100
101        return [
102            'UID'     => 'sabre-vobject-' . VObject\UUIDUtil::getUUID(),
103            'DTSTAMP' => date('Ymd\\THis\\Z'),
104        ];
105
106    }
107}
108