lib/api lib/client lib/kolab_client_task.php
Aleksander Machniak
machniak at kolabsys.com
Mon Apr 9 17:59:12 CEST 2012
lib/api/kolab_api_service_form_value.php | 102 ++++++++++++++++---------
lib/api/kolab_api_service_roles.php | 2
lib/client/kolab_client_task_group.php | 3
lib/client/kolab_client_task_user.php | 3
lib/kolab_client_task.php | 123 +++++++------------------------
5 files changed, 98 insertions(+), 135 deletions(-)
New commits:
commit 0ff0e866114ef705b11e5dc196eba859f9a0dc37
Author: Aleksander Machniak <machniak at kolabsys.com>
Date: Mon Apr 9 17:58:25 2012 +0200
Move list options convertion to user-friendly values to the API
Fixed role attribute list "resolving"
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index 63c04d7..614bd18 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -516,21 +516,31 @@ class kolab_api_service_form_value extends kolab_api_service
private function list_options_kolabdelegate($postdata, $attribs = array())
{
- $service = $this->controller->get_service('users');
-
- $keyword = array('value' => $postdata['search']);
- $data = array(
- 'attributes' => array('displayname', 'mail'),
- 'page_size' => 15,
- 'search' => array(
+ // return specified records only, by exact DN attributes
+ if (!empty($postdata['list'])) {
+ $data['search'] = array(
+ 'entrydn' => array(
+ 'value' => $postdata['list'],
+ 'type' => 'exact',
+ ),
+ );
+ }
+ // return records with specified string
+ else {
+ $keyword = array('value' => $postdata['search']);
+ $data['page_size'] = 15;
+ $data['search'] = array(
'displayname' => $keyword,
'cn' => $keyword,
'mail' => $keyword,
- ),
- );
+ );
+ }
+
+ $data['attributes'] = array('displayname', 'mail');
- $result = $service->users_list(null, $data);
- $list = $result['list'];
+ $service = $this->controller->get_service('users');
+ $result = $service->users_list(null, $data);
+ $list = $result['list'];
// convert to key=>value array
foreach ($list as $idx => $value) {
@@ -556,21 +566,31 @@ class kolab_api_service_form_value extends kolab_api_service
private function list_options_nsroledn($postdata, $attribs = Array())
{
- $service = $this->controller->get_service('roles');
-
- $keyword = array('value' => $postdata['search']);
- $data = array(
- 'attributes' => array('cn'),
- 'page_size' => 15,
- 'search' => array(
+ // return specified records only, by exact DN attributes
+ if (!empty($postdata['list'])) {
+ $data['search'] = array(
+ 'entrydn' => array(
+ 'value' => $postdata['list'],
+ 'type' => 'exact',
+ ),
+ );
+ }
+ // return records with specified string
+ else {
+ $keyword = array('value' => $postdata['search']);
+ $data['page_size'] = 15;
+ $data['search'] = array(
'displayname' => $keyword,
'cn' => $keyword,
'mail' => $keyword,
- ),
- );
+ );
+ }
- $result = $service->roles_list(null, $data);
- $list = $result['list'];
+ $data['attributes'] = array('cn');
+
+ $service = $this->controller->get_service('roles');
+ $result = $service->roles_list(null, $data);
+ $list = $result['list'];
// convert to key=>value array
foreach ($list as $idx => $value) {
@@ -671,27 +691,37 @@ class kolab_api_service_form_value extends kolab_api_service
private function _list_options_members($postdata, $attribs = array())
{
- $service = $this->controller->get_service('users');
-
- $keyword = array('value' => $postdata['search']);
- $data = array(
- 'attributes' => array('displayname', 'cn', 'mail'),
- 'page_size' => 15,
- 'search' => array(
+ // return specified records only, by exact DN attributes
+ if (!empty($postdata['list'])) {
+ $data['search'] = array(
+ 'entrydn' => array(
+ 'value' => $postdata['list'],
+ 'type' => 'exact',
+ ),
+ );
+ }
+ // return records with specified string
+ else {
+ $keyword = array('value' => $postdata['search']);
+ $data['page_size'] = 15;
+ $data['search'] = array(
'displayname' => $keyword,
'cn' => $keyword,
'mail' => $keyword,
- ),
- );
+ );
+ }
- $result = $service->users_list(null, $data);
- $list = $result['list'];
+ $data['attributes'] = array('displayname', 'cn', 'mail');
+
+ $service = $this->controller->get_service('users');
+ $result = $service->users_list(null, $data);
+ $list = $result['list'];
- $service = $this->controller->get_service('groups');
$data['attributes'] = array('cn', 'mail');
- $result = $service->groups_list(null, $data);
- $list = array_merge($list, $result['list']);
+ $service = $this->controller->get_service('groups');
+ $result = $service->groups_list(null, $data);
+ $list = array_merge($list, $result['list']);
// convert to key=>value array
foreach ($list as $idx => $value) {
diff --git a/lib/api/kolab_api_service_roles.php b/lib/api/kolab_api_service_roles.php
index 1c9b8aa..7f67ab3 100644
--- a/lib/api/kolab_api_service_roles.php
+++ b/lib/api/kolab_api_service_roles.php
@@ -31,7 +31,7 @@ class kolab_api_service_roles extends kolab_api_service
public $list_attribs = array(
'cn',
'objectclass',
- 'dn',
+ 'entrydn',
'description',
);
diff --git a/lib/client/kolab_client_task_group.php b/lib/client/kolab_client_task_group.php
index d257129..402fabe 100644
--- a/lib/client/kolab_client_task_group.php
+++ b/lib/client/kolab_client_task_group.php
@@ -252,9 +252,6 @@ class kolab_client_task_group extends kolab_client_task
);
}
- // Prepare data of the form
- $this->form_data_prepare($fields, $data);
-
// Create form object and populate with fields
$form = $this->form_create('group', $attribs, $sections, $fields, $fields_map, $data, $add_mode);
diff --git a/lib/client/kolab_client_task_user.php b/lib/client/kolab_client_task_user.php
index 34ca6c2..e390868 100644
--- a/lib/client/kolab_client_task_user.php
+++ b/lib/client/kolab_client_task_user.php
@@ -313,9 +313,6 @@ class kolab_client_task_user extends kolab_client_task
);
}
- // Prepare data for the form
- $this->form_data_prepare($fields, $data);
-
// Create form object and populate with fields
$form = $this->form_create('user', $attribs, $sections, $fields, $fields_map, $data, $add_mode);
diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php
index a4cd924..53422e4 100644
--- a/lib/kolab_client_task.php
+++ b/lib/kolab_client_task.php
@@ -944,18 +944,41 @@ class kolab_client_task
// Add object type hidden field
$fields['object_type'] = array(
- 'section' => 'system',
- 'type' => kolab_form::INPUT_HIDDEN,
- 'value' => $name,
- );
+ 'section' => 'system',
+ 'type' => kolab_form::INPUT_HIDDEN,
+ 'value' => $name,
+ );
+
+ // Get user-friendly names for lists
+ foreach ($fields as $fname => $field) {
+ if (!empty($field['data-autocomplete']) && !empty($data[$fname])) {
+ if (!is_array($data[$fname])) {
+ $data[$fname] = (array) $data[$fname];
+ }
+
+ // request parameters
+ $post = array(
+ 'list' => $data[$fname],
+ 'attribute' => $fname,
+ 'object_type' => $name,
+ 'type_id' => $data['type_id'],
+ );
+
+ // get options list
+ $result = $this->api->post('form_value.list_options', null, $post);
+ $result = $result->get('list');
+
+ $data[$fname] = $result;
+ }
+ }
// Add entry identifier
if (!$add_mode) {
$fields['id'] = array(
- 'section' => 'system',
- 'type' => kolab_form::INPUT_HIDDEN,
- 'value' => $data['id']
- );
+ 'section' => 'system',
+ 'type' => kolab_form::INPUT_HIDDEN,
+ 'value' => $data['id']
+ );
}
return array($fields, $types, $type);
@@ -1117,89 +1140,5 @@ class kolab_client_task
return $form;
}
- /**
- * Resolves entries of common list fields into user-friendly form
- *
- * @param array $fields Form fields definition
- * @param array $data Form data
- */
- protected function form_data_prepare($fields, &$data)
- {
- // Roles (extract role names)
- $role_attrs = array('nsrole', 'nsroledn');
- foreach ($role_attrs as $ra) {
- if (!empty($fields[$ra]) && !empty($data[$ra])) {
- if (!is_array($data[$ra])) {
- $data[$ra] = (array) $data[$ra];
- }
- $data[$ra] = array_combine($data[$ra], $data[$ra]);
- foreach ($data[$ra] as $dn => $val) {
- // @TODO: maybe ldap_explode_dn() would be better?
- if (preg_match('/^cn=([^,]+)/i', $val, $m)) {
- $data[$ra][$dn] = $m[1];
- }
- }
- }
- }
-
- // Get user-friendly names for DN lists, e.g. kolabdelegate
- $list_attrs = array('kolabdelegate', 'member', 'uniquemember');
- foreach ($list_attrs as $la) {
- if (!empty($fields[$la]) && !empty($data[$la])) {
- if (!is_array($data[$la])) {
- $data[$la] = (array) $data[$la];
- }
-
- $search = array();
- foreach ($data[$la] as $key => $val) {
- $search[] = $val;
- }
-
- // request parameters
- $post = array(
- 'attributes' => array('displayname', 'cn', 'mail'),
- 'search' => array(
- 'entrydn' => array(
- 'value' => $search,
- 'type' => 'exact',
- ),
- ),
- 'search_operator' => 'OR',
- );
-
- // get users list
- $result = $this->api->post('users.list', null, $post);
- $result = $result->get('list');
- $list = array();
-
- if (is_array($result)) {
- foreach ($result as $key => $val) {
- $list[$key] = $val['displayname'] ? $val['displayname'] : $val['cn'];
- if ($val['mail']) {
- $list[$key] .= ' <' . $val['mail'] . '>';
- }
- }
- }
-
- // Search for groups too
- if (count($list) < count($search)) {
- // get groups list
- $result = $this->api->post('groups.list', null, $post);
- $result = $result->get('list');
-
- if (is_array($result)) {
- foreach ($result as $key => $val) {
- $list[$key] = $val['cn'];
- if ($val['mail']) {
- $list[$key] .= ' <' . $val['mail'] . '>';
- }
- }
- }
- }
-
- $data[$la] = $list;
- }
- }
- }
}
More information about the commits
mailing list