3 commits - lib/api lib/SQL.php
Aleksander Machniak
machniak at kolabsys.com
Wed Sep 26 08:56:10 CEST 2012
lib/SQL.php | 5 +
lib/api/kolab_api_service_form_value.php | 23 +++++
lib/api/kolab_api_service_type.php | 128 ++++++++++++++++++++++---------
3 files changed, 118 insertions(+), 38 deletions(-)
New commits:
commit 6e50c6786ed16bdeaa9b2a6ff51f42c63978d278
Author: Aleksander Machniak <alec at alec.pl>
Date: Wed Sep 26 08:55:39 2012 +0200
Implemented type.add and type.edit
diff --git a/lib/api/kolab_api_service_type.php b/lib/api/kolab_api_service_type.php
index 4b71080..429df7b 100644
--- a/lib/api/kolab_api_service_type.php
+++ b/lib/api/kolab_api_service_type.php
@@ -24,7 +24,7 @@
*/
/**
- * Service providing user data management
+ * Service providing object types management
*/
class kolab_api_service_type extends kolab_api_service
{
@@ -50,35 +50,64 @@ class kolab_api_service_type extends kolab_api_service
$rights['edit'] = "w";
}
+ $rights['info'] = "r";
$rights['effective_rights'] = "r";
return $rights;
}
/**
- * Create user.
+ * Create type.
*
- * @param array $get GET parameters
- * @param array $post POST parameters
+ * @param array $get GET parameters
+ * @param array $post POST parameters
*
- * @return array|bool User attributes or False on error.
+ * @return array|bool Type attributes or False on error.
*/
public function type_add($getdata, $postdata)
{
- //console("type_add()", $postdata);
+ if (!in_array($postdata['type'], $this->supported_types_db)) {
+ return false;
+ }
+
+ if (empty($postdata['name']) || empty($postdata['key'])) {
+ return false;
+ }
+
+ if (empty($postdata['attributes']) || !is_array($postdata['attributes'])) {
+ return false;
+ }
+
+ // @TODO: check privileges
- $type_attributes = $this->parse_input_attributes('type', $postdata);
+ $type = $postdata['type'];
+ $query = array(
+ 'key' => $postdata['key'],
+ 'name' => $postdata['name'],
+ 'description' => $postdata['description'] ? $postdata['description'] : '',
+ 'attributes' => json_encode($postdata['attributes']),
+ );
- //console("type_add()", $type_attributes);
+ if ($postdata['type'] == 'user') {
+ $query['used_for'] = $postdata['used_for'] == 'hosted' ? 'hosted' : null;
+ }
-// $auth = Auth::get_instance();
-// $result = $auth->type_add($type_attributes, $postdata['type_id']);
+ $query = array_map(array($this->db, 'escape'), $query);
- if ($result) {
- return $type_attributes;
+ $this->db->query("INSERT INTO {$type}_types"
+ . " (" . implode(',', array_keys($query)) . ")"
+ . " VALUES (" . implode(',', $query) . ")");
+
+ if (!($id = $this->db->last_insert_id())) {
+ return false;
}
- return false;
+ // update cache
+ $this->cache['object_types'][$type][$id] = $postdata;
+
+ $postdata['id'] = $id;
+
+ return $postdata;
}
/**
@@ -102,6 +131,8 @@ class kolab_api_service_type extends kolab_api_service
$object_name = $postdata['type'];
$object_id = $postdata['id'];
+ // @TODO: check privileges
+
$this->db->query("DELETE FROM {$object_name}_types WHERE id = ?", array($object_id));
return (bool) $this->db->affected_rows();
@@ -117,21 +148,49 @@ class kolab_api_service_type extends kolab_api_service
*/
public function type_edit($getdata, $postdata)
{
- //console("\$postdata to type_edit()", $postdata);
+ if (empty($postdata['type']) || empty($postdata['id'])) {
+ return false;
+ }
+
+ if (empty($postdata['name']) || empty($postdata['key'])) {
+ return false;
+ }
+
+ if (empty($postdata['attributes']) || !is_array($postdata['attributes'])) {
+ return false;
+ }
- $type_attributes = $this->parse_input_attributes('type', $postdata);
- $type = $postdata['id'];
+ // @TODO: check privileges
-// $auth = Auth::get_instance();
-// $result = $auth->type_edit($type, $type_attributes, $postdata['type_id']);
+ $type = $postdata['type'];
+ $query = array(
+ 'key' => $postdata['key'],
+ 'name' => $postdata['name'],
+ 'description' => $postdata['description'] ? $postdata['description'] : '',
+ 'attributes' => json_encode($postdata['attributes']),
+ );
- // Return the $mod_array
- if ($result) {
- return $result;
+ if ($postdata['type'] == 'user') {
+ $query['used_for'] = $postdata['used_for'] == 'hosted' ? 'hosted' : null;
}
- return false;
+ foreach ($query as $idx => $value) {
+ $query[$idx] = $idx . " = " . $this->db->escape($value);
+ }
+ $this->db->query("UPDATE {$type}_types SET "
+ . implode(', ', $query) . " WHERE id = ?", array($postdata['id']));
+
+ if (!($id = $this->db->last_insert_id())) {
+ return false;
+ }
+
+ // update cache
+ $this->cache['object_types'][$type][$id] = $postdata;
+
+ $postdata['id'] = $id;
+
+ return $postdata;
}
public function type_effective_rights($getdata, $postdata)
@@ -143,32 +202,27 @@ class kolab_api_service_type extends kolab_api_service
}
/**
- * User information.
+ * Type information.
*
* @param array $get GET parameters
* @param array $post POST parameters
*
- * @return array|bool User attributes, False on error
+ * @return array|bool Type data, False on error
*/
public function type_info($getdata, $postdata)
{
- if (!isset($getdata['type'])) {
+ if (empty($getdata['type']) || empty($getdata['id'])) {
return false;
}
-// $auth = Auth::get_instance();
-// $result = $auth->type_info($getdata['type']);
-
-// Log::trace("type.info on " . $getdata['type'] . " result: " . var_export($result, TRUE));
- // normalize result
-// $result = $this->parse_result_attributes('type', $result);
-
-// Log::trace("type.info on " . $getdata['type'] . " parsed result: " . var_export($result, TRUE));
-
- if ($result) {
- return $result;
+ if (!in_array($getdata['type'], $this->supported_types_db)) {
+ return false;
}
- return false;
+ $object_name = $getdata['type'];
+ $object_id = $getdata['id'];
+ $types = $this->object_types($object_name);
+
+ return !empty($types[$object_id]) ? $types[$object_id] : false;
}
}
commit 3b6c7567e7475b328d7112d47f2e7a950eec992e
Author: Aleksander Machniak <alec at alec.pl>
Date: Tue Sep 25 13:58:41 2012 +0200
Added select_options_objectclass() method, @TODO: get objectclasses from LDAP
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index 4d90d68..22cc294 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -153,7 +153,6 @@ class kolab_api_service_form_value extends kolab_api_service
public function select_options($getdata, $postdata)
{
//console("form_value.select_options postdata", $postdata);
-
$attribs = $this->object_type_attributes($postdata['object_type'], $postdata['type_id']);
$attributes = (array) $postdata['attributes'];
$result = array();
@@ -764,6 +763,28 @@ class kolab_api_service_form_value extends kolab_api_service
return $this->_select_options_from_db('c');
}
+ private function select_options_objectclass($postdata, $attribs = array())
+ {
+ // @TODO: get list from LDAP
+ // @TODO: filter by object type?
+ $classes = array(
+ 'groupofuniquenames',
+ 'inetorgperson',
+ 'kolabgroupofuniquenames',
+ 'kolabinetorgperson',
+ 'kolabsharedfolder',
+ 'mailrecipient',
+ 'organizationalperson',
+ 'organizationalunit',
+ 'person',
+ 'posixaccount',
+ 'posixgroup',
+ 'top',
+ );
+
+ return $classes;
+ }
+
private function select_options_ou($postdata, $attribs = array())
{
$auth = Auth::get_instance();
commit 149e2b11e2377789bd6d20b463d0cf3e941b04a7
Author: Aleksander Machniak <alec at alec.pl>
Date: Tue Sep 25 10:42:23 2012 +0200
Added last_insert_id() method
diff --git a/lib/SQL.php b/lib/SQL.php
index d5b6737..129a090 100644
--- a/lib/SQL.php
+++ b/lib/SQL.php
@@ -103,6 +103,11 @@ class SQL
return mysql_affected_rows($this->conn);
}
+ public function last_insert_id()
+ {
+ return mysql_insert_id($this->conn);
+ }
+
public function escape($str)
{
if ($str === null || is_array($str)) {
More information about the commits
mailing list