xref: /plugin/davcal/vendor/sabre/dav/lib/CalDAV/Xml/Property/ScheduleCalendarTransp.php (revision a1a3b6794e0e143a4a8b51d3185ce2d339be61ab)
1*a1a3b679SAndreas Boehler<?php
2*a1a3b679SAndreas Boehler
3*a1a3b679SAndreas Boehlernamespace Sabre\CalDAV\Xml\Property;
4*a1a3b679SAndreas Boehler
5*a1a3b679SAndreas Boehleruse Sabre\Xml\Element;
6*a1a3b679SAndreas Boehleruse Sabre\Xml\Reader;
7*a1a3b679SAndreas Boehleruse Sabre\Xml\Writer;
8*a1a3b679SAndreas Boehleruse Sabre\Xml\Element\Elements;
9*a1a3b679SAndreas Boehleruse Sabre\CalDAV\Plugin;
10*a1a3b679SAndreas Boehler
11*a1a3b679SAndreas Boehler/**
12*a1a3b679SAndreas Boehler * schedule-calendar-transp property.
13*a1a3b679SAndreas Boehler *
14*a1a3b679SAndreas Boehler * This property is a representation of the schedule-calendar-transp property.
15*a1a3b679SAndreas Boehler * This property is defined in:
16*a1a3b679SAndreas Boehler *
17*a1a3b679SAndreas Boehler * http://tools.ietf.org/html/rfc6638#section-9.1
18*a1a3b679SAndreas Boehler *
19*a1a3b679SAndreas Boehler * Its values are either 'transparent' or 'opaque'. If it's transparent, it
20*a1a3b679SAndreas Boehler * means that this calendar will not be taken into consideration when a
21*a1a3b679SAndreas Boehler * different user queries for free-busy information. If it's 'opaque', it will.
22*a1a3b679SAndreas Boehler *
23*a1a3b679SAndreas Boehler * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
24*a1a3b679SAndreas Boehler * @author Evert Pot (http://www.rooftopsolutions.nl/)
25*a1a3b679SAndreas Boehler * @license http://sabre.io/license/ Modified BSD License
26*a1a3b679SAndreas Boehler */
27*a1a3b679SAndreas Boehlerclass ScheduleCalendarTransp implements Element {
28*a1a3b679SAndreas Boehler
29*a1a3b679SAndreas Boehler    const TRANSPARENT = 'transparent';
30*a1a3b679SAndreas Boehler    const OPAQUE = 'opaque';
31*a1a3b679SAndreas Boehler
32*a1a3b679SAndreas Boehler    /**
33*a1a3b679SAndreas Boehler     * value
34*a1a3b679SAndreas Boehler     *
35*a1a3b679SAndreas Boehler     * @var string
36*a1a3b679SAndreas Boehler     */
37*a1a3b679SAndreas Boehler    protected $value;
38*a1a3b679SAndreas Boehler
39*a1a3b679SAndreas Boehler    /**
40*a1a3b679SAndreas Boehler     * Creates the property
41*a1a3b679SAndreas Boehler     *
42*a1a3b679SAndreas Boehler     * @param string $value
43*a1a3b679SAndreas Boehler     */
44*a1a3b679SAndreas Boehler    function __construct($value) {
45*a1a3b679SAndreas Boehler
46*a1a3b679SAndreas Boehler        if ($value !== self::TRANSPARENT && $value !== self::OPAQUE) {
47*a1a3b679SAndreas Boehler            throw new \InvalidArgumentException('The value must either be specified as "transparent" or "opaque"');
48*a1a3b679SAndreas Boehler        }
49*a1a3b679SAndreas Boehler        $this->value = $value;
50*a1a3b679SAndreas Boehler
51*a1a3b679SAndreas Boehler    }
52*a1a3b679SAndreas Boehler
53*a1a3b679SAndreas Boehler    /**
54*a1a3b679SAndreas Boehler     * Returns the current value
55*a1a3b679SAndreas Boehler     *
56*a1a3b679SAndreas Boehler     * @return string
57*a1a3b679SAndreas Boehler     */
58*a1a3b679SAndreas Boehler    function getValue() {
59*a1a3b679SAndreas Boehler
60*a1a3b679SAndreas Boehler        return $this->value;
61*a1a3b679SAndreas Boehler
62*a1a3b679SAndreas Boehler    }
63*a1a3b679SAndreas Boehler
64*a1a3b679SAndreas Boehler    /**
65*a1a3b679SAndreas Boehler     * The xmlSerialize metod is called during xml writing.
66*a1a3b679SAndreas Boehler     *
67*a1a3b679SAndreas Boehler     * Use the $writer argument to write its own xml serialization.
68*a1a3b679SAndreas Boehler     *
69*a1a3b679SAndreas Boehler     * An important note: do _not_ create a parent element. Any element
70*a1a3b679SAndreas Boehler     * implementing XmlSerializble should only ever write what's considered
71*a1a3b679SAndreas Boehler     * its 'inner xml'.
72*a1a3b679SAndreas Boehler     *
73*a1a3b679SAndreas Boehler     * The parent of the current element is responsible for writing a
74*a1a3b679SAndreas Boehler     * containing element.
75*a1a3b679SAndreas Boehler     *
76*a1a3b679SAndreas Boehler     * This allows serializers to be re-used for different element names.
77*a1a3b679SAndreas Boehler     *
78*a1a3b679SAndreas Boehler     * If you are opening new elements, you must also close them again.
79*a1a3b679SAndreas Boehler     *
80*a1a3b679SAndreas Boehler     * @param Writer $writer
81*a1a3b679SAndreas Boehler     * @return void
82*a1a3b679SAndreas Boehler     */
83*a1a3b679SAndreas Boehler    function xmlSerialize(Writer $writer) {
84*a1a3b679SAndreas Boehler
85*a1a3b679SAndreas Boehler        switch ($this->value) {
86*a1a3b679SAndreas Boehler            case self::TRANSPARENT :
87*a1a3b679SAndreas Boehler                $writer->writeElement('{' . Plugin::NS_CALDAV . '}transparent');
88*a1a3b679SAndreas Boehler                break;
89*a1a3b679SAndreas Boehler            case self::OPAQUE :
90*a1a3b679SAndreas Boehler                $writer->writeElement('{' . Plugin::NS_CALDAV . '}opaque');
91*a1a3b679SAndreas Boehler                break;
92*a1a3b679SAndreas Boehler        }
93*a1a3b679SAndreas Boehler
94*a1a3b679SAndreas Boehler    }
95*a1a3b679SAndreas Boehler
96*a1a3b679SAndreas Boehler    /**
97*a1a3b679SAndreas Boehler     * The deserialize method is called during xml parsing.
98*a1a3b679SAndreas Boehler     *
99*a1a3b679SAndreas Boehler     * This method is called statictly, this is because in theory this method
100*a1a3b679SAndreas Boehler     * may be used as a type of constructor, or factory method.
101*a1a3b679SAndreas Boehler     *
102*a1a3b679SAndreas Boehler     * Often you want to return an instance of the current class, but you are
103*a1a3b679SAndreas Boehler     * free to return other data as well.
104*a1a3b679SAndreas Boehler     *
105*a1a3b679SAndreas Boehler     * You are responsible for advancing the reader to the next element. Not
106*a1a3b679SAndreas Boehler     * doing anything will result in a never-ending loop.
107*a1a3b679SAndreas Boehler     *
108*a1a3b679SAndreas Boehler     * If you just want to skip parsing for this element altogether, you can
109*a1a3b679SAndreas Boehler     * just call $reader->next();
110*a1a3b679SAndreas Boehler     *
111*a1a3b679SAndreas Boehler     * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
112*a1a3b679SAndreas Boehler     * the next element.
113*a1a3b679SAndreas Boehler     *
114*a1a3b679SAndreas Boehler     * @param Reader $reader
115*a1a3b679SAndreas Boehler     * @return mixed
116*a1a3b679SAndreas Boehler     */
117*a1a3b679SAndreas Boehler    static function xmlDeserialize(Reader $reader) {
118*a1a3b679SAndreas Boehler
119*a1a3b679SAndreas Boehler        $elems = Elements::xmlDeserialize($reader);
120*a1a3b679SAndreas Boehler
121*a1a3b679SAndreas Boehler        $value = null;
122*a1a3b679SAndreas Boehler
123*a1a3b679SAndreas Boehler        foreach ($elems as $elem) {
124*a1a3b679SAndreas Boehler            switch ($elem) {
125*a1a3b679SAndreas Boehler                case '{' . Plugin::NS_CALDAV . '}opaque' :
126*a1a3b679SAndreas Boehler                    $value = self::OPAQUE;
127*a1a3b679SAndreas Boehler                    break;
128*a1a3b679SAndreas Boehler                case '{' . Plugin::NS_CALDAV . '}transparent' :
129*a1a3b679SAndreas Boehler                    $value = self::TRANSPARENT;
130*a1a3b679SAndreas Boehler                    break;
131*a1a3b679SAndreas Boehler            }
132*a1a3b679SAndreas Boehler        }
133*a1a3b679SAndreas Boehler        if (is_null($value))
134*a1a3b679SAndreas Boehler           return null;
135*a1a3b679SAndreas Boehler
136*a1a3b679SAndreas Boehler        return new self($value);
137*a1a3b679SAndreas Boehler
138*a1a3b679SAndreas Boehler    }
139*a1a3b679SAndreas Boehler
140*a1a3b679SAndreas Boehler}
141