7 * @license http://www.gnu.org/licenses/agpl.html AGPL3
8 * @copyright Copyright (c) 2008-2014 Metaways Infosystems GmbH (http://www.metaways.de)
9 * @author Lars Kneschke <l.kneschke@metaways.de>
11 * @todo add search count function
15 * abstract class for all group backends
21 abstract class Tinebase_Group_Abstract
28 protected $_classCache = array ();
31 * return all groups an account is member of
33 * @param mixed $_accountId the account as integer or Tinebase_Model_User
36 abstract public function getGroupMemberships($_accountId);
39 * get list of groupmembers
41 * @param int $_groupId
44 abstract public function getGroupMembers($_groupId);
47 * replace all current groupmembers with the new groupmembers list
49 * @param int $_groupId
50 * @param array $_groupMembers
53 abstract public function setGroupMembers($_groupId, $_groupMembers);
56 * add a new groupmember to the group
58 * @param int $_groupId
59 * @param int $_accountId
62 abstract public function addGroupMember($_groupId, $_accountId);
65 * remove one groupmember from the group
67 * @param int $_groupId
68 * @param int $_accountId
71 abstract public function removeGroupMember($_groupId, $_accountId);
77 * @return Tinebase_Group_Sql
79 public function resetClassCache($key = null)
81 foreach ($this->_classCache as $cacheKey => $cacheValue) {
82 if ($key === null || $key === $cacheKey) {
83 $this->_classCache[$cacheKey] = array();
93 * @param string $_groupName
96 abstract public function addGroup(Tinebase_Model_Group $_group);
99 * updates an existing group
101 * @param Tinebase_Model_Group $_account
102 * @return Tinebase_Model_Group
104 abstract public function updateGroup(Tinebase_Model_Group $_group);
109 * @param mixed $_groupId
112 abstract public function deleteGroups($_groupId);
117 * @param int $_groupId
118 * @return Tinebase_Model_Group
119 * @throws Tinebase_Exception_Record_NotDefined
121 abstract public function getGroupById($_groupId);
126 * @param string $_groupName
127 * @return Tinebase_Model_Group
128 * @throws Tinebase_Exception_Record_NotDefined
130 abstract public function getGroupByName($_groupName);
135 * @return Tinebase_Model_Group
137 public function getDefaultGroup()
139 return $this->_getDefaultGroup('Users');
143 * get default admin group
145 * @return Tinebase_Model_Group
147 public function getDefaultAdminGroup()
149 return $this->_getDefaultGroup('Administrators');
153 * Get multiple groups
155 * @param string|array $_ids Ids
156 * @return Tinebase_Record_RecordSet
158 abstract public function getMultiple($_ids);
163 * @param string $_filter
164 * @param string $_sort
165 * @param string $_dir
168 * @return Tinebase_Record_RecordSet with record class Tinebase_Model_Group
170 abstract public function getGroups($_filter = NULL, $_sort = 'name', $_dir = 'ASC', $_start = NULL, $_limit = NULL);
173 * get default group for users/admins
175 * @param string $_name group name (Users|Administrators)
176 * @return unknown_type
178 protected function _getDefaultGroup($_name = 'Users')
180 if (! in_array($_name, array('Users', 'Administrators'))) {
181 throw new Tinebase_Exception_InvalidArgument('Wrong group name: ' . $_name);
184 $configKey = ($_name == 'Users') ? Tinebase_User::DEFAULT_USER_GROUP_NAME_KEY : Tinebase_User::DEFAULT_ADMIN_GROUP_NAME_KEY;
185 $defaultGroupName = Tinebase_User::getBackendConfiguration($configKey);
186 if (empty($defaultGroupName)) {
187 Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' ' . $configKey . ' not found. Check your user backend configuration.');
188 $defaultGroupName = $_name;
192 $result = $this->getGroupByName($defaultGroupName);
193 } catch (Tinebase_Exception_Record_NotDefined $tenf) {
194 // create group on the fly
195 $result = $this->addGroup(new Tinebase_Model_Group(array(
196 'name' => $defaultGroupName,
204 * get dummy group record
206 * @param integer $_id [optional]
207 * @return Tinebase_Model_Group
209 public function getNonExistentGroup($_id = NULL)
211 $translate = Tinebase_Translation::getTranslation('Tinebase');
213 $result = new Tinebase_Model_Group(array(
215 'name' => $translate->_('unknown'),