1: <?php
2: /**
3: * Handles a cached list of folder acls.
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: * Handles a cached list of folder acls.
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: * @category Kolab
23: * @package Kolab_Storage
24: * @author Gunnar Wrobel <wrobel@pardus.de>
25: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
26: * @link http://pear.horde.org/index.php?package=Kolab_Storage
27: */
28: class Horde_Kolab_Storage_List_Query_Acl_Cache
29: extends Horde_Kolab_Storage_List_Query_Acl_Base
30: {
31: /** The acl support */
32: const CAPABILITY = 'ACL';
33:
34: /** The ACL query data */
35: const ACL = 'ACL';
36:
37: /** The user specific rights */
38: const MYRIGHTS = 'MYRIGHTS';
39:
40: /** All rights */
41: const ALLRIGHTS = 'ALLRIGHTS';
42:
43: /**
44: * The list cache.
45: *
46: * @var Horde_Kolab_Storage_Cache_List
47: */
48: private $_list_cache;
49:
50: /**
51: * The cached ACL data.
52: *
53: * @var array
54: */
55: private $_acl;
56:
57: /**
58: * The cached user rights.
59: *
60: * @var array
61: */
62: private $_my_rights;
63:
64: /**
65: * The cached rights.
66: *
67: * @var array
68: */
69: private $_all_rights;
70:
71: /**
72: * Constructor.
73: *
74: * @param Horde_Kolab_Storage_List $list The queriable list.
75: * @param array $params Additional parameters.
76: */
77: public function __construct(Horde_Kolab_Storage_List $list,
78: $params)
79: {
80: parent::__construct($list, $params);
81: $this->_list_cache = $params['cache'];
82: if ($this->_list_cache->hasQuery(self::ACL)) {
83: $this->_acl = $this->_list_cache->getQuery(self::ACL);
84: } else {
85: $this->_acl = array();
86: }
87: if ($this->_list_cache->hasQuery(self::MYRIGHTS)) {
88: $this->_my_rights = $this->_list_cache->getQuery(self::MYRIGHTS);
89: } else {
90: $this->_my_rights = array();
91: }
92: }
93:
94: /**
95: * Does the backend support ACL?
96: *
97: * @return boolean True if the backend supports ACLs.
98: */
99: public function hasAclSupport()
100: {
101: if (!$this->_list_cache->issetSupport(self::CAPABILITY)) {
102: $this->_list_cache->setSupport(
103: self::CAPABILITY,
104: parent::hasAclSupport()
105: );
106: $this->_list_cache->save();
107: }
108: return $this->_list_cache->hasSupport(self::CAPABILITY);
109: }
110:
111: /**
112: * Retrieve the access rights for a folder.
113: *
114: * @param string $folder The folder to retrieve the ACL for.
115: *
116: * @return array An array of rights.
117: */
118: public function getAcl($folder)
119: {
120: if (!isset($this->_acl[$folder])) {
121: $this->_acl[$folder] = parent::getAcl($folder);
122: $this->_list_cache->setQuery(self::ACL, $this->_acl);
123: $this->_list_cache->save();
124: }
125: return $this->_acl[$folder];
126: }
127:
128: /**
129: * Retrieve the access rights the current user has on a folder.
130: *
131: * @param string $folder The folder to retrieve the user ACL for.
132: *
133: * @return string The user rights.
134: */
135: public function getMyAcl($folder)
136: {
137: if (!isset($this->_my_rights[$folder])) {
138: $this->_my_rights[$folder] = parent::getMyAcl($folder);
139: $this->_list_cache->setQuery(self::MYRIGHTS, $this->_my_rights);
140: $this->_list_cache->save();
141: }
142: return $this->_my_rights[$folder];
143: }
144:
145: /**
146: * Retrieve the all access rights on a folder.
147: *
148: * @param string $folder The folder to retrieve the ACL for.
149: *
150: * @since Horde_Kolab_Storage 1.1.0
151: *
152: * @return string The folder rights.
153: */
154: public function getAllAcl($folder)
155: {
156: if (!isset($this->_all_rights[$folder])) {
157: $this->_all_rights[$folder] = parent::getAllAcl($folder);
158: $this->_list_cache->setQuery(self::ALLRIGHTS, $this->_all_rights);
159: $this->_list_cache->save();
160: }
161: return $this->_all_rights[$folder];
162: }
163:
164: /**
165: * Set the access rights for a folder.
166: *
167: * @param string $folder The folder to act upon.
168: * @param string $user The user to set the ACL for.
169: * @param string $acl The ACL.
170: *
171: * @return NULL
172: */
173: public function setAcl($folder, $user, $acl)
174: {
175: parent::setAcl($folder, $user, $acl);
176: $this->_purgeFolder($folder);
177: }
178:
179: /**
180: * Delete the access rights for user on a folder.
181: *
182: * @param string $folder The folder to act upon.
183: * @param string $user The user to delete the ACL for
184: *
185: * @return NULL
186: */
187: public function deleteAcl($folder, $user)
188: {
189: parent::deleteAcl($folder, $user);
190: $this->_purgeFolder($folder);
191: }
192:
193: /**
194: * Create a new folder.
195: *
196: * @param string $folder The path of the folder to create.
197: * @param string $type An optional type for the folder.
198: *
199: * @return NULL
200: */
201: public function createFolder($folder, $type = null)
202: {
203: }
204:
205: /**
206: * Delete a folder.
207: *
208: * @param string $folder The path of the folder to delete.
209: *
210: * @return NULL
211: */
212: public function deleteFolder($folder)
213: {
214: $this->_purgeFolder($folder);
215: }
216:
217: /**
218: * Rename a folder.
219: *
220: * @param string $old The old path of the folder.
221: * @param string $new The new path of the folder.
222: *
223: * @return NULL
224: */
225: public function renameFolder($old, $new)
226: {
227: $this->_purgeFolder($old);
228: }
229:
230: /**
231: * Return the last sync stamp.
232: *
233: * @return string The stamp.
234: */
235: public function getStamp()
236: {
237: return $this->_list->getStamp();
238: }
239:
240: /**
241: * Synchronize the ACL information with the information from the backend.
242: *
243: * @param array $params Additional parameters.
244: *
245: * @return NULL
246: */
247: public function synchronize($params = array())
248: {
249: $this->_acl = array();
250: $this->_my_rights = array();
251: $this->_all_rights = array();
252: }
253:
254: /**
255: * Remove outdated folder data from the cache.
256: *
257: * @param string $folder The folder name.
258: *
259: * @return NULL
260: */
261: private function _purgeFolder($folder)
262: {
263: unset($this->_acl[$folder]);
264: unset($this->_my_rights[$folder]);
265: unset($this->_all_rights[$folder]);
266: $this->_list_cache->setQuery(self::ACL, $this->_acl);
267: $this->_list_cache->setQuery(self::MYRIGHTS, $this->_my_rights);
268: $this->_list_cache->setQuery(self::MYRIGHTS, $this->_all_rights);
269: $this->_list_cache->save();
270: }
271: }