1<?php
2
3namespace Sabre\VObject\Component;
4
5use Sabre\VObject;
6
7/**
8 * The VAvailability component
9 *
10 * This component adds functionality to a component, specific for VAVAILABILITY
11 * components.
12 *
13 * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
14 * @author Ivan Enderlin
15 * @license http://sabre.io/license/ Modified BSD License
16 */
17class VAvailability extends VObject\Component {
18
19    /**
20     * A simple list of validation rules.
21     *
22     * This is simply a list of properties, and how many times they either
23     * must or must not appear.
24     *
25     * Possible values per property:
26     *   * 0 - Must not appear.
27     *   * 1 - Must appear exactly once.
28     *   * + - Must appear at least once.
29     *   * * - Can appear any number of times.
30     *   * ? - May appear, but not more than once.
31     *
32     * @var array
33     */
34    function getValidationRules() {
35
36        return array(
37            'UID' => 1,
38            'DTSTAMP' => 1,
39
40            'BUSYTYPE' => '?',
41            'CLASS' => '?',
42            'CREATED' => '?',
43            'DESCRIPTION' => '?',
44            'DTSTART' => '?',
45            'LAST-MODIFIED' => '?',
46            'ORGANIZER' => '?',
47            'PRIORITY' => '?',
48            'SEQUENCE' => '?',
49            'SUMMARY' => '?',
50            'URL' => '?',
51            'DTEND' => '?',
52            'DURATION' => '?',
53
54            'CATEGORIES' => '*',
55            'COMMENT' => '*',
56            'CONTACT' => '*',
57        );
58
59    }
60
61    /**
62     * Validates the node for correctness.
63     *
64     * The following options are supported:
65     *   Node::REPAIR - May attempt to automatically repair the problem.
66     *   Node::PROFILE_CARDDAV - Validate the vCard for CardDAV purposes.
67     *   Node::PROFILE_CALDAV - Validate the iCalendar for CalDAV purposes.
68     *
69     * This method returns an array with detected problems.
70     * Every element has the following properties:
71     *
72     *  * level - problem level.
73     *  * message - A human-readable string describing the issue.
74     *  * node - A reference to the problematic node.
75     *
76     * The level means:
77     *   1 - The issue was repaired (only happens if REPAIR was turned on).
78     *   2 - A warning.
79     *   3 - An error.
80     *
81     * @param int $options
82     * @return array
83     */
84    function validate($options = 0) {
85
86        $result = parent::validate($options);
87
88        if (isset($this->DTEND) && isset($this->DURATION)) {
89            $result[] = array(
90                'level' => 3,
91                'message' => 'DTEND and DURATION cannot both be present',
92                'node' => $this
93            );
94        }
95
96        return $result;
97
98    }
99}
100