Overview

Packages

  • Group

Classes

  • Horde_Group_Base
  • Horde_Group_Contactlists
  • Horde_Group_Exception
  • Horde_Group_Kolab
  • Horde_Group_Ldap
  • Horde_Group_Mock
  • Horde_Group_Sql
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * This class provides a driver for the Horde group system based on Turba
  4:  * contact lists.
  5:  *
  6:  * Copyright 2008-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * See the enclosed file COPYING for license information (LGPL). If you
  9:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 10:  *
 11:  * @author   Michael J. Rubinsky <mrubinsk@horde.org>
 12:  * @author   Jan Schneider <jan@horde.org>
 13:  * @category Horde
 14:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 15:  * @package  Group
 16:  */
 17: class Horde_Group_Contactlists extends Horde_Group_Base
 18: {
 19:     /**
 20:      * API object.
 21:      *
 22:      * @var Horde_Registry_Caller
 23:      */
 24:     protected $_api;
 25: 
 26:     /**
 27:      * True if we are inside a listAll() call.
 28:      *
 29:      * This is used to protect against infinite recursion when the contacts API
 30:      * is using groups to determine the available contact lists.
 31:      *
 32:      * @var boolean
 33:      */
 34:     protected $_inListAll = false;
 35: 
 36:     /**
 37:      * True if we are inside a listGroups() call.
 38:      *
 39:      * This is used to protect against infinite recursion when the contacts API
 40:      * is using groups to determine the available contact lists.
 41:      *
 42:      * @var boolean
 43:      */
 44:     protected $_inListGroups = false;
 45: 
 46:     /**
 47:      * Constructor.
 48:      */
 49:     public function __construct($params)
 50:     {
 51:         if (!isset($params['api'])) {
 52:             throw new Horde_Group_Exception('The \'api\' parameter is missing.');
 53:         }
 54:         $this->_api = $params['api'];
 55:     }
 56: 
 57:     /**
 58:      * Checks if a group exists.
 59:      *
 60:      * @param mixed $gid  A group ID.
 61:      *
 62:      * @return boolean  True if the group exists.
 63:      * @throws Horde_Group_Exception
 64:      */
 65:     public function exists($gid)
 66:     {
 67:         try {
 68:             return (bool)$this->_api->getGroupObject($gid);
 69:         } catch (Horde_Exception $e) {
 70:             throw new Horde_Group_Exception($e);
 71:         }
 72:     }
 73: 
 74:     /**
 75:      * Returns a group name.
 76:      *
 77:      * @param mixed $gid  A group ID.
 78:      *
 79:      * @return string  The group's name.
 80:      * @throws Horde_Group_Exception
 81:      * @throws Horde_Exception_NotFound
 82:      */
 83:     public function getName($gid)
 84:     {
 85:         $group = $this->getData($gid);
 86:         return $group['name'];
 87:     }
 88: 
 89:     /**
 90:      * Returns all available attributes of a group.
 91:      *
 92:      * @param mixed $gid  A group ID.
 93:      *
 94:      * @return array  The group's date.
 95:      * @throws Horde_Group_Exception
 96:      * @throws Horde_Exception_NotFound
 97:      */
 98:     public function getData($gid)
 99:     {
100:         try {
101:             $group = $this->_api->getGroupObject($gid);
102:         } catch (Horde_Exception $e) {
103:             throw new Horde_Group_Exception($e);
104:         }
105:         if (!$group) {
106:             throw new Horde_Exception_NotFound('Group "' . $gid . '" not found');
107:         }
108:         return $group;
109:     }
110: 
111:     /**
112:      * Returns a list of all groups a user may see, with IDs as keys and names
113:      * as values.
114:      *
115:      * @param string $member  Only return groups that this user is a member of.
116:      *
117:      * @return array  All existing groups.
118:      * @throws Horde_Group_Exception
119:      */
120:     public function listAll($member = null)
121:     {
122:         if ($this->_inListAll) {
123:             return array();
124:         }
125:         $this->_inListAll = true;
126: 
127:         $list = array();
128:         try {
129:             foreach ($this->_api->getGroupObjects() as $id => $group) {
130:                 $list[$id] = $group['name'];
131:             }
132:         } catch (Horde_Exception $e) {
133:             $this->_inListAll = false;
134:             throw new Horde_Group_Exception($e);
135:         }
136: 
137:         if (!is_null($member)) {
138:             $list = array_intersect_assoc($list, $this->listGroups($member));
139:         }
140: 
141:         $this->_inListAll = false;
142:         return $list;
143:     }
144: 
145:     /**
146:      * Returns a list of users in a group.
147:      *
148:      * @param mixed $gid  A group ID.
149:      *
150:      * @return array  List of group users.
151:      * @throws Horde_Group_Exception
152:      * @throws Horde_Exception_NotFound
153:      */
154:     public function listUsers($gid)
155:     {
156:         try {
157:             return $this->_api->getGroupMembers($gid);
158:         } catch (Horde_Exception $e) {
159:             throw new Horde_Group_Exception($e);
160:         }
161:     }
162: 
163:     /**
164:      * Returns a list of groups a user belongs to.
165:      *
166:      * @param string $user  A user name.
167:      *
168:      * @return array  A list of groups, with IDs as keys and names as values.
169:      * @throws Horde_Group_Exception
170:      */
171:     public function listGroups($user)
172:     {
173:         if ($this->_inListGroups) {
174:             return array();
175:         }
176:         $this->_inListGroups = true;
177:         try {
178:             $groups = $this->_api->getGroupMemberships($user);
179:         } catch (Horde_Exception $e) {
180:             $this->_inListGroups = false;
181:             throw new Horde_Group_Exception($e);
182:         }
183:         $this->_inListGroups = false;
184:         return $groups;
185:     }
186: 
187:     /**
188:      * Searches for group names.
189:      *
190:      * @param string $name  A search string.
191:      *
192:      * @return array  A list of matching groups, with IDs as keys and names as
193:      *                values.
194:      * @throws Horde_Group_Exception
195:      */
196:     public function search($name)
197:     {
198:     }
199: }
200: 
API documentation generated by ApiGen