| 1 |
<?php |
| 2 |
|
| 3 |
namespace ImportWP\Common\Addon; |
| 4 |
|
| 5 |
class AddonDataApi |
| 6 |
{ |
| 7 |
protected $_addon; |
| 8 |
protected $_object_id; |
| 9 |
protected $_section_id; |
| 10 |
protected $_data; |
| 11 |
protected $_importer_model; |
| 12 |
protected $_template; |
| 13 |
|
| 14 |
/** |
| 15 |
* @param AddonBase $addon |
| 16 |
* @param string $object_id |
| 17 |
* @param string $section_id |
| 18 |
* @param string[] $data |
| 19 |
* @param ImporterModel $importer_model |
| 20 |
* @param \ImportWP\Common\Importer\Template\Template $template |
| 21 |
*/ |
| 22 |
public function __construct($addon, $object_id, $section_id, $data, $importer_model, $template) |
| 23 |
{ |
| 24 |
$this->_addon = $addon; |
| 25 |
$this->_object_id = $object_id; |
| 26 |
$this->_section_id = $section_id; |
| 27 |
$this->_data = $data; |
| 28 |
$this->_importer_model = $importer_model; |
| 29 |
$this->_template = $template; |
| 30 |
} |
| 31 |
|
| 32 |
public function addon() |
| 33 |
{ |
| 34 |
return $this->_addon; |
| 35 |
} |
| 36 |
|
| 37 |
public function object_id() |
| 38 |
{ |
| 39 |
return $this->_object_id; |
| 40 |
} |
| 41 |
|
| 42 |
public function section_id() |
| 43 |
{ |
| 44 |
return $this->_section_id; |
| 45 |
} |
| 46 |
|
| 47 |
public function data($key = false) |
| 48 |
{ |
| 49 |
if ($key) { |
| 50 |
return isset($this->_data[$key]) ? $this->_data[$key] : false; |
| 51 |
} |
| 52 |
return $this->_data; |
| 53 |
} |
| 54 |
|
| 55 |
public function importer_model() |
| 56 |
{ |
| 57 |
return $this->_importer_model; |
| 58 |
} |
| 59 |
|
| 60 |
public function template() |
| 61 |
{ |
| 62 |
return $this->_template; |
| 63 |
} |
| 64 |
|
| 65 |
public function get_mapper(){ |
| 66 |
return $this->template()->get_mapper(); |
| 67 |
} |
| 68 |
|
| 69 |
public function get_panel_id() |
| 70 |
{ |
| 71 |
return $this->section_id(); |
| 72 |
} |
| 73 |
|
| 74 |
public function get_meta($section_id = false) |
| 75 |
{ |
| 76 |
if ($section_id === false) { |
| 77 |
$section_id = $this->get_panel_id(); |
| 78 |
} |
| 79 |
|
| 80 |
return $this->addon()->get_meta($section_id); |
| 81 |
} |
| 82 |
|
| 83 |
public function store_meta($key, $value, $i = false) |
| 84 |
{ |
| 85 |
$this->addon()->store_meta($this->get_panel_id(), $this->object_id(), $key, $value, $i); |
| 86 |
} |
| 87 |
|
| 88 |
public function update_meta($key, $value, $is_unique = true) |
| 89 |
{ |
| 90 |
$this->addon()->update_meta($this->object_id(), $key, $value, $is_unique); |
| 91 |
} |
| 92 |
} |
| 93 |
|