1<?php
2
3namespace Sabre\CalDAV\Xml\Request;
4
5use Sabre\CalDAV\Plugin;
6use Sabre\Uri;
7use Sabre\Xml\Reader;
8use Sabre\Xml\XmlDeserializable;
9
10/**
11 * CalendarMultiGetReport request parser.
12 *
13 * This class parses the {urn:ietf:params:xml:ns:caldav}calendar-multiget
14 * REPORT, as defined in:
15 *
16 * https://tools.ietf.org/html/rfc4791#section-7.9
17 *
18 * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
19 * @author Evert Pot (http://www.rooftopsolutions.nl/)
20 * @license http://sabre.io/license/ Modified BSD License
21 */
22class CalendarMultiGetReport implements XmlDeserializable {
23
24    /**
25     * An array with requested properties.
26     *
27     * @var array
28     */
29    public $properties;
30
31    /**
32     * This is an array with the urls that are being requested.
33     *
34     * @var array
35     */
36    public $hrefs;
37
38    /**
39     * If the calendar data must be expanded, this will contain an array with 2
40     * elements: start and end.
41     *
42     * Each may be a DateTime or null.
43     *
44     * @var array|null
45     */
46    public $expand = null;
47
48    /**
49     * The mimetype of the content that should be returend. Usually
50     * text/calendar.
51     *
52     * @var string
53     */
54    public $contentType = null;
55
56    /**
57     * The version of calendar-data that should be returned. Usually '2.0',
58     * referring to iCalendar 2.0.
59     *
60     * @var string
61     */
62    public $version = null;
63
64    /**
65     * The deserialize method is called during xml parsing.
66     *
67     * This method is called statically, this is because in theory this method
68     * may be used as a type of constructor, or factory method.
69     *
70     * Often you want to return an instance of the current class, but you are
71     * free to return other data as well.
72     *
73     * You are responsible for advancing the reader to the next element. Not
74     * doing anything will result in a never-ending loop.
75     *
76     * If you just want to skip parsing for this element altogether, you can
77     * just call $reader->next();
78     *
79     * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
80     * the next element.
81     *
82     * @param Reader $reader
83     * @return mixed
84     */
85    static function xmlDeserialize(Reader $reader) {
86
87        $elems = $reader->parseInnerTree([
88            '{urn:ietf:params:xml:ns:caldav}calendar-data' => 'Sabre\\CalDAV\\Xml\\Filter\\CalendarData',
89            '{DAV:}prop'                                   => 'Sabre\\Xml\\Element\\KeyValue',
90        ]);
91
92        $newProps = [
93            'hrefs'      => [],
94            'properties' => [],
95        ];
96
97        foreach ($elems as $elem) {
98
99            switch ($elem['name']) {
100
101                case '{DAV:}prop' :
102                    $newProps['properties'] = array_keys($elem['value']);
103                    if (isset($elem['value']['{' . Plugin::NS_CALDAV . '}calendar-data'])) {
104                        $newProps += $elem['value']['{' . Plugin::NS_CALDAV . '}calendar-data'];
105                    }
106                    break;
107                case '{DAV:}href' :
108                    $newProps['hrefs'][] = Uri\resolve($reader->contextUri, $elem['value']);
109                    break;
110
111            }
112
113        }
114
115        $obj = new self();
116        foreach ($newProps as $key => $value) {
117            $obj->$key = $value;
118        }
119
120        return $obj;
121
122    }
123
124}
125