1<?php
2
3namespace Sabre\CalDAV\Xml\Property;
4
5use Sabre\CalDAV\Plugin;
6use Sabre\Xml\Writer;
7use Sabre\Xml\XmlSerializable;
8
9/**
10 * AllowedSharingModes
11 *
12 * This property encodes the 'allowed-sharing-modes' property, as defined by
13 * the 'caldav-sharing-02' spec, in the http://calendarserver.org/ns/
14 * namespace.
15 *
16 * This property is a representation of the supported-calendar_component-set
17 * property in the CalDAV namespace. It simply requires an array of components,
18 * such as VEVENT, VTODO
19 *
20 * @see https://trac.calendarserver.org/browser/CalendarServer/trunk/doc/Extensions/caldav-sharing-02.txt
21 * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
22 * @author Evert Pot (http://www.rooftopsolutions.nl/)
23 * @license http://sabre.io/license/ Modified BSD License
24 */
25class AllowedSharingModes implements XmlSerializable {
26
27    /**
28     * Whether or not a calendar can be shared with another user
29     *
30     * @var bool
31     */
32    protected $canBeShared;
33
34    /**
35     * Whether or not the calendar can be placed on a public url.
36     *
37     * @var bool
38     */
39    protected $canBePublished;
40
41    /**
42     * Constructor
43     *
44     * @param bool $canBeShared
45     * @param bool $canBePublished
46     * @return void
47     */
48    function __construct($canBeShared, $canBePublished) {
49
50        $this->canBeShared = $canBeShared;
51        $this->canBePublished = $canBePublished;
52
53    }
54
55    /**
56     * The xmlSerialize method is called during xml writing.
57     *
58     * Use the $writer argument to write its own xml serialization.
59     *
60     * An important note: do _not_ create a parent element. Any element
61     * implementing XmlSerializable should only ever write what's considered
62     * its 'inner xml'.
63     *
64     * The parent of the current element is responsible for writing a
65     * containing element.
66     *
67     * This allows serializers to be re-used for different element names.
68     *
69     * If you are opening new elements, you must also close them again.
70     *
71     * @param Writer $writer
72     * @return void
73     */
74    function xmlSerialize(Writer $writer) {
75
76        if ($this->canBeShared) {
77            $writer->writeElement('{' . Plugin::NS_CALENDARSERVER . '}can-be-shared');
78        }
79        if ($this->canBePublished) {
80            $writer->writeElement('{' . Plugin::NS_CALENDARSERVER . '}can-be-published');
81        }
82
83    }
84
85
86
87}
88