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