Commit f906b671 authored by Carsten  Rose's avatar Carsten Rose
Browse files

#3431 / typeAheadSql: columnname 'key' is a reserverd SQL statement - replace...

#3431 / typeAheadSql: columnname 'key' is a reserverd SQL statement - replace by 'id'. Additional the parametername 'typeAheadLdapKeyPrintf' renamed to 'typeAheadLdapIdPrintf'.
typeAhead.php: fixed typo.
TypeAhead.php: introduced new mapping from 'id' (SQL) to 'key' (API).
AbstractBuildForm.php: Constant renamed.
Database.php: update function makeArrayDict() to reflect name mapping.
parent 68db05cd
......@@ -831,9 +831,9 @@ of the *Form*. If LDAP access is:
+--------------------------+----------------------------------+------------------------------------------------------------+------+-------------+----------+
| typeAheadLdapSearch | `(|(cn=*?*)(mail=*?*))` | Regular LDAP search expresssion | x | x | TA |
+--------------------------+----------------------------------+------------------------------------------------------------+------+-------------+----------+
| typeAheadLdapValuePrintf | `'%s / %s', cn, email` | Custom format to disply attributes, as value | x | x | TA |
| typeAheadLdapValuePrintf | `'%s / %s', cn, email` | Custom format to display attributes, as `value` | x | x | TA |
+--------------------------+----------------------------------+------------------------------------------------------------+------+-------------+----------+
| typeAheadLdapKeyPrintf | `'%s', email` | Custom format to disply attributes, as key | x | x | TA |
| typeAheadLdapIdPrintf | `'%s', email` | Custom format to display attributes, as `id` | x | x | TA |
+--------------------------+----------------------------------+------------------------------------------------------------+------+-------------+----------+
| typeAheadLimit | 20 (default) | Result will be limited to this number of entries | x | x | TA |
+--------------------------+----------------------------------+------------------------------------------------------------+------+-------------+----------+
......@@ -862,14 +862,14 @@ The *FormElement.parameter*=*typeAheadLdap* will trigger LDAP searches on every
* *ldapBaseDn* = `ou=Addressbook,dc=example,dc=com`
* *typeAheadLdapSearch* = `(|(cn=*?*)(mail=*?*))`
* *typeAheadLdapValuePrintf* = `'%s / %s', cn, email`
* *typeAheadLdapKeyPrintf* = `'%s', email`
* *typeAheadLdapIdPrintf* = `'%s', email`
All fetched LDAP values will be formatted with:
* *typeAheadLdapValuePrintf*, shown to the user in a drop-down box and
* *typeAheadLdapKeyPrintf*, which represents the final data to save.
* *typeAheadLdapIdPrintf*, which represents the final data to save.
The `key/value` translation is compareable to a regular select drop-down box with key/value pairs.
Only attributes, defined in *typeAheadLdapValuePrintf* / *typeAheadLdapKeyPrintf* will be fetched from the LDAP directory.
The `id/value` translation is compareable to a regular select drop-down box with id/value pairs.
Only attributes, defined in *typeAheadLdapValuePrintf* / *typeAheadLdapIdPrintf* will be fetched from the LDAP directory.
To examine all possible values of an LDAP server, use the commandline tool `ldapsearch`. E.g.::
ldapsearch -x -h directory.example.com -L -b ou=Addressbook,dc=example,dc=com "(mail=john.doe@example.com)"
......@@ -1051,7 +1051,7 @@ parameter
+--------------------------+--------+----------------------------------------------------------------------------------------------------------+
| typeAheadLdapValuePrintf | string | Value formatting of LDAP result, per entry. E.g.: `'%s / %s / %s', mail, roomnumber, telephonenumber` |
+--------------------------+--------+----------------------------------------------------------------------------------------------------------+
| typeAheadLdapKeyPrintf | string | Key formatting of LDAP result, per entry. E.g.: `'%s', mail` |
| typeAheadLdapIdPrintf | string | Key formatting of LDAP result, per entry. E.g.: `'%s', mail` |
+--------------------------+--------+----------------------------------------------------------------------------------------------------------+
| typeAheadLimit | int | Maximum number of entries. The limit is applied to the server (LDAP or SQL) and the Client |
+--------------------------+--------+----------------------------------------------------------------------------------------------------------+
......@@ -1593,7 +1593,7 @@ the server, the lookup will be performed and the result, upto *typeAheadLimit* e
* *typeAheadLimit* = <number>. Max numbers of result records to be shown. Default is 20.
* *typeAheadMinLength* = <number>. Minimum length to type before the first lookup starts.
Depending of the `typeahead` setup, the given FormElement will contain the displayed `value` or `key` (if a key/value dict is
Depending of the `typeahead` setup, the given FormElement will contain the displayed `value` or `id` (if an id/value dict is
configured).
Configuration via Form / FormElement
......@@ -1607,10 +1607,10 @@ SQL
* *FormElement.parameter*:
* *typeAheadSql* = `SELECT ... AS 'key', ... AS 'value' WHERE name LIKE ? OR firstName LIKE ? LIMIT 100`
* *typeAheadSql* = `SELECT ... AS 'id', ... AS 'value' WHERE name LIKE ? OR firstName LIKE ? LIMIT 100`
* If there is only one column in the SELECT statement, that one will be used and there is no dict (key/value pair).
* If there is no column `key` or no column `value`, than the first column becomes `key` and the second column becomes `value`.
* If there is no column `id` or no column `value`, than the first column becomes `id` and the second column becomes `value`.
* The query will be fired as a 'prepared statement'.
* The value, typed by the user, will be replaced on all places where a `?` appears.
* All `?` will be automatically surrounded by '%'. Therefore wildcard search is implemented: `... LIKE '%<?>%' ...`
......@@ -2721,7 +2721,7 @@ Table: Person
# Typeahead
typeAheadLdapSearch = (|(cn=*?*)(mail=*?*))
typeAheadLdapValuePrintf ‘%s / %s’, cn, email
typeAheadLdapKeyPrintf ‘%s’, email
typeAheadLdapIdPrintf ‘%s’, email
# dynamicUpdate: show note
fillStoreLdap
......
......@@ -9,6 +9,12 @@ Version 0.future
Changes
^^^^^^^
* Play formEditor.sql.
* #3431, Parameter keyword 'typeAheadLdapKeyPrintf' changed to 'typeAheadLdapIdPrintf'.::
UPDATE FormElement SET parameter = REPLACE(parameter, 'typeAheadLdapKeyPrintf', 'typeAheadLdapIdPrintf')
Features
^^^^^^^^
......
......@@ -26,7 +26,7 @@ try {
} catch (\Exception $e) {
// $answer[API_MESSAGE] = "Generic Exception: " . $e->getMessage();
$answer[] = [API_TYPEAHEAD_KEY => 'errror', API_TYPEAHEAD_VALUE => "Error: " . $e->getMessage()];
$answer[] = [API_TYPEAHEAD_KEY => 'Error', API_TYPEAHEAD_VALUE => "Error: " . $e->getMessage()];
}
header("Content-Type: application/json");
......
......@@ -431,7 +431,6 @@ abstract class AbstractBuildForm {
$storeUse = str_replace(STORE_TABLE_DEFAULT, '', $storeUse); // Remove STORE_DEFAULT
}
$value = $this->store->getVar($name, $storeUse, $formElement['checkType']);
}
// Typically: $htmlElementNameIdZero = true
......@@ -439,7 +438,6 @@ abstract class AbstractBuildForm {
$htmlFormElementName = HelperFormElement::buildFormElementName($formElement[FE_NAME], ($htmlElementNameIdZero) ? 0 : $recordId);
$formElement[FE_HTML_ID] = HelperFormElement::buildFormElementId($this->formSpec[F_ID], $formElement[FE_ID], ($htmlElementNameIdZero) ? 0 : $recordId, 0);
// Construct Marshaller Name: buildElement
$buildElementFunctionName = 'build' . $this->buildElementFunctionName[$formElement[FE_TYPE]];
......@@ -499,7 +497,7 @@ abstract class AbstractBuildForm {
if (isset($formElement[FE_FILL_STORE_LDAP]) || isset($formElement[FE_TYPEAHEAD_LDAP])) {
$keyNames = [F_LDAP_SERVER, F_LDAP_BASE_DN, F_LDAP_ATTRIBUTES, F_LDAP_SEARCH, F_TYPEAHEAD_LDAP_SEARCH, F_TYPEAHEAD_LIMIT,
F_TYPEAHEAD_MINLENGTH, F_TYPEAHEAD_LDAP_VALUE_PRINTF, F_TYPEAHEAD_LDAP_KEY_PRINTF, F_LDAP_TIME_LIMIT];
F_TYPEAHEAD_MINLENGTH, F_TYPEAHEAD_LDAP_VALUE_PRINTF, F_TYPEAHEAD_LDAP_ID_PRINTF, F_LDAP_TIME_LIMIT];
$formElement = OnArray::copyArrayItemsIfNotAlreadyExist($this->formSpec, $formElement, $keyNames);
} else {
return $formElement; // nothing to do.
......@@ -772,7 +770,6 @@ abstract class AbstractBuildForm {
* [maxlength="$maxLength"] [placeholder="$placeholder"] [size="$size"] [min="$min"] [max="$max"]
* [pattern="$pattern"] [required="required"] [disabled="disabled"] value="$value">
*
*
* @param array $formElement
* @param string $htmlFormElementName
* @param string $value
......
......@@ -394,6 +394,7 @@ const MODE_DB_NO_LOG = 'noLog';
const TYPEAHEAD_API_QUERY = 'query'; // Name of parameter in API call of typeahead.php?query=...&s=... - See also FE_TYPE_AHEAD_SQL
const TYPEAHEAD_API_SIP = 'sip'; // Name of parameter in API call of typeahead.php?query=...&s=...
const TYPEAHEAD_DEFAULT_LIMIT = 20;
const TYPEAHEAD_SQL_KEY_NAME = 'id';
const DEFAULT_LDAP_TIME_LIMIT = 3;
......@@ -562,7 +563,7 @@ const F_LDAP_TIME_LIMIT = 'ldapTimeLimit';
const F_TYPEAHEAD_LIMIT = 'typeAheadLimit';
const F_TYPEAHEAD_MINLENGTH = 'typeAheadMinLength';
const F_TYPEAHEAD_LDAP_VALUE_PRINTF = 'typeAheadLdapValuePrintf';
const F_TYPEAHEAD_LDAP_KEY_PRINTF = 'typeAheadLdapKeyPrintf';
const F_TYPEAHEAD_LDAP_ID_PRINTF = 'typeAheadLdapIdPrintf';
const F_TYPEAHEAD_LDAP_SEARCH = 'typeAheadLdapSearch';
// FORM_ELEMENT_STATI
......@@ -654,7 +655,7 @@ const FE_TYPEAHEAD_LIMIT = F_TYPEAHEAD_LIMIT;
const FE_TYPEAHEAD_MINLENGTH = F_TYPEAHEAD_MINLENGTH;
const FE_TYPEAHEAD_SQL = 'typeAheadSql';
const FE_TYPEAHEAD_LDAP_VALUE_PRINTF = F_TYPEAHEAD_LDAP_VALUE_PRINTF;
const FE_TYPEAHEAD_LDAP_KEY_PRINTF = F_TYPEAHEAD_LDAP_KEY_PRINTF;
const FE_TYPEAHEAD_LDAP_KEY_PRINTF = F_TYPEAHEAD_LDAP_ID_PRINTF;
const FE_TYPEAHEAD_LDAP = 'typeAheadLdap';
const FE_TYPEAHEAD_LDAP_SEARCH = F_TYPEAHEAD_LDAP_SEARCH;
const FE_FILL_STORE_LDAP = 'fillStoreLdap';
......
......@@ -690,18 +690,27 @@ class Database {
/**
* $arr will be converted to a two column array with keys $keyName1 and $keyName2.
* $arr might be one column or more columns.
* $arr might contain one or more columns.
* Only when $keyName1 and $keyName2 exist, those will be used. Else the first column becomes $keyName1 and the second becomes $keyName2.
* If there is only one column, that column will be doubled.
*
* @param array $arr
* @param string $keyName1
* @param string $keyName2
* @param string $srcColumn1
* @param string $srcColumn2
* @param string $destColumn1
* @param string $destColumn2
* @return array
*/
public function makeArrayDict(array $arr, $keyName1, $keyName2) {
$keyName = 0;
$valueName = 1;
public function makeArrayDict(array $arr, $srcColumn1, $srcColumn2, $destColumn1 = '', $destColumn2 = '') {
if ($destColumn1 == '') {
$destColumn1 = $srcColumn1;
}
if ($destColumn2 == '') {
$destColumn2 = $srcColumn2;
}
$new = array();
if ($arr == array() || $arr === null) {
......@@ -711,19 +720,19 @@ class Database {
$row = $arr[0];
$keys = array_keys($row);
if (count($row) < 2) {
$keyName = $keys[0];
$valueName = $keys[0];
} elseif (array_key_exists($keyName1, $row) && array_key_exists($keyName2, $row)) {
$keyName = $keyName1;
$valueName = $keyName2;
$column1 = $keys[0];
$column2 = $keys[0];
} elseif (array_key_exists($srcColumn1, $row) && array_key_exists($srcColumn2, $row)) {
$column1 = $srcColumn1;
$column2 = $srcColumn2;
} else {
$keyName = $keys[0];
$valueName = $keys[1];
$column1 = $keys[0];
$column2 = $keys[1];
}
$row = array_shift($arr);
while (null !== $row) {
$new[] = [$keyName1 => $row[$keyName], $keyName2 => $row[$valueName]];
$new[] = [$destColumn1 => $row[$column1], $destColumn2 => $row[$column2]];
$row = array_shift($arr);
}
......
......@@ -109,7 +109,7 @@ class TypeAhead {
return array();
}
return $this->db->makeArrayDict($arr, API_TYPEAHEAD_KEY, API_TYPEAHEAD_VALUE);
return $this->db->makeArrayDict($arr, TYPEAHEAD_SQL_KEY_NAME, API_TYPEAHEAD_VALUE, API_TYPEAHEAD_KEY, API_TYPEAHEAD_VALUE);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment