| 1 |
<?php |
| 2 |
|
| 3 |
namespace ImportWP\Common\AddonAPI\Exporter; |
| 4 |
|
| 5 |
class FieldData |
| 6 |
{ |
| 7 |
private $_id; |
| 8 |
|
| 9 |
private $_value; |
| 10 |
|
| 11 |
private $_sub_fields = []; |
| 12 |
|
| 13 |
public function __construct($id, $value = null) |
| 14 |
{ |
| 15 |
$this->_id = $id; |
| 16 |
$this->set_value($value); |
| 17 |
} |
| 18 |
|
| 19 |
public function set_value($value, $suffix = null) |
| 20 |
{ |
| 21 |
if (!is_null($suffix)) { |
| 22 |
$this->_sub_fields[$suffix] = $value; |
| 23 |
} else { |
| 24 |
$this->_value = $value; |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
public function get_id() |
| 29 |
{ |
| 30 |
return $this->_id; |
| 31 |
} |
| 32 |
|
| 33 |
public function get_value() |
| 34 |
{ |
| 35 |
return $this->_value; |
| 36 |
} |
| 37 |
|
| 38 |
public function get_values() |
| 39 |
{ |
| 40 |
$tmp = [ |
| 41 |
$this->get_id() => $this->get_value(), |
| 42 |
]; |
| 43 |
|
| 44 |
if (empty($this->_sub_fields)) { |
| 45 |
return $tmp; |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
foreach ($this->_sub_fields as $suffix => $value) { |
| 50 |
$tmp[$this->get_id() . '::' . $suffix] = $value; |
| 51 |
} |
| 52 |
|
| 53 |
return $tmp; |
| 54 |
} |
| 55 |
} |
| 56 |
|