aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/lib/SabreDAV/lib/OldSabre/DAV/Property/SupportedReportSet.php
blob: ecbde7d89d9808770c973be8a36838be61287393 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php

namespace OldSabre\DAV\Property;

use OldSabre\DAV;

/**
 * supported-report-set property.
 *
 * This property is defined in RFC3253, but since it's
 * so common in other webdav-related specs, it is part of the core server.
 *
 * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
 * @author Evert Pot (http://evertpot.com/)
 * @license http://sabre.io/license/ Modified BSD License
 */
class SupportedReportSet extends DAV\Property {

    /**
     * List of reports
     *
     * @var array
     */
    protected $reports = array();

    /**
     * Creates the property
     *
     * Any reports passed in the constructor
     * should be valid report-types in clark-notation.
     *
     * Either a string or an array of strings must be passed.
     *
     * @param mixed $reports
     */
    public function __construct($reports = null) {

        if (!is_null($reports))
            $this->addReport($reports);

    }

    /**
     * Adds a report to this property
     *
     * The report must be a string in clark-notation.
     * Multiple reports can be specified as an array.
     *
     * @param mixed $report
     * @return void
     */
    public function addReport($report) {

        if (!is_array($report)) $report = array($report);

        foreach($report as $r) {

            if (!preg_match('/^{([^}]*)}(.*)$/',$r))
                throw new DAV\Exception('Reportname must be in clark-notation');

            $this->reports[] = $r;

        }

    }

    /**
     * Returns the list of supported reports
     *
     * @return array
     */
    public function getValue() {

        return $this->reports;

    }

    /**
     * Serializes the node
     *
     * @param DAV\Server $server
     * @param \DOMElement $prop
     * @return void
     */
    public function serialize(DAV\Server $server, \DOMElement $prop) {

        foreach($this->reports as $reportName) {

            $supportedReport = $prop->ownerDocument->createElement('d:supported-report');
            $prop->appendChild($supportedReport);

            $report = $prop->ownerDocument->createElement('d:report');
            $supportedReport->appendChild($report);

            preg_match('/^{([^}]*)}(.*)$/',$reportName,$matches);

            list(, $namespace, $element) = $matches;

            $prefix = isset($server->xmlNamespaces[$namespace])?$server->xmlNamespaces[$namespace]:null;

            if ($prefix) {
                $report->appendChild($prop->ownerDocument->createElement($prefix . ':' . $element));
            } else {
                $report->appendChild($prop->ownerDocument->createElementNS($namespace, 'x:' . $element));
            }

        }

    }

}

© 2014-2024 Faster IT GmbH | imprint | privacy policy