summaryrefslogtreecommitdiffstats
path: root/lib/kolab_api_service.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/kolab_api_service.php')
-rw-r--r--lib/kolab_api_service.php73
1 files changed, 73 insertions, 0 deletions
diff --git a/lib/kolab_api_service.php b/lib/kolab_api_service.php
index 5d144ff..8630cbe 100644
--- a/lib/kolab_api_service.php
+++ b/lib/kolab_api_service.php
@@ -107,4 +107,77 @@ abstract class kolab_api_service
return $uta;
}
+ /**
+ * Detects user type ID for specified objectClass attribute value
+ *
+ * @param array $object_class Value of objectClass attribute
+ *
+ * @return int User type identifier
+ */
+ protected function user_type_id($object_class)
+ {
+ if (empty($object_class)) {
+ return null;
+ }
+
+ $object_class = array_map('strtolower', $object_class);
+ $user_types = $this->user_types();
+ $type_score = -1;
+ $type_id = null;
+
+ console("Data objectClasses: " . implode(", ", $object_class));
+
+ foreach ($user_types as $idx => $elem) {
+ $ref_class = $elem['attributes']['fields']['objectclass'];
+
+ console("Reference objectclasses for " . $elem['key'] . ": " . implode(", ", $ref_class));
+
+ // Eliminate the duplicates between the $data_ocs and $ref_ocs
+ $_object_class = array_diff($object_class, $ref_class);
+ $_ref_class = array_diff($ref_class, $object_class);
+
+ $differences = count($_object_class) + count($_ref_class);
+ $commonalities = count($object_class) - $differences;
+ $elem_score = $differences > 0 ? ($commonalities / $differences) : $commonalities;
+
+// 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 . ")");
+
+ if ($elem_score > $type_score) {
+ $type_id = $idx;
+ $type_score = $elem_score;
+ }
+ }
+
+ return $type_id;
+ }
+
+ /**
+ * Returns user types definitions.
+ *
+ * @return array User types.
+ */
+ protected function user_types()
+ {
+ $sql_result = $this->db->query("SELECT * FROM user_types");
+ $user_types = array();
+
+ while ($row = $this->db->fetch_assoc($sql_result)) {
+ $user_types[$row['id']] = array();
+
+ foreach ($row as $key => $value) {
+ if ($key != "id") {
+ if ($key == "attributes") {
+ $user_types[$row['id']][$key] = json_decode(unserialize($value), true);
+ }
+ else {
+ $user_types[$row['id']][$key] = $value;
+ }
+ }
+ }
+ }
+
+ return $user_types;
+ }
}