Merge branch 'feature/483' of https://github.com/tainacan/tainacan into feature/483

This commit is contained in:
mateuswetah 2021-03-04 16:15:29 -03:00
commit 3ff0bbe48d
1 changed files with 29 additions and 3 deletions

View File

@ -274,7 +274,7 @@ class REST_Reports_Controller extends REST_Controller {
$sql_statement = $wpdb->prepare( $sql_statement = $wpdb->prepare(
"SELECT p.post_title AS 'name', m.meta_key AS id, ((m.total/$total_items) * 100) as fill_percentage "SELECT p.post_title AS 'name', m.meta_key AS id, ((m.total/$total_items) * 100) as fill_percentage
FROM FROM
(SELECT meta_key, count(*) AS total (SELECT meta_key, count(DISTINCT post_id) AS total
FROM $wpdb->postmeta FROM $wpdb->postmeta
WHERE $wpdb->postmeta.meta_key IN ($string_meta_ids) WHERE $wpdb->postmeta.meta_key IN ($string_meta_ids)
AND $wpdb->postmeta.post_id IN ( AND $wpdb->postmeta.post_id IN (
@ -283,10 +283,36 @@ class REST_Reports_Controller extends REST_Controller {
WHERE $wpdb->posts.post_type = '$collection_post_type' WHERE $wpdb->posts.post_type = '$collection_post_type'
) )
GROUP BY $wpdb->postmeta.meta_key) m GROUP BY $wpdb->postmeta.meta_key) m
INNER JOIN $wpdb->posts p on m.meta_key = p.id
UNION
SELECT p.post_title AS 'name', m.meta_key AS id, ((m.total/$total_items) * 100) as fill_percentage
FROM
(
SELECT
mt.meta_key, count(DISTINCT tr.object_id) AS total
FROM
$wpdb->term_taxonomy tt
INNER JOIN $wpdb->term_relationships tr ON tt.term_taxonomy_id = tr.term_taxonomy_id
INNER JOIN (
SELECT
post_id as 'meta_key', concat('tnc_tax_', meta_value) as 'tax_id'
FROM
$wpdb->postmeta
WHERE
meta_key='_option_taxonomy_id'
) mt ON tt.taxonomy = mt.tax_id
WHERE
mt.meta_key IN ($string_meta_ids)
AND tr.object_id IN (
SELECT id
FROM $wpdb->posts
WHERE $wpdb->posts.post_type = '$collection_post_type'
)
GROUP BY mt.meta_key) m
INNER JOIN $wpdb->posts p on m.meta_key = p.id;" INNER JOIN $wpdb->posts p on m.meta_key = p.id;"
); );
$res = $wpdb->get_results($sql_statement); $res = $wpdb->get_results($sql_statement);
//return $sql_statement; //return ['t' => $res, 's' => $sql_statement];
return $res; return $res;
} }