1: <?php
2: /**
3: * Basic query for preferences data.
4: *
5: * PHP version 5
6: *
7: * @category Kolab
8: * @package Kolab_Storage
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
11: * @link http://pear.horde.org/index.php?package=Kolab_Storage
12: */
13:
14: /**
15: * Basic query for preferences data.
16: *
17: * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (LGPL). If you
20: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
21: *
22: * @since Horde_Kolab_Storage 1.1.0
23: *
24: * @category Kolab
25: * @package Kolab_Storage
26: * @author Gunnar Wrobel <wrobel@pardus.de>
27: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
28: * @link http://pear.horde.org/index.php?package=Kolab_Storage
29: */
30: class Horde_Kolab_Storage_Data_Query_Preferences_Base
31: implements Horde_Kolab_Storage_Data_Query_Preferences
32: {
33: /**
34: * The queriable data.
35: *
36: * @var Horde_Kolab_Storage_Data
37: */
38: private $_data;
39:
40: /**
41: * The cached preference mapping.
42: *
43: * @var array
44: */
45: private $_mapping;
46:
47: /**
48: * Constructor.
49: *
50: * @param Horde_Kolab_Storage_Data $data The queriable data.
51: * @param array $params Additional parameters.
52: */
53: public function __construct(Horde_Kolab_Storage_Data $data,
54: $params)
55: {
56: $this->_data = $data;
57: }
58:
59: /**
60: * Return the preferences for the specified application.
61: *
62: * @param string $application The application.
63: *
64: * @return array The preferences.
65: */
66: public function getApplicationPreferences($application)
67: {
68: $this->_initMapping();
69: if (isset($this->_mapping[$application])) {
70: return $this->_data->getObject($this->_mapping[$application]);
71: } else {
72: throw new Horde_Kolab_Storage_Exception(
73: sprintf(
74: 'No preferences for application %s available',
75: $application
76: )
77: );
78: }
79: }
80:
81: /**
82: * Return the applications for which preferences exist in the backend.
83: *
84: * @param string $application The application.
85: *
86: * @return array The applications.
87: */
88: public function getApplications()
89: {
90: $this->_initMapping();
91: return array_keys($this->_mapping);
92: }
93:
94: /**
95: * Initialize the application <-> object mapping.
96: *
97: * @return NULL
98: */
99: private function _initMapping()
100: {
101: if ($this->_mapping === null) {
102: foreach ($this->_data->getObjects() as $id => $data) {
103: $this->_mapping[$data['application']] = $id;
104: }
105: }
106: }
107:
108: /**
109: * Synchronize the preferences information with the information from the
110: * backend.
111: *
112: * @param array $params Additional parameters.
113: *
114: * @return NULL
115: */
116: public function synchronize($params = array())
117: {
118: }
119: }