N°917: Fix TagSet search

This commit is contained in:
Pierre Goiffon
2018-09-27 15:20:37 +02:00
committed by Eric
parent 333c51b0f9
commit f55c0aa1c9
5 changed files with 64 additions and 65 deletions

View File

@@ -2045,7 +2045,7 @@ EOF
$sJson = $oAttDef->GetJsonForWidget($value, $aArgs);
$sEscapedJson = htmlentities($sJson, ENT_QUOTES, 'UTF-8');
$sSetInputName = "attr_{$sFormPrefix}{$sAttCode}";
$sHTMLValue = '<div class="field_input_zone field_input_set"><input id="'.$iId.'" name="'.$sSetInputName.'" type="hidden" value="'.$sEscapedJson.'"></div>'.$sValidationSpan.$sReloadSpan;
$sHTMLValue = '<div class="field_input_zone field_input_set"><input id="'.$iId.'" name="'.$sSetInputName.'" type="hidden" value="'.$sEscapedJson.'"></div>'.$sValidationSpan.$sReloadSpan;
$sScript = "$('#$iId').set_widget();";
$oPage->add_ready_script($sScript);
break;
@@ -3306,6 +3306,7 @@ EOF
{
$oSet = new ormSet(get_class($this), $sAttCode);
}
$oSet->SetValues($value['orig_value']);
$oSet->ApplyDelta($value);
$this->Set($sAttCode, $oSet);
break;

View File

@@ -137,38 +137,6 @@ class QueryOQL extends Query
return $aFieldsMap;
}
public function ComputeValues()
{
parent::ComputeValues();
// Remove unwanted attribute codes
$aChanges = $this->ListChanges();
if (isset($aChanges['fields']))
{
$oAttDef = MetaModel::GetAttributeDef(get_class($this), 'fields');
$aArgs = array('this' => $this);
$aAllowedValues = $oAttDef->GetAllowedValues($aArgs);
/** @var \ormSet $oValue */
$oValue = $this->Get('fields');
$aValues = $oValue->GetValues();
$bChanged = false;
foreach($aValues as $key => $sValue)
{
if (!isset($aAllowedValues[$sValue]))
{
unset($aValues[$key]);
$bChanged = true;
}
}
if ($bChanged)
{
$oValue->SetValues($aValues);
$this->Set('fields', $oValue);
}
}
}
}
?>

View File

@@ -124,6 +124,7 @@ abstract class AttributeDefinition
const SEARCH_WIDGET_TYPE_DATE_TIME = 'date_time';
const SEARCH_WIDGET_TYPE_DATE = 'date';
const SEARCH_WIDGET_TYPE_SET = 'set';
const SEARCH_WIDGET_TYPE_TAG_SET = 'tag_set';
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_RAW;
@@ -6766,6 +6767,9 @@ class AttributeExternalField extends AttributeDefinition
*/
class AttributeTagSet extends AttributeSet
{
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_TAG_SET;
public function __construct($sCode, array $aParams)
{
parent::__construct($sCode, $aParams);
@@ -10054,7 +10058,7 @@ class AttributeQueryAttCodeSet extends AttributeSet
{
if (isset($aAllowedAttributes[$sAttCode]))
{
$aLocalizedValues[] = '<span class="attribute-set-item" data-code="'.$sAttCode.'" data-label="'.$sAttCode.'" data-description="">'.$aAllowedAttributes[$sAttCode].'</span>';
$aLocalizedValues[] = '<span class="attribute-set-item" data-code="'.$sAttCode.'" data-label="'.$aAllowedAttributes[$sAttCode]." ($sAttCode)".'" data-description="">'.$aAllowedAttributes[$sAttCode].'</span>';
}
}
$value = $aLocalizedValues;

View File

@@ -495,37 +495,6 @@ class TriggerOnObjectUpdate extends TriggerOnObject
return false;
}
public function ComputeValues()
{
parent::ComputeValues();
// Remove unwanted attribute codes
$aChanges = $this->ListChanges();
if (isset($aChanges['target_attcodes']))
{
$oAttDef = MetaModel::GetAttributeDef(get_class($this), 'target_attcodes');
$aArgs = array('this' => $this);
$aAllowedValues = $oAttDef->GetAllowedValues($aArgs);
/** @var \ormSet $oValue */
$oValue = $this->Get('target_attcodes');
$aValues = $oValue->GetValues();
$bChanged = false;
foreach($aValues as $key => $sValue)
{
if (!isset($aAllowedValues[$sValue]))
{
unset($aValues[$key]);
$bChanged = true;
}
}
if ($bChanged)
{
$oValue->SetValues($aValues);
$this->Set('target_attcodes', $oValue);
}
}
}
}
/**

View File

@@ -72,6 +72,7 @@ class CriterionToSearchForm extends CriterionConversionAbstract
AttributeDefinition::SEARCH_WIDGET_TYPE_HIERARCHICAL_KEY => 'ExternalKeyToSearchForm',
AttributeDefinition::SEARCH_WIDGET_TYPE_ENUM => 'EnumToSearchForm',
AttributeDefinition::SEARCH_WIDGET_TYPE_SET => 'SetToSearchForm',
AttributeDefinition::SEARCH_WIDGET_TYPE_TAG_SET => 'TagSetToSearchForm',
);
foreach($aAndCriterionRaw as $aCriteria)
@@ -667,8 +668,64 @@ class CriterionToSearchForm extends CriterionConversionAbstract
return $aCriteria;
}
protected static function TagSetToSearchForm($aCriteria, $aFields)
{
$sOperator = $aCriteria['operator'];
switch ($sOperator)
{
case 'MATCHES':
// Nothing special to do
if (isset($aCriteria['has_undefined']) && $aCriteria['has_undefined'])
{
if (!isset($aCriteria['values']))
{
$aCriteria['values'] = array();
}
// Convention for 'undefined' tag set
$aCriteria['values'][] = array('value' => '', 'label' => Dict::S('Enum:Undefined'));
}
break;
case 'OR':
case 'ISNULL':
$aCriteria['operator'] = CriterionConversionAbstract::OP_EQUALS;
if (isset($aCriteria['has_undefined']) && $aCriteria['has_undefined'])
{
if (!isset($aCriteria['values']))
{
$aCriteria['values'] = array();
}
// Convention for 'undefined' tag set
$aCriteria['values'][] = array('value' => '', 'label' => Dict::S('Enum:Undefined'));
}
break;
case '=':
// TODO BUG SPLIT INTO AN 'AND' LIST OF MATCHES
$aCriteria['operator'] = CriterionConversionAbstract::OP_EQUALS;
if (isset($aCriteria['has_undefined']) && $aCriteria['has_undefined'])
{
if (!isset($aCriteria['values']))
{
$aCriteria['values'] = array();
}
// Convention for 'undefined' tag set
$aCriteria['values'][] = array('value' => '', 'label' => Dict::S('Enum:Undefined'));
}
break;
default:
// Unknown operator
$aCriteria['widget'] = AttributeDefinition::SEARCH_WIDGET_TYPE_RAW;
break;
}
return $aCriteria;
}
protected static function SetToSearchForm($aCriteria, $aFields)
{
// TODO New widget based on String but with match
$aCriteria['widget'] = AttributeDefinition::SEARCH_WIDGET_TYPE_RAW;
$sOperator = $aCriteria['operator'];
switch ($sOperator)
{