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