Merge branch 'release/0.18' of https://github.com/tainacan/tainacan into release/0.18
This commit is contained in:
commit
f23ac48179
|
@ -382,8 +382,9 @@ class REST_Bulkedit_Controller extends REST_Controller {
|
||||||
global $Tainacan_Generic_Process_Handler;
|
global $Tainacan_Generic_Process_Handler;
|
||||||
$process = $Tainacan_Generic_Process_Handler->get_process_instance_by_session_id($bulk_id);
|
$process = $Tainacan_Generic_Process_Handler->get_process_instance_by_session_id($bulk_id);
|
||||||
if ($process !== false) {
|
if ($process !== false) {
|
||||||
|
$bulk_edit_value = isset($body['new_value']) ? $body['new_value'] : (isset($body['value']) ? $body['value'] : null);
|
||||||
$bulk_edit_data = [
|
$bulk_edit_data = [
|
||||||
"value" => isset($body['new_value']) ? $body['new_value'] : $body['value'],
|
"value" => $bulk_edit_value,
|
||||||
"method" => $method,
|
"method" => $method,
|
||||||
"old_value" => isset($body['old_value']) ? $body['old_value'] : null,
|
"old_value" => isset($body['old_value']) ? $body['old_value'] : null,
|
||||||
"metadatum_id" => isset($body['metadatum_id']) ? $body['metadatum_id'] : null,
|
"metadatum_id" => isset($body['metadatum_id']) ? $body['metadatum_id'] : null,
|
||||||
|
|
|
@ -311,7 +311,9 @@ class REST_Reports_Controller extends REST_Controller {
|
||||||
'trash' => 0,
|
'trash' => 0,
|
||||||
'draft' => 0,
|
'draft' => 0,
|
||||||
'publish' => 0,
|
'publish' => 0,
|
||||||
'private' => 0
|
'private' => 0,
|
||||||
|
'restrict' => 0,
|
||||||
|
'not_restrict' => 0
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -339,7 +341,7 @@ class REST_Reports_Controller extends REST_Controller {
|
||||||
$cached_object = $this->get_cache_object($key_cache_object, $request);
|
$cached_object = $this->get_cache_object($key_cache_object, $request);
|
||||||
if($cached_object !== false ) return new \WP_REST_Response($cached_object, 200);
|
if($cached_object !== false ) return new \WP_REST_Response($cached_object, 200);
|
||||||
|
|
||||||
$collections = $this->collections_repository->fetch([]);
|
$collections = $this->collections_repository->fetch(['status'=> ['publish', 'private', 'trash']]);
|
||||||
$response['totals']['collections'] = array(
|
$response['totals']['collections'] = array(
|
||||||
'total' => 0,
|
'total' => 0,
|
||||||
'trash' => 0,
|
'trash' => 0,
|
||||||
|
@ -354,12 +356,20 @@ class REST_Reports_Controller extends REST_Controller {
|
||||||
$response['totals']['collections']['total']++;
|
$response['totals']['collections']['total']++;
|
||||||
$total_items = wp_count_posts( $collection->get_db_identifier(), 'readable' );
|
$total_items = wp_count_posts( $collection->get_db_identifier(), 'readable' );
|
||||||
|
|
||||||
if (isset($total_items->publish) || isset($total_items->private) ||
|
$response['totals']['items']['trash'] += isset($total_items->trash) ? intval($total_items->trash) : 0;
|
||||||
isset($total_items->trash) || isset($total_items->draft)) {
|
$response['totals']['items']['draft'] += isset($total_items->draft) ? intval($total_items->draft) : 0;
|
||||||
$response['totals']['items']['trash'] += $total_items->trash;
|
$response['totals']['items']['publish'] += isset($total_items->publish)? intval($total_items->publish) : 0;
|
||||||
$response['totals']['items']['draft'] += $total_items->draft;
|
$response['totals']['items']['private'] += isset($total_items->private)? intval($total_items->private) : 0;
|
||||||
$response['totals']['items']['publish'] += $total_items->publish;
|
|
||||||
$response['totals']['items']['private'] += $total_items->private;
|
if ( \is_post_status_viewable( $collection->get_status() ) === true ) {
|
||||||
|
$response['totals']['items']['not_restrict'] += isset($total_items->publish) ? intval($total_items->publish) : 0;
|
||||||
|
} else {
|
||||||
|
$response['totals']['items']['restrict'] += (
|
||||||
|
(isset($total_items->trash) ? intval($total_items->trash) : 0) +
|
||||||
|
(isset($total_items->draft) ? intval($total_items->draft) : 0) +
|
||||||
|
(isset($total_items->publish) ? intval($total_items->publish) : 0) +
|
||||||
|
(isset($total_items->private) ? intval($total_items->private) : 0)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wp_reset_postdata();
|
wp_reset_postdata();
|
||||||
|
@ -376,20 +386,14 @@ class REST_Reports_Controller extends REST_Controller {
|
||||||
);
|
);
|
||||||
$total_taxonomies = wp_count_posts( 'tainacan-taxonomy', 'readable' );
|
$total_taxonomies = wp_count_posts( 'tainacan-taxonomy', 'readable' );
|
||||||
|
|
||||||
if (isset($total_taxonomies->publish) ||
|
$response['totals']['taxonomies']['trash'] = isset($total_taxonomies->trash) ? intval($total_taxonomies->trash) : 0;
|
||||||
isset($total_taxonomies->private) ||
|
$response['totals']['taxonomies']['draft'] = isset($total_taxonomies->draft) ? intval($total_taxonomies->draft) : 0;
|
||||||
isset($total_taxonomies->trash) ||
|
$response['totals']['taxonomies']['publish'] = isset($total_taxonomies->publish)? intval($total_taxonomies->publish) : 0;
|
||||||
isset($total_taxonomies->draft)) {
|
$response['totals']['taxonomies']['private'] = isset($total_taxonomies->private)? intval($total_taxonomies->private) : 0;
|
||||||
|
|
||||||
$response['totals']['taxonomies']['trash'] = intval($total_taxonomies->trash);
|
|
||||||
$response['totals']['taxonomies']['publish'] = intval($total_taxonomies->publish);
|
|
||||||
$response['totals']['taxonomies']['draft'] = intval($total_taxonomies->draft);
|
|
||||||
$response['totals']['taxonomies']['private'] = intval($total_taxonomies->private);
|
|
||||||
$response['totals']['taxonomies']['total'] = $response['totals']['taxonomies']['trash'] + $response['totals']['taxonomies']['publish'] + $response['totals']['taxonomies']['draft'] + $response['totals']['taxonomies']['private'];
|
$response['totals']['taxonomies']['total'] = $response['totals']['taxonomies']['trash'] + $response['totals']['taxonomies']['publish'] + $response['totals']['taxonomies']['draft'] + $response['totals']['taxonomies']['private'];
|
||||||
$response['totals']['taxonomies']['used'] = $this->query_count_used_taxononomies();
|
$response['totals']['taxonomies']['used'] = $this->query_count_used_taxononomies();
|
||||||
$response['totals']['taxonomies']['not_used'] = $response['totals']['taxonomies']['total'] - $response['totals']['taxonomies']['used'];
|
$response['totals']['taxonomies']['not_used'] = $response['totals']['taxonomies']['total'] - $response['totals']['taxonomies']['used'];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
$response['totals']['items']['total'] = ($response['totals']['items']['trash'] + $response['totals']['items']['draft'] + $response['totals']['items']['publish'] + $response['totals']['items']['private']);
|
$response['totals']['items']['total'] = ($response['totals']['items']['trash'] + $response['totals']['items']['draft'] + $response['totals']['items']['publish'] + $response['totals']['items']['private']);
|
||||||
$this->set_cache_object($key_cache_object, $response);
|
$this->set_cache_object($key_cache_object, $response);
|
||||||
return new \WP_REST_Response($response, 200);
|
return new \WP_REST_Response($response, 200);
|
||||||
|
|
|
@ -278,7 +278,8 @@ class Bulk_Edit_Process extends Generic_Process {
|
||||||
|
|
||||||
private function clear_value(\Tainacan\Entities\Item $item) {
|
private function clear_value(\Tainacan\Entities\Item $item) {
|
||||||
$metadatum = $this->metadatum_repository->fetch($this->bulk_edit_data['metadatum_id']);
|
$metadatum = $this->metadatum_repository->fetch($this->bulk_edit_data['metadatum_id']);
|
||||||
$item_metadata = new Entities\Item_Metadata_Entity( $item, $metadatum );
|
$parent_meta_id = $this->get_parent_meta_id($item, $metadatum);
|
||||||
|
$item_metadata = new Entities\Item_Metadata_Entity( $item, $metadatum, null, $parent_meta_id );
|
||||||
$item_metadata->set_value("");
|
$item_metadata->set_value("");
|
||||||
return $this->save_item_metadata($item_metadata, $item);
|
return $this->save_item_metadata($item_metadata, $item);
|
||||||
}
|
}
|
||||||
|
@ -286,8 +287,9 @@ class Bulk_Edit_Process extends Generic_Process {
|
||||||
private function set_value(\Tainacan\Entities\Item $item) {
|
private function set_value(\Tainacan\Entities\Item $item) {
|
||||||
$metadatum = $this->metadatum_repository->fetch($this->bulk_edit_data['metadatum_id']);
|
$metadatum = $this->metadatum_repository->fetch($this->bulk_edit_data['metadatum_id']);
|
||||||
$value = $this->bulk_edit_data['value'];
|
$value = $this->bulk_edit_data['value'];
|
||||||
|
$parent_meta_id = $this->get_parent_meta_id($item, $metadatum);
|
||||||
|
|
||||||
$item_metadata = new Entities\Item_Metadata_Entity( $item, $metadatum );
|
$item_metadata = new Entities\Item_Metadata_Entity( $item, $metadatum, null, $parent_meta_id );
|
||||||
|
|
||||||
if($item_metadata->is_multiple()) {
|
if($item_metadata->is_multiple()) {
|
||||||
$value = is_array( $value ) ? $value : [$value];
|
$value = is_array( $value ) ? $value : [$value];
|
||||||
|
@ -300,6 +302,22 @@ class Bulk_Edit_Process extends Generic_Process {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function get_parent_meta_id($item, $metadatum) {
|
||||||
|
$metadatum_parent_id = $metadatum->get_parent();
|
||||||
|
if ($metadatum_parent_id > 0) {
|
||||||
|
$metadatum_parent = $this->metadatum_repository->fetch($metadatum_parent_id);
|
||||||
|
$compoundItem = new Entities\Item_Metadata_Entity($item, $metadatum_parent);
|
||||||
|
$unique = !$compoundItem->is_multiple();
|
||||||
|
$compoundValue = $compoundItem->get_value();
|
||||||
|
if ( $unique && !empty($compoundValue) ) {
|
||||||
|
$key = array_keys($compoundValue)[0]; // get the first metadata ID, if the argument metadata does not exist
|
||||||
|
$parent_meta_id = $compoundValue[$key]->get_parent_meta_id();
|
||||||
|
return $parent_meta_id;
|
||||||
|
} // elseif ((is_array($compoundValue) && sizeof($compoundValue) > 0))
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private function add_value(\Tainacan\Entities\Item $item) {
|
private function add_value(\Tainacan\Entities\Item $item) {
|
||||||
$metadatum_id = $this->bulk_edit_data['metadatum_id'];
|
$metadatum_id = $this->bulk_edit_data['metadatum_id'];
|
||||||
$metadatum = $this->metadatum_repository->fetch($metadatum_id);
|
$metadatum = $this->metadatum_repository->fetch($metadatum_id);
|
||||||
|
|
Loading…
Reference in New Issue