1: <?php
2: /**
3: * A Kolab object of type administrator.
4: *
5: * PHP version 5
6: *
7: * @category Kolab
8: * @package Kolab_Server
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_Server
12: */
13:
14: /**
15: * This class provides methods to deal with administrator object types.
16: *
17: * Copyright 2008-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_Server
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_Server
27: */
28: class Horde_Kolab_Server_Object_Kolab_Adminrole extends Horde_Kolab_Server_Object_Kolabinetorgperson
29: {
30:
31: static public $init_attributes = array(
32: );
33:
34: /**
35: * The group the UID must be member of so that this object really
36: * matches this class type. This may not include the root UID.
37: *
38: * @var string
39: */
40: public $required_group;
41:
42: /**
43: * Return the filter string to retrieve this object type.
44: *
45: * @return string The filter to retrieve this object type from the server
46: * database.
47: */
48: public static function getFilter()
49: {
50: if (isset($conf['kolab']['server']['params']['admin'][self::ATTRIBUTE_SID])) {
51: $manager = $conf['kolab']['server']['params']['admin'][self::ATTRIBUTE_SID];
52: } else {
53: $manager = 'manager';
54: }
55:
56: $criteria = array('AND' => array(
57: array('field' => self::ATTRIBUTE_CN,
58: 'op' => 'any'),
59: array('field' => self::ATTRIBUTE_SN,
60: 'op' => 'any'),
61: array('field' => self::ATTRIBUTE_OC,
62: 'op' => '=',
63: 'test' => self::OBJECTCLASS_INETORGPERSON),
64: array('NOT' => array(
65: array('field' => self::ATTRIBUTE_SID,
66: 'op' => '=',
67: 'test' => $manager),
68: ),
69: ),
70: ),
71: );
72: return $criteria;
73: }
74:
75: /**
76: * Saves object information.
77: *
78: * @param array $info The information about the object.
79: *
80: * @return boolean|PEAR_Error True on success.
81: */
82: public function save(array $info)
83: {
84: $admin_group = new Horde_Kolab_Server_Object_Kolabgroupofnames($this->server, null, $this->required_group);
85:
86: $save_result = parent::save($info);
87:
88: if (!$admin_group->exists()) {
89: $data = array_merge($this->required_group,
90: array(Horde_Kolab_Server_Object_Kolabgroupofnames::ATTRIBUTE_MEMBER => array($this->uid)));
91: } else {
92: $result = $admin_group->isMember($this->uid);
93: if ($result === false) {
94: $members = $admin_group->getMembers();
95: $members[] = $this->uid;
96: $data = array(Horde_Kolab_Server_Object_Kolabgroupofnames::ATTRIBUTE_MEMBER => $members);
97: } else {
98: $data = null;
99: }
100: }
101: if (!empty($data)) {
102: return $admin_group->save($data);
103: }
104: return $save_result;
105: }
106: }
107: