mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°1150 AtributeCustomFields : FromJSONToValue is now delegated to the handler
Method was always returning null before
This commit is contained in:
@@ -35,10 +35,11 @@ class ormCustomFieldsValue
|
||||
* _template_name: string,
|
||||
* template_id: string,
|
||||
* template_data: string,
|
||||
* user_data: string,
|
||||
* user_data: array<string, mixed>,
|
||||
* current_template_id: string,
|
||||
* current_template_data: string,
|
||||
* } $aCurrentValues Containing JSON encoded strings in template_data/current_template_data, user_data.
|
||||
* } $aCurrentValues Containing JSON encoded strings in template_data/current_template_data.
|
||||
* The user_data key contains an array with field code as key and field value as value
|
||||
* Warning, current_* are mandatory for data to be saved in a DBUpdate() call !
|
||||
*/
|
||||
protected $aCurrentValues;
|
||||
@@ -48,13 +49,31 @@ class ormCustomFieldsValue
|
||||
* @param string $sAttCode
|
||||
* @param array $aCurrentValues
|
||||
*/
|
||||
public function __construct(DBObject $oHostObject, $sAttCode, $aCurrentValues = null)
|
||||
public function __construct(?DBObject $oHostObject, $sAttCode, $aCurrentValues = null)
|
||||
{
|
||||
$this->oHostObject = $oHostObject;
|
||||
$this->sAttCode = $sAttCode;
|
||||
$this->aCurrentValues = $aCurrentValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DBObject|null
|
||||
*/
|
||||
public function GetHostObject(): ?DBObject
|
||||
{
|
||||
return $this->oHostObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DBObject|null $oHostObject
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function SetHostObject(?DBObject $oHostObject): void
|
||||
{
|
||||
$this->oHostObject = $oHostObject;
|
||||
}
|
||||
|
||||
public function GetValues()
|
||||
{
|
||||
return $this->aCurrentValues;
|
||||
@@ -62,6 +81,7 @@ class ormCustomFieldsValue
|
||||
|
||||
/**
|
||||
* Wrapper used when the only thing you have is the value...
|
||||
*
|
||||
* @return \Combodo\iTop\Form\Form
|
||||
*/
|
||||
public function GetForm($sFormPrefix = null)
|
||||
@@ -96,6 +116,19 @@ class ormCustomFieldsValue
|
||||
return $this->GetHandler()->GetAsJSON($this->aCurrentValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $json
|
||||
* @param \AttributeDefinition $oAttDef
|
||||
*
|
||||
* @return \ormCustomFieldsValue
|
||||
*
|
||||
* @since 3.1.0 N°1150 Method creation
|
||||
*/
|
||||
public static function FromJSONToValue(?stdClass $json, AttributeCustomFields $oAttDef)
|
||||
{
|
||||
return $oAttDef->GetHandler()->FromJSONToValue($json, $oAttDef->GetCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \CustomFieldsHandler
|
||||
* @throws \Exception
|
||||
@@ -103,6 +136,7 @@ class ormCustomFieldsValue
|
||||
*/
|
||||
final protected function GetHandler()
|
||||
{
|
||||
/** @var \AttributeCustomFields $oAttDef */
|
||||
$oAttDef = MetaModel::GetAttributeDef(get_class($this->oHostObject), $this->sAttCode);
|
||||
|
||||
return $oAttDef->GetHandler($this->GetValues());
|
||||
|
||||
Reference in New Issue
Block a user