Merge branch 'feature/compount-metadata-type-refactor' of https://github.com/tainacan/tainacan into feature/compount-metadata-type-refactor

This commit is contained in:
mateuswetah 2020-03-18 18:03:32 -03:00
commit 6207f2b276
3 changed files with 14 additions and 9 deletions

View File

@ -255,11 +255,7 @@ class REST_Items_Controller extends REST_Controller {
}
// \error_log("DEBUG-1:");
// \error_log(\json_encode($item_arr));
$item_arr = apply_filters('tainacan-api-items-prepare-for-response', $item_arr, $item, $request);
// \error_log("DEBUG-2:");
// \error_log(\json_encode($item_arr));
return $item_arr;
}

View File

@ -186,12 +186,12 @@ class Item_Metadata_Entity extends Entity {
if( is_array($v) ) {
$compounds = [];
foreach ($v as $itemMetadata) {
if ( $itemMetadata instanceof ItemMetadataEntity ) {
if ( $itemMetadata instanceof Item_Metadata_Entity ) {
$compounds[] = $itemMetadata->_toArray();
}
}
$return[] = $compounds;
} else if ( $v instanceof Term || $v instanceof ItemMetadataEntity ) {
} else if ( $v instanceof Term || $v instanceof Item_Metadata_Entity ) {
$return[] = $v->_toArray();
} else {
$return[] = $v;
@ -236,7 +236,7 @@ class Item_Metadata_Entity extends Entity {
}
ksort( $compounds );
$return = array_merge($compounds, $compounds_not_ordinate);
} else if ( $value instanceof Term || $value instanceof ItemMetadataEntity ) {
} else if ( $value instanceof Term || $value instanceof Item_Metadata_Entity ) {
$return = $value->_toArray();
} else {
$return = $value;

View File

@ -90,6 +90,7 @@ class Compound extends Metadata_Type {
$options = parent::get_options();
$options['children_order'] = isset($options['children_order']) ? $options['children_order'] : [];
$options['children_objects'] = [];
$children_not_ordinate = [];
if( isset( $options['parent'] ) ) {
$childrens = $Tainacan_Metadata->fetch( ['parent' => $options['parent'] ], "OBJECT" );
@ -100,9 +101,17 @@ class Compound extends Metadata_Type {
ob_start();
$child->get_metadata_type_object()->form();
$child = ob_get_clean();
$item_arr['edit_form'] = $form;
$options['children_objects'][] = $item_arr;
$item_arr['edit_form'] = $form;
$index = array_search( $item_arr['id'], array_column( $options['children_order'], 'id' ) );
if ( $index !== false ) {
$options['children_objects'][$index] = $item_arr;
} else {
$children_not_ordinate['children_objects'][] = $item_arr;
}
}
ksort( $options['children_objects'] );
$options['children_objects'] = array_merge($options['children_objects'], $children_not_ordinate);
}
return $options;
}