Overview

Packages

  • None
  • Share

Classes

  • Horde_Share_Base
  • Horde_Share_Datatree
  • Horde_Share_Kolab
  • Horde_Share_Object
  • Horde_Share_Object_Datatree
  • Horde_Share_Object_DataTree_Share
  • Horde_Share_Object_Kolab
  • Horde_Share_Object_Sql
  • Horde_Share_Object_Sqlng
  • Horde_Share_Sql
  • Horde_Share_Sqlng
  • Horde_Share_Translation
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Abstract class for storing Share information.
  4:  *
  5:  * This class should be extended for the more specific drivers.
  6:  *
  7:  * @author  Mike Cochrane <mike@graftonhall.co.nz>
  8:  * @author  Jan Schneider <jan@horde.org>
  9:  * @author  Gunnar Wrobel <wrobel@pardus.de>
 10:  * @package Share
 11:  */
 12: abstract class Horde_Share_Object implements Serializable
 13: {
 14:     /**
 15:      * A function to be called when a Horde_Share object is needed and not
 16:      * available.
 17:      *
 18:      * @var callback
 19:      */
 20:     protected $_shareCallback;
 21: 
 22:     /**
 23:      * The Horde_Share object which this share is associated with.
 24:      * If this is empty, the $_shareCallback is called to obtain it.
 25:      *
 26:      * @var Horde_Share
 27:      */
 28:     protected $_shareOb;
 29: 
 30:     /**
 31:      * Associates a Share object with this share, or provides a callback that
 32:      * knows how to provide it.
 33:      *
 34:      * @param mixed Horde_Share | Callback $shareOb  The Share object.
 35:      */
 36:     public function setShareOb($shareOb)
 37:     {
 38:         if ($shareOb instanceof Horde_Share_Base) {
 39:             $this->_shareOb = $shareOb;
 40:         } else {
 41:             $this->_shareCallback = $shareOb;
 42:         }
 43:     }
 44: 
 45:     /**
 46:      * Obtain this object's share driver.
 47:      *
 48:      * @return Horde_Share  The share driver.
 49:      */
 50:     public function getShareOb()
 51:     {
 52:         if (empty($this->_shareOb)) {
 53:             $this->_shareOb = call_user_func($this->_shareCallback);
 54:         }
 55: 
 56:         if (empty($this->_shareOb)) {
 57:             throw new Horde_Share_Exception('Unable to obtain a Horde_Share object');
 58:         }
 59:         return $this->_shareOb;
 60:     }
 61: 
 62:     /**
 63:      * Sets an attribute value in this object.
 64:      *
 65:      * @param string $attribute  The attribute to set.
 66:      * @param mixed $value       The value for $attribute.
 67:      * @param boolean $update    Immediately update only this change.
 68:      *
 69:      * @return boolean
 70:      */
 71:     abstract public function set($attribute, $value, $update = false);
 72: 
 73:     /**
 74:      * Returns an attribute value from this object.
 75:      *
 76:      * @param string $attribute  The attribute to return.
 77:      *
 78:      * @return mixed  The value for $attribute.
 79:      */
 80:     abstract public function get($attribute);
 81: 
 82:     /**
 83:      * Returns the ID of this share.
 84:      *
 85:      * @return string  The share's ID.
 86:      */
 87:     abstract public function getId();
 88: 
 89:     /**
 90:      * Returns the name of this share.
 91:      *
 92:      * @return string  The share's name.
 93:      */
 94:     abstract public function getName();
 95: 
 96:     /**
 97:      * Saves the current attribute values.
 98:      *
 99:      * @return boolean
100:      * @throws Horde_Exception
101:      */
102:     public function save()
103:     {
104:         $this->getShareOb()->runCallback('modify', array($this));
105:         $this->getShareOb()->expireListCache();
106:         return $this->_save();
107:     }
108: 
109:     /**
110:      * Saves the current attribute values.
111:      */
112:     abstract protected function _save();
113: 
114:     /**
115:      * Gives a user a certain privilege for this share.
116:      *
117:      * @param string $userid       The userid of the user.
118:      * @param integer $permission  A Horde_Perms::* constant.
119:      */
120:     public function addUserPermission($userid, $permission)
121:     {
122:         $perm = $this->getPermission();
123:         $perm->addUserPermission($userid, $permission, false);
124:         $this->setPermission($perm);
125:     }
126: 
127:     /**
128:      * Removes a certain privilege for a user from this share.
129:      *
130:      * @param string $userid       The userid of the user.
131:      * @param integer $permission  A Horde_Perms::* constant.
132:      */
133:     public function removeUserPermission($userid, $permission)
134:     {
135:         $perm = $this->getPermission();
136:         $perm->removeUserPermission($userid, $permission, false);
137:         $this->setPermission($perm);
138:     }
139: 
140:     /**
141:      * Gives a group certain privileges for this share.
142:      *
143:      * @param string $group        The group to add permissions for.
144:      * @param integer $permission  A Horde_Perms::* constant.
145:      */
146:     public function addGroupPermission($group, $permission)
147:     {
148:         $perm = $this->getPermission();
149:         $perm->addGroupPermission($group, $permission, false);
150:         $this->setPermission($perm);
151:     }
152: 
153:     /**
154:      * Removes a certain privilege from a group.
155:      *
156:      * @param string $group         The group to remove permissions from.
157:      * @param constant $permission  A Horde_Perms::* constant.
158:      */
159:     public function removeGroupPermission($group, $permission)
160:     {
161:         $perm = $this->getPermission();
162:         $perm->removeGroupPermission($group, $permission, false);
163:         $this->setPermission($perm);
164:     }
165: 
166:     /**
167:      * Removes a user from this share.
168:      *
169:      * @param string $userid  The userid of the user to remove.
170:      */
171:     public function removeUser($userid)
172:     {
173:         /* Remove all $userid's permissions. */
174:         $perm = $this->getPermission();
175:         $perm->removeUserPermission($userid, Horde_Perms::SHOW, false);
176:         $perm->removeUserPermission($userid, Horde_Perms::READ, false);
177:         $perm->removeUserPermission($userid, Horde_Perms::EDIT, false);
178:         $perm->removeUserPermission($userid, Horde_Perms::DELETE, false);
179: 
180:         return $this->setPermission($perm);
181:     }
182: 
183:     /**
184:      * Removes a group from this share.
185:      *
186:      * @param integer $groupId  The group to remove.
187:      */
188:     public function removeGroup($groupId)
189:     {
190:         /* Remove all $groupId's permissions. */
191:         $perm = $this->getPermission();
192:         $perm->removeGroupPermission($groupId, Horde_Perms::SHOW, false);
193:         $perm->removeGroupPermission($groupId, Horde_Perms::READ, false);
194:         $perm->removeGroupPermission($groupId, Horde_Perms::EDIT, false);
195:         $perm->removeGroupPermission($groupId, Horde_Perms::DELETE, false);
196: 
197:         return $this->setPermission($perm);
198:     }
199: 
200:     /**
201:      * Returns an array containing all the userids of the users with access to
202:      * this share.
203:      *
204:      * @param integer $perm_level  List only users with this permission level.
205:      *                             Defaults to all users.
206:      *
207:      * @return array  The users with access to this share.
208:      */
209:     public function listUsers($perm_level = null)
210:     {
211:         $perm = $this->getPermission();
212:         $results = array_keys($perm->getUserPermissions($perm_level));
213:         // Always return the share's owner.
214:         if ($this->get('owner')) {
215:             array_push($results, $this->get('owner'));
216:         }
217:         return $results;
218:     }
219: 
220:     /**
221:      * Returns an array containing all the groupids of the groups with access
222:      * to this share.
223:      *
224:      * @param integer $perm_level  List only users with this permission level.
225:      *                             Defaults to all users.
226:      *
227:      * @return array  The IDs of the groups with access to this share.
228:      */
229:     public function listGroups($perm_level = null)
230:     {
231:         $perm = $this->getPermission();
232:         return array_keys($perm->getGroupPermissions($perm_level));
233:     }
234: 
235:     /**
236:      * Gives guests a certain privilege for this share.
237:      *
238:      * @param integer $permission  A Horde_Perms::* constant.
239:      */
240:     public function addGuestPermission($permission)
241:     {
242:         $perm = $this->getPermission();
243:         $perm->addGuestPermission($permission, false);
244:         $this->setPermission($perm);
245:     }
246: 
247:     /**
248:      * Removes a certain privilege for guests from this share.
249:      *
250:      * @param integer $permission  A Horde_Perms::* constant.
251:      */
252:     public function removeGuestPermission($permission)
253:     {
254:         $perm = $this->getPermission();
255:         $perm->removeGuestPermission($permission, false);
256:         $this->setPermission($perm);
257:     }
258: 
259:     /**
260:      * Gives creators a certain privilege for this share.
261:      *
262:      * @param integer $permission  A Horde_Perms::* constant.
263:      */
264:     public function addCreatorPermission($permission)
265:     {
266:         $perm = $this->getPermission();
267:         $perm->addCreatorPermission($permission, false);
268:         $this->setPermission($perm);
269:     }
270: 
271:     /**
272:      * Removes a certain privilege for creators from this share.
273:      *
274:      * @param integer $permission  A Horde_Perms::* constant.
275:      */
276:     public function removeCreatorPermission($permission)
277:     {
278:         $perm = $this->getPermission();
279:         $perm->removeCreatorPermission($permission, false);
280:         $this->setPermission($perm);
281:     }
282: 
283:     /**
284:      * Gives all authenticated users a certain privilege for this share.
285:      *
286:      * @param integer $permission  A Horde_Perms::* constant.
287:      */
288:     public function addDefaultPermission($permission)
289:     {
290:         $perm = $this->getPermission();
291:         $perm->addDefaultPermission($permission, false);
292:         $this->setPermission($perm);
293:     }
294: 
295:     /**
296:      * Removes a certain privilege for all authenticated users from this share.
297:      *
298:      * @param integer $permission  A Horde_Perms::* constant.
299:      */
300:     public function removeDefaultPermission($permission)
301:     {
302:         $perm = $this->getPermission();
303:         $perm->removeDefaultPermission($permission, false);
304:         $this->setPermission($perm);
305:     }
306: 
307:     /**
308:      * Checks to see if a user has a given permission.
309:      *
310:      * @param string $userid       The userid of the user.
311:      * @param integer $permission  A Horde_Perms::* constant to test for.
312:      * @param string $creator      The creator of the event.
313:      *
314:      * @return boolean  Whether or not $userid has $permission.
315:      */
316:     abstract public function hasPermission($userid, $permission,
317:                                            $creator = null);
318: 
319:     /**
320:      * Sets the permission of this share.
321:      *
322:      * @param Horde_Perms_Permission $perm  Permission object.
323:      * @param boolean $update               Should the share be saved
324:      *                                      after this operation?
325:      */
326:     abstract public function setPermission($perm, $update = true);
327: 
328:     /**
329:      * Returns the permission of this share.
330:      *
331:      * @return Horde_Perms_Permission  Permission object that represents the
332:      *                                 permissions on this share.
333:      */
334:     abstract public function getPermission();
335: }
336: 
API documentation generated by ApiGen