1: <?php
2: /**
3: * Handles the recurrence range attribute.
4: *
5: * PHP version 5
6: *
7: * @category Kolab
8: * @package Kolab_Format
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL
11: * @link http://www.horde.org/libraries/Horde_Kolab_Format
12: */
13:
14: /**
15: * Handles the recurrence range attribute.
16: *
17: * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (LGPL). If you did not
20: * receive this file, see
21: * http://www.horde.org/licenses/lgpl21.
22: *
23: * @since Horde_Kolab_Format 1.1.0
24: *
25: * @category Kolab
26: * @package Kolab_Format
27: * @author Gunnar Wrobel <wrobel@pardus.de>
28: * @license http://www.horde.org/licenses/lgpl21 LGPL
29: * @link http://www.horde.org/libraries/Horde_Kolab_Format
30: */
31: class Horde_Kolab_Format_Xml_Type_RecurrenceRange
32: extends Horde_Kolab_Format_Xml_Type_String
33: {
34: /**
35: * Load the value of a node.
36: *
37: * @param DOMNode $node Retrieve value for this node.
38: * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance.
39: * @param array $params Additiona parameters for
40: * this parse operation.
41: *
42: * @return mixed|null The value or null if no value was found.
43: */
44: public function loadNodeValue(
45: $node,
46: Horde_Kolab_Format_Xml_Helper $helper,
47: $params = array()
48: )
49: {
50: $result = $helper->fetchNodeValue($node);
51: $type = $node->getAttribute('type');
52: if (empty($type) || $type == 'none') {
53: return null;
54: }
55: if ($type == 'date') {
56: $tz = $node->getAttribute('tz');
57: if (empty($tz)) {
58: /**
59: * @todo Be more strict once KEP2 has been completely adopted if
60: * (!$this->isRelaxed()) throw new Horde_Kolab_Format_Exception();
61: */
62: $tz = 'UTC';
63: }
64: return Horde_Kolab_Format_Date::readDate($result, $tz);
65: }
66: return $result;
67: }
68:
69: /**
70: * Update the specified attribute.
71: *
72: * @param string $name The name of the attribute
73: * to be updated.
74: * @param mixed $value The value to store.
75: * @param DOMNode $parent_node The parent node of the
76: * node that should be
77: * updated.
78: * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance.
79: * @param array $params The parameters for this
80: * write operation.
81: * @param DOMNode|NULL $old_node The previous value (or
82: * null if there is none).
83: *
84: * @return DOMNode|boolean The new/updated child node or false if this
85: * failed.
86: *
87: * @throws Horde_Kolab_Format_Exception If converting the data to XML failed.
88: */
89: public function saveNodeValue(
90: $name,
91: $value,
92: $parent_node,
93: Horde_Kolab_Format_Xml_Helper $helper,
94: $params = array(),
95: $old_node = false
96: )
97: {
98: $tz = false;
99: if (empty($value)) {
100: $type = 'none';
101: $value = '';
102: } else if ($value instanceOf DateTime) {
103: $type = 'date';
104: $tz = $value->getTimezone()->getName();
105: $value = Horde_Kolab_Format_Date::writeDate($value);
106: } else {
107: $type = 'number';
108: }
109: $node = parent::saveNodeValue(
110: $name, $value, $parent_node, $helper, $params, $old_node
111: );
112: $node->setAttribute('type', $type);
113: if ($tz !== false) {
114: $node->setAttribute('tz', $tz);
115: }
116: return $node;
117: }
118: }
119: