xref: /plugin/davcal/vendor/sabre/vobject/lib/Component/VAvailability.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 VAvailability component
9*a1a3b679SAndreas Boehler *
10*a1a3b679SAndreas Boehler * This component adds functionality to a component, specific for VAVAILABILITY
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 VAvailability 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            'DTSTAMP' => 1,
39*a1a3b679SAndreas Boehler
40*a1a3b679SAndreas Boehler            'BUSYTYPE' => '?',
41*a1a3b679SAndreas Boehler            'CLASS' => '?',
42*a1a3b679SAndreas Boehler            'CREATED' => '?',
43*a1a3b679SAndreas Boehler            'DESCRIPTION' => '?',
44*a1a3b679SAndreas Boehler            'DTSTART' => '?',
45*a1a3b679SAndreas Boehler            'LAST-MODIFIED' => '?',
46*a1a3b679SAndreas Boehler            'ORGANIZER' => '?',
47*a1a3b679SAndreas Boehler            'PRIORITY' => '?',
48*a1a3b679SAndreas Boehler            'SEQUENCE' => '?',
49*a1a3b679SAndreas Boehler            'SUMMARY' => '?',
50*a1a3b679SAndreas Boehler            'URL' => '?',
51*a1a3b679SAndreas Boehler            'DTEND' => '?',
52*a1a3b679SAndreas Boehler            'DURATION' => '?',
53*a1a3b679SAndreas Boehler
54*a1a3b679SAndreas Boehler            'CATEGORIES' => '*',
55*a1a3b679SAndreas Boehler            'COMMENT' => '*',
56*a1a3b679SAndreas Boehler            'CONTACT' => '*',
57*a1a3b679SAndreas Boehler        );
58*a1a3b679SAndreas Boehler
59*a1a3b679SAndreas Boehler    }
60*a1a3b679SAndreas Boehler
61*a1a3b679SAndreas Boehler    /**
62*a1a3b679SAndreas Boehler     * Validates the node for correctness.
63*a1a3b679SAndreas Boehler     *
64*a1a3b679SAndreas Boehler     * The following options are supported:
65*a1a3b679SAndreas Boehler     *   Node::REPAIR - May attempt to automatically repair the problem.
66*a1a3b679SAndreas Boehler     *   Node::PROFILE_CARDDAV - Validate the vCard for CardDAV purposes.
67*a1a3b679SAndreas Boehler     *   Node::PROFILE_CALDAV - Validate the iCalendar for CalDAV purposes.
68*a1a3b679SAndreas Boehler     *
69*a1a3b679SAndreas Boehler     * This method returns an array with detected problems.
70*a1a3b679SAndreas Boehler     * Every element has the following properties:
71*a1a3b679SAndreas Boehler     *
72*a1a3b679SAndreas Boehler     *  * level - problem level.
73*a1a3b679SAndreas Boehler     *  * message - A human-readable string describing the issue.
74*a1a3b679SAndreas Boehler     *  * node - A reference to the problematic node.
75*a1a3b679SAndreas Boehler     *
76*a1a3b679SAndreas Boehler     * The level means:
77*a1a3b679SAndreas Boehler     *   1 - The issue was repaired (only happens if REPAIR was turned on).
78*a1a3b679SAndreas Boehler     *   2 - A warning.
79*a1a3b679SAndreas Boehler     *   3 - An error.
80*a1a3b679SAndreas Boehler     *
81*a1a3b679SAndreas Boehler     * @param int $options
82*a1a3b679SAndreas Boehler     * @return array
83*a1a3b679SAndreas Boehler     */
84*a1a3b679SAndreas Boehler    function validate($options = 0) {
85*a1a3b679SAndreas Boehler
86*a1a3b679SAndreas Boehler        $result = parent::validate($options);
87*a1a3b679SAndreas Boehler
88*a1a3b679SAndreas Boehler        if (isset($this->DTEND) && isset($this->DURATION)) {
89*a1a3b679SAndreas Boehler            $result[] = array(
90*a1a3b679SAndreas Boehler                'level' => 3,
91*a1a3b679SAndreas Boehler                'message' => 'DTEND and DURATION cannot both be present',
92*a1a3b679SAndreas Boehler                'node' => $this
93*a1a3b679SAndreas Boehler            );
94*a1a3b679SAndreas Boehler        }
95*a1a3b679SAndreas Boehler
96*a1a3b679SAndreas Boehler        return $result;
97*a1a3b679SAndreas Boehler
98*a1a3b679SAndreas Boehler    }
99*a1a3b679SAndreas Boehler}
100