diff --git a/application/ui.extkeywidget.class.inc.php b/application/ui.extkeywidget.class.inc.php index ba67ea3a8..780ed999c 100644 --- a/application/ui.extkeywidget.class.inc.php +++ b/application/ui.extkeywidget.class.inc.php @@ -437,7 +437,20 @@ EOF if (empty($sOperation) || 'equals_start_with' == $sOperation) { - $aValues = $oValuesSet->GetValues(array('this' => $oObj, 'current_extkey_id' => $iCurrentExtKeyId), $sContains, 'equals_start_with'); + $aValues = $oValuesSet->GetValues(array('this' => $oObj, 'current_extkey_id' => $iCurrentExtKeyId), $sContains, 'equals'); + asort($aValues); + + $iMax -= count($aValues); + if ($iMax > 0 ) { + $oValuesSet->SetLimit($iMax); + $aValuesStartWith = $oValuesSet->GetValues(array('this' => $oObj, 'current_extkey_id' => $iCurrentExtKeyId), $sContains, 'start_with'); + asort($aValuesStartWith); + foreach ($aValuesStartWith as $sKey => $sFriendlyName) { + if (!isset($aValues[$sKey])) { + $aValues[$sKey] = $sFriendlyName; + } + } + } } else { @@ -462,9 +475,15 @@ EOF switch($sOutputFormat) { case static::ENUM_OUTPUT_FORMAT_JSON: - // Array flip to preserve values order on the label, otherwise the JS will re-order regarding the keys. - $oP->SetContentType('application/json'); - $oP->add(json_encode(array_flip($aValues))); + + $aJsonMap = array(); + foreach ($aValues as $sKey => $sLabel) + { + $aJsonMap[] = array('value' => $sKey, 'label' => $sLabel); + } + + $oP->SetContentType('application/json'); + $oP->add(json_encode($aJsonMap)); break; case static::ENUM_OUTPUT_FORMAT_CSV: diff --git a/core/valuesetdef.class.inc.php b/core/valuesetdef.class.inc.php index 9e71ae3f9..855507104 100644 --- a/core/valuesetdef.class.inc.php +++ b/core/valuesetdef.class.inc.php @@ -230,33 +230,38 @@ class ValueSetObjects extends ValueSetDefinition switch ($sOperation) { - case 'equals_start_with': + case 'equals': $aAttributes = MetaModel::GetFriendlyNameAttributeCodeList($oFilter->GetClass()); $sClassAlias = $oFilter->GetClassAlias(); $aFilters = array(); - // Equals first $oValueExpr = new ScalarExpression($sContains); foreach($aAttributes as $sAttribute) { $oNewFilter = $oFilter->DeepClone(); $oNameExpr = new FieldExpression($sAttribute, $sClassAlias); - $oCondition = new BinaryExpression($oNameExpr, 'LIKE', $oValueExpr); + $oCondition = new BinaryExpression($oNameExpr, '=', $oValueExpr); $oNewFilter->AddConditionExpression($oCondition); $aFilters[] = $oNewFilter; } - // start with next - $oValueExpr = new ScalarExpression($sContains.'%'); - foreach($aAttributes as $sAttribute) - { - $oNewFilter = $oFilter->DeepClone(); - $oNameExpr = new FieldExpression($sAttribute, $sClassAlias); - $oCondition = new BinaryExpression($oNameExpr, 'LIKE', $oValueExpr); - $oNewFilter->AddConditionExpression($oCondition); - $aFilters[] = $oNewFilter; - } - // Unions are much faster than OR conditions + // Unions are much faster than OR conditions $oFilter = new DBUnionSearch($aFilters); break; + case 'start_with': + $aAttributes = MetaModel::GetFriendlyNameAttributeCodeList($oFilter->GetClass()); + $sClassAlias = $oFilter->GetClassAlias(); + $aFilters = array(); + $oValueExpr = new ScalarExpression($sContains.'%'); + foreach($aAttributes as $sAttribute) + { + $oNewFilter = $oFilter->DeepClone(); + $oNameExpr = new FieldExpression($sAttribute, $sClassAlias); + $oCondition = new BinaryExpression($oNameExpr, 'LIKE', $oValueExpr); + $oNewFilter->AddConditionExpression($oCondition); + $aFilters[] = $oNewFilter; + } + // Unions are much faster than OR conditions + $oFilter = new DBUnionSearch($aFilters); + break; default: $oValueExpr = new ScalarExpression('%'.$sContains.'%'); diff --git a/js/search/search_form_criteria_enum.js b/js/search/search_form_criteria_enum.js index e932d5594..6b04589de 100644 --- a/js/search/search_form_criteria_enum.js +++ b/js/search/search_form_criteria_enum.js @@ -609,9 +609,10 @@ $(function() if(Object.keys(oResponse).length > 0) { // Note: Response is indexed by labels from server so the JSON is always ordered on decoding. - for(var sLabel in oResponse) + for(var skey in oResponse) { - var sValue = oResponse[sLabel]; + var sValue = oResponse[skey].value; + var sLabel = oResponse[skey].label; // Note: We don't use the _isSelectedValue() method here as it only returns "applied" values; at this moment will could have a checked value that is not among selected (me.options.values) yet. The result would be an hidden item from the AC results. var bSelected = (this.element.find(this._getSelectedValuesWrapperSelector() + ' .sfc_opc_mc_item[data-value-code="' + sValue + '"]').length > 0); var bInitChecked = bSelected; @@ -636,9 +637,10 @@ $(function() if(Object.keys(oResponse).length > 0) { // Note: Response is indexed by labels from server so the JSON is always ordered on decoding. - for(var sLabel in oResponse) + for(var skey in oResponse) { - var sValue = oResponse[sLabel]; + var sValue = oResponse[skey].value; + var sLabel = oResponse[skey].label; // Note: We don't use the _isSelectedValue() method here as it only returns "applied" values; at this moment will could have a checked value that is not among selected (me.options.values) yet. The result would be an hidden item from the AC results. var bSelected = (this.element.find(this._getSelectedValuesWrapperSelector() + ' .sfc_opc_mc_item[data-value-code="' + sValue + '"]').length > 0); var bInitChecked = bSelected;