diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index bc5f89520..5d5eefcaa 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -9851,16 +9851,16 @@ abstract class AttributeSet extends AttributeDBFieldVoid return 255; } - public function FromStringToArray($proposedValue) + public function FromStringToArray($proposedValue, $sDefaultSepItem = ',') { $aValues = array(); if (!empty($proposedValue)) { $sSepItem = MetaModel::GetConfig()->Get('tag_set_item_separator'); // convert also , separated strings - if ($sSepItem !== ',') + if ($sSepItem !== $sDefaultSepItem) { - $proposedValue = str_replace(',', $sSepItem, $proposedValue); + $proposedValue = str_replace($sDefaultSepItem, $sSepItem, $proposedValue); } foreach(explode($sSepItem, $proposedValue) as $sCode) { @@ -10138,7 +10138,6 @@ abstract class AttributeSet extends AttributeDBFieldVoid class AttributeEnumSet extends AttributeSet { const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_TAG_SET; - public static function ListExpectedParams() { return array_merge(parent::ListExpectedParams(), array('possible_values', 'is_null_allowed', 'max_items')); @@ -10354,6 +10353,38 @@ class AttributeEnumSet extends AttributeSet return $this->MakeRealValue($sProposedValue, null, false); } } + + /** + * @param string $proposedValue Search string used for MATCHES + * + * @param string $sDefaultSepItem word separator to extract items + * + * @return array of EnumSet codes + * @throws \Exception + */ + public function FromStringToArray($proposedValue, $sDefaultSepItem = ',') + { + $aValues = array(); + if (!empty($proposedValue)) + { + $sSepItem = MetaModel::GetConfig()->Get('tag_set_item_separator'); + // convert also other separators + if ($sSepItem !== $sDefaultSepItem) + { + $proposedValue = str_replace($sDefaultSepItem, $sSepItem, $proposedValue); + } + foreach(explode($sSepItem, $proposedValue) as $sCode) + { + $sValue = trim($sCode); + if (strlen($sValue) > 2) + { + $sLabel = $this->GetValueLabel($sValue); + $aValues[$sLabel] = $sValue; + } + } + } + return $aValues; + } } @@ -10875,7 +10906,7 @@ class AttributeTagSet extends AttributeSet return json_encode($aJson); } - public function FromStringToArray($proposedValue) + public function FromStringToArray($proposedValue, $sDefaultSepItem = ',') { $aValues = array(); if (!empty($proposedValue)) diff --git a/core/oql/expression.class.inc.php b/core/oql/expression.class.inc.php index 365177c97..600b78565 100644 --- a/core/oql/expression.class.inc.php +++ b/core/oql/expression.class.inc.php @@ -1127,7 +1127,7 @@ class ScalarExpression extends UnaryExpression { $oValue = $oAttDef->GetExistingTagsFromString($oValue, true); } - /** @var \ormTagSet $oValue */ + /** @var \ormTagSet $sValue */ $aTags = $oValue->GetTags(); foreach($aTags as $oTag) { @@ -1146,6 +1146,38 @@ class ScalarExpression extends UnaryExpression IssueLog::Error($e->getMessage()); } break; + case ($oAttDef instanceof AttributeEnumSet): + try + { + if (!empty($this->GetValue())) + { + $aValues = array(); + $sValue = $this->GetValue(); + if (is_string($sValue)) + { + $aTags = $oAttDef->FromStringToArray($sValue, ' '); + } + else + { + $aTags = array(); + } + foreach($aTags as $sLabel => $sValue) + { + $aValue['label'] = $sLabel; + $aValue['value'] = $sValue; + $aValues[] = $aValue; + } + $aCriterion['values'] = $aValues; + } + else + { + $aCriterion['has_undefined'] = true; + } + } catch (Exception $e) + { + IssueLog::Error($e->getMessage()); + } + break; case $oAttDef->IsExternalKey(): try { diff --git a/sources/application/search/criterionconversion/criteriontosearchform.class.inc.php b/sources/application/search/criterionconversion/criteriontosearchform.class.inc.php index b3e5b8d48..8399716e3 100644 --- a/sources/application/search/criterionconversion/criteriontosearchform.class.inc.php +++ b/sources/application/search/criterionconversion/criteriontosearchform.class.inc.php @@ -810,4 +810,4 @@ class CriterionToSearchForm extends CriterionConversionAbstract return $aCriteria; } -} \ No newline at end of file +}