mudando o mapeamento da entidade de lugar

This commit is contained in:
Leo Germani 2017-11-08 13:52:41 -02:00
parent 33e86ece1d
commit a0200dcf86
3 changed files with 20 additions and 19 deletions

View File

@ -10,9 +10,10 @@ if ( ! defined( 'ABSPATH' ) ) {
class TainacanCollection extends Entity {
function __construct($which = 0) {
$this->repository = 'TainacanCollections';
if (is_numeric($which) && $which > 0) {
$post = get_post($which);
if ($post instanceof WP_Post) {
@ -26,21 +27,7 @@ class TainacanCollection extends Entity {
}
}
function map_properties() {
return [
'ID' => 'ID',
'name' => 'post_title',
'order' => 'menu_order',
'parent' => 'parent',
'description' => 'post_content',
'itens_per_page' => 'meta'
];
}
// Getters
//
function get_id() {

View File

@ -3,14 +3,19 @@
class Entity {
var $repository;
function get_mapped_property($prop) {
global ${$this->repository};
$map = ${$this->repository}->map;
if (isset($this->$prop) && !empty($this->$prop))
return $this->$prop;
$map = $this->map_properties();
//$map = $this->map_properties();
if (!array_key_exists($prop, $map))
return null;
@ -33,6 +38,6 @@ class Entity {
}
}

View File

@ -10,6 +10,15 @@ class TainacanCollections {
const POST_TYPE = 'tainacan-collections';
const DB_IDENTIFIER_META = '_db_identifier';
var $map = [
'ID' => 'ID',
'name' => 'post_title',
'order' => 'menu_order',
'parent' => 'parent',
'description' => 'post_content',
'itens_per_page' => 'meta'
];
function __construct() {
add_action('init', array(&$this, 'register_post_type'));
}
@ -52,7 +61,7 @@ class TainacanCollections {
function insert(TainacanCollection $collection) {
// First iterate through the native post properties
$map = $collection->map_properties();
$map = $this->map;
foreach ($map as $prop => $mapped) {
if ($mapped != 'meta') {
$collection->WP_Post->$mapped = $collection->get_mapped_property($prop);