1: <?php
2: /**
3: * An organizational person (objectclass 2.5.6.7).
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 for the organizationalPerson objectclass.
16: *
17: * Copyright 2009-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_Organizationalperson extends Horde_Kolab_Server_Object_Person
29: {
30: /** Define attributes specific to this object type */
31:
32: /** The postal address */
33: const ATTRIBUTE_POSTALADDRESS = 'postalAddress';
34:
35: /** The job title */
36: const ATTRIBUTE_JOBTITLE = 'title';
37:
38: /** The street address */
39: const ATTRIBUTE_STREET = 'street';
40:
41: /** The post office box */
42: const ATTRIBUTE_POSTOFFICEBOX = 'postOfficeBox';
43:
44: /** The postal code */
45: const ATTRIBUTE_POSTALCODE = 'postalCode';
46:
47: /** The city */
48: const ATTRIBUTE_CITY = 'l';
49:
50: /** The fax number */
51: const ATTRIBUTE_FAX = 'facsimileTelephoneNumber';
52:
53: /** The specific object class of this object type */
54: const OBJECTCLASS_ORGANIZATIONALPERSON = 'organizationalPerson';
55:
56: /**
57: * A structure to initialize the attribute structure for this class.
58: *
59: * @var array
60: */
61: /* static public $init_attributes = array( */
62: /* 'defined' => array( */
63: /* self::ATTRIBUTE_JOBTITLE, */
64: /* self::ATTRIBUTE_STREET, */
65: /* self::ATTRIBUTE_POSTOFFICEBOX, */
66: /* self::ATTRIBUTE_POSTALCODE, */
67: /* self::ATTRIBUTE_CITY, */
68: /* self::ATTRIBUTE_FAX, */
69: /* self::ATTRIBUTE_POSTALADDRESS, */
70: /* ), */
71: /* 'collapsed' => array( */
72: /* self::ATTRIBUTE_POSTALADDRESS => array( */
73: /* 'base' => array( */
74: /* self::ATTRIBUTE_SN, */
75: /* self::ATTRIBUTE_STREET, */
76: /* self::ATTRIBUTE_POSTOFFICEBOX, */
77: /* self::ATTRIBUTE_POSTALCODE, */
78: /* self::ATTRIBUTE_CITY, */
79: /* ), */
80: /* 'method' => 'setPostalAddress', */
81: /* ), */
82: /* ), */
83: /* 'object_classes' => array( */
84: /* self::OBJECTCLASS_ORGANIZATIONALPERSON, */
85: /* ), */
86: /* ); */
87:
88: /**
89: * Return the filter string to retrieve this object type.
90: *
91: * @static
92: *
93: * @return string The filter to retrieve this object type from the server
94: * database.
95: */
96: public static function getFilter()
97: {
98: $criteria = array('AND' => array(array('field' => self::ATTRIBUTE_OC,
99: 'op' => '=',
100: 'test' => self::OBJECTCLASS_ORGANIZATIONALPERSON),
101: ),
102: );
103: return $criteria;
104: }
105:
106: /**
107: * Set the complete postal address.
108: *
109: * @param string $key The attribute to collapse into.
110: * @param array $attributes The attributes to collapse.
111: * @param array &$info The information currently working on.
112: *
113: * @return NULL.
114: */
115: protected function setPostalAddress($key, $attributes, &$info)
116: {
117: $empty = true;
118: $postal_data = array();
119: foreach ($attributes as $attribute) {
120: if (isset($info[$attribute])) {
121: if (is_array($info[$attribute])) {
122: $new = $info[$attribute][0];
123: } else {
124: $new = $info[$attribute];
125: }
126: $postal_data[$attribute] = $this->quote($new);
127: $empty = false;
128: } else {
129: $old = $this->get($attribute, true);
130: if (!empty($old)) {
131: $postal_data[$attribute] = $old;
132: $empty = false;
133: } else {
134: $postal_data[$attribute] = '';
135: }
136: }
137: }
138:
139: if ($empty === true) {
140: return;
141: }
142:
143: if (!empty($postal_data[self::ATTRIBUTE_POSTOFFICEBOX])) {
144: $postal_data['street_segment'] = $postal_data[self::ATTRIBUTE_POSTOFFICEBOX];
145: } else {
146: $postal_data['street_segment'] = $postal_data[self::ATTRIBUTE_STREET];
147: }
148:
149: $info[$key] = sprintf('%s$%s$%s %s',
150: $postal_data[self::ATTRIBUTE_SN],
151: $postal_data['street_segment'],
152: $postal_data[self::ATTRIBUTE_POSTALCODE],
153: $postal_data[self::ATTRIBUTE_CITY]);
154: }
155:
156: }