prefix . 'aieo_price_history'; if ( ! $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $aieo_ph_table ) ) ) { return array(); } $aieo_ph_sql = " SELECT h.product_id, COALESCE( NULLIF( p.post_title, '' ), NULLIF( pp.post_title, '' ), CONCAT( '#', h.product_id ) ) AS product, COUNT(*) AS changes, MIN( h.observed_at ) AS first_at, MAX( h.observed_at ) AS last_at, MIN( h.price ) AS lo, MAX( h.price ) AS hi FROM {prefix}aieo_price_history h LEFT JOIN {prefix}posts p ON p.ID = h.product_id LEFT JOIN {prefix}posts pp ON pp.ID = p.post_parent GROUP BY h.product_id, p.post_title, pp.post_title "; return array( 'id' => 'price_history_changes', 'label' => 'Products with the most price changes', 'description' => '', 'scope' => 'both', 'source' => 'sql', 'sql' => $aieo_ph_sql, 'registry_id' => 'price_history.omnibus', 'version' => '1', 'per_page' => 50, 'row_key' => 'product_id', 'default_sort' => array( 'changes', 'desc' ), 'empty_state' => 'No price changes recorded yet. The change-only sweep writes a row the first time a product’s effective price differs from the last one it saw, so this fills up as prices move.', 'columns' => array( array( 'key' => 'product_id', 'label' => 'Product ID', 'type' => 'id', 'sortable' => true, 'searchable' => true, 'hidden' => true, ), array( 'key' => 'product', 'label' => 'Product', 'type' => 'text', 'sortable' => true, 'searchable' => true, 'truncate' => 48, 'tooltip' => true, 'subline' => 'product_id', ), array( 'key' => 'changes', 'label' => 'Changes', 'type' => 'integer', 'width' => '90px', 'sortable' => true, 'filter' => 'number_range', 'aggregate' => 'SUM', ), array( 'key' => 'first_at', 'label' => 'First', 'type' => 'date', 'width' => '110px', 'nowrap' => true, 'sortable' => true, 'filter' => 'date_range', 'format' => array( 'tz' => 'utc' ), ), array( 'key' => 'last_at', 'label' => 'Last', 'type' => 'date', 'width' => '110px', 'nowrap' => true, 'sortable' => true, 'filter' => 'date_range', 'format' => array( 'tz' => 'utc' ), ), array( 'key' => 'lo', 'label' => 'Lowest', 'type' => 'money', 'width' => '110px', 'sortable' => true, ), array( 'key' => 'hi', 'label' => 'Highest', 'type' => 'money', 'width' => '110px', 'sortable' => true, ), ), );