| 1 |
<?php |
| 2 |
|
| 3 |
namespace ImportWP\Common\AddonAPI\Importer; |
| 4 |
|
| 5 |
use ImportWP\Common\Importer\ParsedData; |
| 6 |
|
| 7 |
class ImporterData |
| 8 |
{ |
| 9 |
private $_id; |
| 10 |
/** |
| 11 |
* @var ParsedData |
| 12 |
*/ |
| 13 |
private $_data; |
| 14 |
|
| 15 |
/** |
| 16 |
* @var \ImportWP\Common\AddonAPI\Importer\Template\Template |
| 17 |
*/ |
| 18 |
private $_addon_template; |
| 19 |
|
| 20 |
/** |
| 21 |
* @var \ImportWP\Common\Importer\Importer |
| 22 |
*/ |
| 23 |
private $_importer; |
| 24 |
|
| 25 |
/** |
| 26 |
* @var \ImportWP\Common\Importer\Template\Template |
| 27 |
*/ |
| 28 |
private $_template; |
| 29 |
|
| 30 |
private $_logs = []; |
| 31 |
|
| 32 |
/** |
| 33 |
* |
| 34 |
* @param int $id |
| 35 |
* @param \ImportWP\Common\Importer\ParsedData $data |
| 36 |
* @param \ImportWP\Common\AddonAPI\Importer\Template\Template $addon_template |
| 37 |
* @param \ImportWP\Common\Importer\Importer $importer |
| 38 |
* @param \ImportWP\Common\Importer\Template\Template $template |
| 39 |
* @return void |
| 40 |
*/ |
| 41 |
public function __construct($id, $data, $addon_template, $importer, $template) |
| 42 |
{ |
| 43 |
$this->_id = $id; |
| 44 |
$this->_data = $data; |
| 45 |
$this->_addon_template = $addon_template; |
| 46 |
$this->_importer = $importer; |
| 47 |
$this->_template = $template; |
| 48 |
} |
| 49 |
|
| 50 |
public function get_id() |
| 51 |
{ |
| 52 |
return $this->_id; |
| 53 |
} |
| 54 |
|
| 55 |
public function get_panel($panel_id) |
| 56 |
{ |
| 57 |
$panel = $this->_addon_template->get_panel($panel_id); |
| 58 |
return $panel ? new PanelData($panel, $this) : false; |
| 59 |
} |
| 60 |
|
| 61 |
public function get_custom_fields($custom_fields_id) |
| 62 |
{ |
| 63 |
foreach ($this->_addon_template->get_custom_fields() as $custom_fields) { |
| 64 |
if ($custom_fields_id == $custom_fields->get_prefix()) { |
| 65 |
return new CustomFieldsData($custom_fields, $this); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
return false; |
| 70 |
} |
| 71 |
|
| 72 |
public function process_attachment($id, $attachment_data) |
| 73 |
{ |
| 74 |
/** |
| 75 |
* @var ImportWP\Common\Filesystem\Filesystem $filesystem |
| 76 |
*/ |
| 77 |
$filesystem = \ImportWP\Container::getInstance()->get('filesystem'); |
| 78 |
|
| 79 |
/** |
| 80 |
* @var ImportWP\Common\Ftp\Ftp $ftp |
| 81 |
*/ |
| 82 |
$ftp = \ImportWP\Container::getInstance()->get('ftp'); |
| 83 |
|
| 84 |
/** |
| 85 |
* @var ImportWP\Common\Attachment\Attachment $attachment |
| 86 |
*/ |
| 87 |
$attachment = \ImportWP\Container::getInstance()->get('attachment'); |
| 88 |
|
| 89 |
return $this->_template->process_attachment($this->get_id(), $attachment_data, '', $filesystem, $ftp, $attachment); |
| 90 |
} |
| 91 |
|
| 92 |
public function add_meta($key, $value, $unique = false) |
| 93 |
{ |
| 94 |
switch ($this->_template->get_mapper()) { |
| 95 |
case 'user': |
| 96 |
$result = add_user_meta($this->get_id(), $key, $value, $unique); |
| 97 |
break; |
| 98 |
case 'term': |
| 99 |
$result = add_term_meta($this->get_id(), $key, $value, $unique); |
| 100 |
break; |
| 101 |
default: |
| 102 |
$result = add_post_meta($this->get_id(), $key, $value, $unique); |
| 103 |
break; |
| 104 |
} |
| 105 |
|
| 106 |
return $result; |
| 107 |
} |
| 108 |
|
| 109 |
public function update_meta($key, $value, $prev_value = '') |
| 110 |
{ |
| 111 |
switch ($this->_template->get_mapper()) { |
| 112 |
case 'user': |
| 113 |
$result = update_user_meta($this->get_id(), $key, $value, $prev_value); |
| 114 |
break; |
| 115 |
case 'term': |
| 116 |
$result = update_term_meta($this->get_id(), $key, $value, $prev_value); |
| 117 |
break; |
| 118 |
default: |
| 119 |
$result = update_post_meta($this->get_id(), $key, $value, $prev_value); |
| 120 |
break; |
| 121 |
} |
| 122 |
|
| 123 |
return $result; |
| 124 |
} |
| 125 |
|
| 126 |
public function delete_meta($key, $value = '') |
| 127 |
{ |
| 128 |
switch ($this->_template->get_mapper()) { |
| 129 |
case 'user': |
| 130 |
$result = delete_user_meta($this->get_id(), $key, $value, $value); |
| 131 |
break; |
| 132 |
case 'term': |
| 133 |
$result = delete_term_meta($this->get_id(), $key, $value, $value); |
| 134 |
break; |
| 135 |
default: |
| 136 |
$result = delete_post_meta($this->get_id(), $key, $value, $value); |
| 137 |
break; |
| 138 |
} |
| 139 |
|
| 140 |
return $result; |
| 141 |
} |
| 142 |
|
| 143 |
public function get_data() |
| 144 |
{ |
| 145 |
return $this->_data; |
| 146 |
} |
| 147 |
|
| 148 |
public function log($field_id, $group_id) |
| 149 |
{ |
| 150 |
if (!isset($this->_logs[$group_id])) { |
| 151 |
$this->_logs[$group_id] = []; |
| 152 |
} |
| 153 |
|
| 154 |
$this->_logs[$group_id][] = $field_id; |
| 155 |
} |
| 156 |
|
| 157 |
public function get_logs() |
| 158 |
{ |
| 159 |
return $this->_logs; |
| 160 |
} |
| 161 |
} |
| 162 |
|