1: <?php
2: /**
3: * A Kolab domain maintainer.
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 associated to Kolab domain maintainers.
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_Domainmaintainer extends Horde_Kolab_Server_Object_Kolab_Adminrole
29: {
30:
31: const ATTRIBUTE_DOMAIN = 'domain';
32:
33: /**
34: * A structure to initialize the attribute structure for this class.
35: *
36: * @var array
37: */
38: static public $init_attributes = array(
39: 'defined' => array(
40: self::ATTRIBUTE_DOMAIN,
41: ),
42: );
43:
44: /**
45: * The group the UID must be member of so that this object really
46: * matches this class type. This may not include the root UID.
47: *
48: * @var array
49: */
50: public $required_group = array(self::ATTRIBUTE_CN => 'domain-maintainer',
51: Horde_Kolab_Server_Object_Kolabgroupofnames::ATTRIBUTE_VISIBILITY => false);
52:
53: /**
54: * Convert the object attributes to a hash.
55: *
56: * @param string $attrs The attributes to return.
57: *
58: * @return array|PEAR_Error The hash representing this object.
59: */
60: public function toHash($attrs = null)
61: {
62: if (!isset($attrs)) {
63: $attrs = array(
64: self::ATTRIBUTE_SID,
65: self::ATTRIBUTE_LNFN,
66: self::ATTRIBUTE_DOMAIN,
67: );
68: }
69: return parent::toHash($attrs);
70: }
71:
72: /**
73: * Distill the server side object information to save.
74: *
75: * @param array $info The information about the object.
76: *
77: * @return NULL.
78: *
79: * @throws Horde_Kolab_Server_Exception If the given information contains errors.
80: */
81: public function prepareObjectInformation(array &$info)
82: {
83: foreach ($info[self::ATTRIBUTE_DOMAIN] as $domain) {
84: $domain_uid = sprintf('cn=%s,cn=domain,cn=internal,%s',
85: $domain, $this->server->getBaseUid());
86:
87: //@todo: This should be made easier by the group object
88:
89: $domain_group = $this->server->fetch($domain_uid, 'Horde_Kolab_Server_Object_Kolabgroupofnames');
90: if ($domain_group instanceOf PEAR_Error) {
91: return $domain_group;
92: }
93: if (!$domain_group->exists()) {
94: $members = array($this->uid);
95: $domain_group->save(array(self::ATTRIBUTE_CN => $domain,
96: Horde_Kolab_Server_Object_Kolabgroupofnames::ATTRIBUTE_MEMBER => $members));
97: } else {
98: $result = $domain_group->isMember($this->uid);
99: if ($result instanceOf PEAR_Error) {
100: return $result;
101: }
102: if ($result === false) {
103: $members = $domain_group->getMembers();
104: $members[] = $this->uid;
105: $domain_group->save(array(Horde_Kolab_Server_Object_Kolabgroupofnames::ATTRIBUTE_MEMBER => $members));
106: }
107: }
108: }
109: parent::prepareObjectInformation(&$info);
110: }
111:
112: }
113: