1: <?php
2: /**
3: * Handles the preferences "application" 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 preferences "application" 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_PrefsApplication
32: extends Horde_Kolab_Format_Xml_Type_Base
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:
61: if ($result === false) {
62: $result = parent::load('categories', $attributes, $parent_node, $helper, $params);
63: }
64:
65: if ($result !== false &&
66: ($value = $this->loadNodeValue($result, $helper, $params)) !== null) {
67: $attributes[$name] = $value;
68: return $result;
69: } else if (!$this->isRelaxed($params)) {
70: throw new Horde_Kolab_Format_Exception_MissingValue('Preferences XML object is missing an application setting.');
71: } else {
72: return false;
73: }
74: }
75:
76: /**
77: * Update the specified attribute.
78: *
79: * @param string $name The name of the the
80: * attribute to be updated.
81: * @param array $attributes The data array that holds
82: * all attribute values.
83: * @param DOMNode $parent_node The parent node of the
84: * node that should be
85: * updated.
86: * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance.
87: * @param array $params Additional parameters
88: * for this write operation.
89: *
90: * @return DOMNode|boolean The new/updated child node or false if this
91: * failed.
92: *
93: * @throws Horde_Kolab_Format_Exception If converting the data to XML failed.
94: */
95: public function save(
96: $name,
97: $attributes,
98: $parent_node,
99: Horde_Kolab_Format_Xml_Helper $helper,
100: $params = array()
101: )
102: {
103: $node = $helper->findNodeRelativeTo(
104: './' . $name, $parent_node
105: );
106:
107: if (!isset($attributes[$name])) {
108: if (!empty($attributes['categories'])) {
109: $attributes[$name] = $attributes['categories'];
110: unset($attributes['categories']);
111: }
112: }
113:
114: if (!isset($attributes[$name]) && $node === false &&
115: !$this->isRelaxed($params)) {
116: throw new Horde_Kolab_Format_Exception_MissingValue('Preferences data is missing an application setting.');
117: }
118:
119: if ($node === false) {
120: $categories = $helper->findNodeRelativeTo(
121: './categories', $parent_node
122: );
123: /** Remove old categories entry */
124: $helper->removeNodes($parent_node, 'categories');
125: }
126:
127: return $this->saveNodeValue(
128: $name,
129: $this->generateWriteValue($name, $attributes, $params),
130: $parent_node,
131: $helper,
132: $params,
133: $node
134: );
135: }
136: }
137: