PageRenderTime 143ms CodeModel.GetById 60ms app.highlight 3ms RepoModel.GetById 77ms app.codeStats 0ms

/lib/Sabre/CalDAV/Property/ScheduleCalendarTransp.php

https://github.com/KOLANICH/SabreDAV
PHP | 103 lines | 46 code | 19 blank | 38 comment | 3 complexity | 571bcf6f1571524b97041c2875be0a66 MD5 | raw file
  1<?php
  2
  3namespace Sabre\CalDAV\Property;
  4
  5use Sabre\DAV;
  6use Sabre\CalDAV;
  7
  8/**
  9 * schedule-calendar-transp property.
 10 *
 11 * This property is a representation of the schedule-calendar-transp property.
 12 * This property is defined in RFC6638 (caldav scheduling).
 13 *
 14 * Its values are either 'transparent' or 'opaque'. If it's transparent, it
 15 * means that this calendar will not be taken into consideration when a
 16 * different user queries for free-busy information. If it's 'opaque', it will.
 17 *
 18 * @copyright Copyright (C) 2007-2013 fruux GmbH (https://fruux.com/).
 19 * @author Evert Pot (http://evertpot.com/)
 20 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
 21 */
 22class ScheduleCalendarTransp extends DAV\Property {
 23
 24    const TRANSPARENT = 'transparent';
 25    const OPAQUE = 'opaque';
 26
 27    protected $value;
 28
 29    /**
 30     * Creates the property
 31     *
 32     * @param string $value
 33     */
 34    public function __construct($value) {
 35
 36        if ($value !== self::TRANSPARENT && $value !== self::OPAQUE) {
 37            throw new \InvalidArgumentException('The value must either be specified as "transparent" or "opaque"');
 38        }
 39        $this->value = $value;
 40
 41    }
 42
 43    /**
 44     * Returns the current value
 45     *
 46     * @return string
 47     */
 48    public function getValue() {
 49
 50        return $this->value;
 51
 52    }
 53
 54    /**
 55     * Serializes the property in a DOMDocument
 56     *
 57     * @param DAV\Server $server
 58     * @param \DOMElement $node
 59     * @return void
 60     */
 61    public function serialize(DAV\Server $server,\DOMElement $node) {
 62
 63        $doc = $node->ownerDocument;
 64        switch($this->value) {
 65            case self::TRANSPARENT :
 66                $xval = $doc->createElement('cal:transparent');
 67                break;
 68            case self::OPAQUE :
 69                $xval = $doc->createElement('cal:opaque');
 70                break;
 71        }
 72
 73        $node->appendChild($xval);
 74
 75    }
 76
 77    /**
 78     * Unserializes the DOMElement back into a Property class.
 79     *
 80     * @param \DOMElement $node
 81     * @param array $propertyMap
 82     * @return ScheduleCalendarTransp
 83     */
 84    static function unserialize(\DOMElement $node, array $propertyMap) {
 85
 86        $value = null;
 87        foreach($node->childNodes as $childNode) {
 88            switch(DAV\XMLUtil::toClarkNotation($childNode)) {
 89                case '{' . CalDAV\Plugin::NS_CALDAV . '}opaque' :
 90                    $value = self::OPAQUE;
 91                    break;
 92                case '{' . CalDAV\Plugin::NS_CALDAV . '}transparent' :
 93                    $value = self::TRANSPARENT;
 94                    break;
 95            }
 96        }
 97        if (is_null($value))
 98           return null;
 99
100        return new self($value);
101
102    }
103}