4 * Principals Collection
6 * This is a helper class that easily allows you to create a collection that
7 * has a childnode for every principal.
9 * To use this class, simply implement the getChildForPrincipal method.
13 * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
14 * @author Evert Pot (http://www.rooftopsolutions.nl/)
15 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
17 abstract class Sabre_DAVACL_AbstractPrincipalCollection extends Sabre_DAV_Collection {
20 * Node or 'directory' name.
29 * @var Sabre_DAVACL_IPrincipalBackend
31 protected $principalBackend;
34 * If this value is set to true, it effectively disables listing of users
35 * it still allows user to find other users if they have an exact url.
39 public $disableListing = false;
44 * This object must be passed the principal backend. This object will
45 * filter all principals from a specified prefix ($principalPrefix). The
46 * default is 'principals', if your principals are stored in a different
47 * collection, override $principalPrefix
50 * @param Sabre_DAVACL_IPrincipalBackend $principalBackend
51 * @param string $principalPrefix
53 public function __construct(Sabre_DAVACL_IPrincipalBackend $principalBackend, $principalPrefix = 'principals') {
55 $this->principalPrefix = $principalPrefix;
56 $this->principalBackend = $principalBackend;
61 * This method returns a node for a principal.
63 * The passed array contains principal information, and is guaranteed to
64 * at least contain a uri item. Other properties may or may not be
65 * supplied by the authentication backend.
67 * @param array $principalInfo
68 * @return Sabre_DAVACL_IPrincipal
70 abstract function getChildForPrincipal(array $principalInfo);
73 * Returns the name of this collection.
77 public function getName() {
79 list(,$name) = Sabre_DAV_URLUtil::splitPath($this->principalPrefix);
85 * Return the list of users
89 public function getChildren() {
91 if ($this->disableListing)
92 throw new Sabre_DAV_Exception_MethodNotAllowed('Listing members of this collection is disabled');
95 foreach($this->principalBackend->getPrincipalsByPrefix($this->principalPrefix) as $principalInfo) {
97 $children[] = $this->getChildForPrincipal($principalInfo);
106 * Returns a child object, by its name.
108 * @param string $name
109 * @throws Sabre_DAV_Exception_NotFound
110 * @return Sabre_DAVACL_IPrincipal
112 public function getChild($name) {
114 $principalInfo = $this->principalBackend->getPrincipalByPath($this->principalPrefix . '/' . $name);
115 if (!$principalInfo) throw new Sabre_DAV_Exception_NotFound('Principal with name ' . $name . ' not found');
116 return $this->getChildForPrincipal($principalInfo);
121 * This method is used to search for principals matching a set of
124 * This search is specifically used by RFC3744's principal-property-search
125 * REPORT. You should at least allow searching on
126 * http://sabredav.org/ns}email-address.
128 * The actual search should be a unicode-non-case-sensitive search. The
129 * keys in searchProperties are the WebDAV property names, while the values
130 * are the property values to search on.
132 * If multiple properties are being searched on, the search should be
135 * This method should simply return a list of 'child names', which may be
136 * used to call $this->getChild in the future.
138 * @param array $searchProperties
141 public function searchPrincipals(array $searchProperties) {
143 $result = $this->principalBackend->searchPrincipals($this->principalPrefix, $searchProperties);
146 foreach($result as $row) {
147 list(, $r[]) = Sabre_DAV_URLUtil::splitPath($row);