1: <?php
2: /**
3: * Handles api version 1 of 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 api version 1 of 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_V1
32: extends Horde_Kolab_Format_Xml_Type_String
33: {
34: /**
35: * Load the node value from the Kolab object.
36: *
37: * @param string $name The name of the the
38: * attribute to be fetched.
39: * @param array &$attributes The data array that
40: * holds all attribute
41: * values.
42: * @param DOMNode $parent_node The parent node of the
43: * node to be loaded.
44: * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance.
45: * @param array $params Additiona parameters for
46: * this parse operation.
47: *
48: * @return DOMNode|boolean The named DOMNode or false if no node value was
49: * found.
50: */
51: public function load(
52: $name,
53: &$attributes,
54: $parent_node,
55: Horde_Kolab_Format_Xml_Helper $helper,
56: $params = array()
57: )
58: {
59: $result = parent::load($name, $attributes, $parent_node, $helper, $params);
60: if ($result !== false) {
61: $type = $result->getAttribute('type');
62: if (!empty($type) && $type != 'none') {
63: $attributes['range-type'] = $type;
64: }
65: }
66: return $result;
67: }
68:
69: /**
70: * Load the value of a node.
71: *
72: * @param DOMNode $node Retrieve value for this node.
73: * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance.
74: * @param array $params Additiona parameters for
75: * this parse operation.
76: *
77: * @return mixed|null The value or null if no value was found.
78: */
79: public function loadNodeValue(
80: $node,
81: Horde_Kolab_Format_Xml_Helper $helper,
82: $params = array()
83: )
84: {
85: $result = $helper->fetchNodeValue($node);
86: $type = $node->getAttribute('type');
87: if (empty($type) || $type == 'none') {
88: return null;
89: }
90: if ($type == 'date') {
91: return Horde_Kolab_Format_Date::decodeDate($result);
92: }
93: return $result;
94: }
95:
96: /**
97: * Update the specified attribute.
98: *
99: * @param string $name The name of the the
100: * attribute to be updated.
101: * @param array $attributes The data array that holds
102: * all attribute values.
103: * @param DOMNode $parent_node The parent node of the
104: * node that should be
105: * updated.
106: * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance.
107: * @param array $params Additional parameters
108: * for this write operation.
109: *
110: * @return DOMNode|boolean The new/updated child node or false if this
111: * failed.
112: *
113: * @throws Horde_Kolab_Format_Exception If converting the data to XML failed.
114: */
115: public function save(
116: $name,
117: $attributes,
118: $parent_node,
119: Horde_Kolab_Format_Xml_Helper $helper,
120: $params = array()
121: )
122: {
123: if (isset($attributes['range-type']) &&
124: $attributes['range-type'] == 'date') {
125: $attributes[$name] = Horde_Kolab_Format_Date::encodeDate($attributes[$name]);
126: }
127: $node = parent::save(
128: $name, $attributes, $parent_node, $helper, $params
129: );
130: if (isset($attributes['range-type'])) {
131: $type = $attributes['range-type'];
132: } else {
133: $type = 'none';
134: }
135: $node->setAttribute('type', $type);
136: }
137: }
138: