Commit 181bc6d8 authored by ZZZ[GONE] frebault's avatar ZZZ[GONE] frebault
Browse files

modify fields for extended fields

parent bd984d2f
......@@ -2,6 +2,7 @@
namespace GGUSHelpdesk;
use GGUSHelpdesk\Exceptions\InvalidFieldException;
use GGUSHelpdesk\ExtendedFields\ArrayObjectFactory;
/**
......@@ -17,24 +18,47 @@ class Fields extends ArrayFields
private $cMap;
private $xmlKeyList;
private $xmlFieldIndex;
private $extendedFieldsIndex;
private $extendedFieldsFactory;
public function __construct(array $cMap, array $xmlKeyList = array(), \ArrayObject $arrayObject)
public function __construct(array $cMap, array $xmlKeyList = array())
{
$this->cMap = $cMap;
$this->xmlKeyList = $xmlKeyList;
$this->xmlFieldIndex = array();
if (isset($this->cMap[self::FIELD_ID])) {
$this->xmlFieldIndex = $this->cMap[self::FIELD_ID];
$this[$this->xmlFieldIndex] = new $arrayObject($this->xmlKeyList);
$this->extendedFieldsIndex = array();
parent::__construct();
}
// public function init()
// {
// }
public function setExtendedFields($index = self::FIELD_ID)
{
if (isset($this->cMap[$index])) {
$this->setExtendedFieldsFactory(new ArrayObjectFactory());
$this->extendedFieldsIndex = $this->cMap[$index];
$this->setXmlFieldsString($this->xmlKeyList);
}
}
parent::__construct();
/*
* $entriesHydrator = new EntriesHydrator();
$dataEntry = $entriesHydrator->hydrate($data);
*/
public function setXmlFieldsString($data)
{
$this[$this->extendedFieldsIndex] = $this->extendedFieldsFactory->createInstanceFromFieldsList($data);
}
public function init()
public function getXmlField()
{
return $this->extendedFieldsFactory->creatInstanceFromString($this[$this->extendedFieldsIndex]);
}
public function setExtendedFieldsFactory(\ArrayObject $factory){
$this->extendedFieldsFactory = $factory;
}
// return map where field name is found, null otherwise
......@@ -64,7 +88,7 @@ class Fields extends ArrayFields
if ($map === self::MAP_TYPE_C) {
$this[$this->cMap[$name]] = $value;
} else {
$this[$this->xmlFieldIndex][$name] = $value;
$this[$this->extendedFieldsIndex][$name] = $value;
}
}
}
......@@ -81,7 +105,7 @@ class Fields extends ArrayFields
} else {
if ($map === self::MAP_TYPE_C) {
if (self::FIELD_ID === $name) {
return $this[$this->xmlFieldIndex]->serialize();
return $this[$this->extendedFieldsIndex]->serialize();
} else {
if (isset($this[$this->cMap[$name]])) {
return $this[$this->cMap[$name]];
......@@ -93,8 +117,8 @@ class Fields extends ArrayFields
}
} else {
if (isset($this[$this->xmlFieldIndex][$name])) {
return $this[$this->xmlFieldIndex][$name];
if (isset($this[$this->extendedFieldsIndex][$name])) {
return $this[$this->extendedFieldsIndex][$name];
} else {
if ($safe === false) {
throw new InvalidFieldException("Undefined '$name' field");
......@@ -110,8 +134,8 @@ class Fields extends ArrayFields
{
$output = $this->getData();
if (isset($this->xmlFieldIndex)) {
$output[$this->xmlFieldIndex] = $this[$this->xmlFieldIndex]->serialize();
if (isset($this->extendedFieldsIndex)) {
$output[$this->extendedFieldsIndex] = $this[$this->extendedFieldsIndex]->serialize();
}
return $output;
}
......@@ -125,8 +149,8 @@ class Fields extends ArrayFields
// make xmlFields as a flat array
foreach ($this->xmlKeyList as $xIdx => $path) {
try {
if(isset($this[$this->xmlFieldIndex][$xIdx])) {
$xValue = $this[$this->xmlFieldIndex][$xIdx];
if(isset($this[$this->extendedFieldsIndex][$xIdx])) {
$xValue = $this[$this->extendedFieldsIndex][$xIdx];
}
else {
$xValue = 'N.A.';
......@@ -147,18 +171,4 @@ class Fields extends ArrayFields
return $output;
}
/*
* $entriesHydrator = new EntriesHydrator();
$dataEntry = $entriesHydrator->hydrate($data);
*/
public function setXmlFieldsString($data)
{
$this[$this->xmlFieldIndex] = $data;
}
public function getXmlField()
{
return $this[$this->xmlFieldIndex];
}
}
\ No newline at end of file
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