diff options
author | Aleksander Machniak <machniak@kolabsys.com> | 2012-03-30 09:10:04 +0200 |
---|---|---|
committer | Aleksander Machniak <machniak@kolabsys.com> | 2012-03-30 09:10:04 +0200 |
commit | c93bfc52f643eb0c4ab77663a26e86823f597bec (patch) | |
tree | d8abb1f199a2f225a47191aae37b84e68be62099 /lib | |
parent | 73e01fe5af2dcebed7dbe2a712994f233df1e935 (diff) | |
download | webadmin-c93bfc52f643eb0c4ab77663a26e86823f597bec.tar.gz |
Group type ID detection (#660)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/kolab_api_service_group.php | 3 | ||||
-rw-r--r-- | lib/api/kolab_api_service_user.php | 2 | ||||
-rw-r--r-- | lib/kolab_api_service.php | 25 |
3 files changed, 22 insertions, 8 deletions
diff --git a/lib/api/kolab_api_service_group.php b/lib/api/kolab_api_service_group.php index f382d79..c1decaf 100644 --- a/lib/api/kolab_api_service_group.php +++ b/lib/api/kolab_api_service_group.php @@ -149,6 +149,9 @@ class kolab_api_service_group extends kolab_api_service $result = $result[$dn]; $result['entrydn'] = $dn; + // add group type id to the result + $result['group_type_id'] = $this->object_type_id('group', $result['objectclass']); + if ($result) { return $result; } diff --git a/lib/api/kolab_api_service_user.php b/lib/api/kolab_api_service_user.php index 8c60d33..fea9f9d 100644 --- a/lib/api/kolab_api_service_user.php +++ b/lib/api/kolab_api_service_user.php @@ -154,7 +154,7 @@ class kolab_api_service_user extends kolab_api_service $result['entrydn'] = $dn; // add user type id to the result - $result['user_type_id'] = $this->user_type_id($result['objectclass']); + $result['user_type_id'] = $this->object_type_id('user', $result['objectclass']); // Search for attributes associated with the type_id that are not part // of the results returned earlier. Example: nsrole / nsroledn / aci, etc. diff --git a/lib/kolab_api_service.php b/lib/kolab_api_service.php index 03c273e..8c41e30 100644 --- a/lib/kolab_api_service.php +++ b/lib/kolab_api_service.php @@ -103,28 +103,39 @@ abstract class kolab_api_service } /** - * Detects user type ID for specified objectClass attribute value + * Detects object type ID for specified objectClass attribute value * - * @param array $object_class Value of objectClass attribute + * @param string $object_name Name of the object (user, group, etc.) + * @param array $object_class Value of objectClass attribute * - * @return int User type identifier + * @return int Object type identifier */ - protected function user_type_id($object_class) + protected function object_type_id($object_name, $object_class) { if (empty($object_class)) { return null; } + $method = $object_name . '_types'; + + if (!method_exists($this, $method)) { + return null; + } + $object_class = array_map('strtolower', $object_class); - $user_types = $this->user_types(); + $object_types = $this->$method(); $type_score = -1; $type_id = null; console("Data objectClasses: " . implode(", ", $object_class)); - foreach ($user_types as $idx => $elem) { + foreach ($object_types as $idx => $elem) { $ref_class = $elem['attributes']['fields']['objectclass']; + if (empty($ref_class)) { + continue; + } + console("Reference objectclasses for " . $elem['key'] . ": " . implode(", ", $ref_class)); // Eliminate the duplicates between the $data_ocs and $ref_ocs @@ -137,7 +148,7 @@ abstract class kolab_api_service // console("\$object_class not in \$ref_class (" . $elem['key'] . "): " . implode(", ", $_object_class)); // console("\$ref_class not in \$object_class (" . $elem['key'] . "): " . implode(", ", $_ref_class)); - console("Score for user type " . $elem['name'] . ": " . $elem_score . "(" . $commonalities . "/" . $differences . ")"); + console("Score for $object_name type " . $elem['name'] . ": " . $elem_score . "(" . $commonalities . "/" . $differences . ")"); if ($elem_score > $type_score) { $type_id = $idx; |