Skip to content

Commit

Permalink
feat(Test): make order by status work with calculated status
Browse files Browse the repository at this point in the history
  • Loading branch information
harunbleech committed Feb 16, 2024
1 parent 0b82ca4 commit 315e22e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion includes/models/class-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Vrts\Models;

use Vrts\Features\Service;
use Vrts\Features\Subscription;
use Vrts\Tables\Tests_Table;

/**
Expand Down Expand Up @@ -56,6 +58,7 @@ public static function get_items( $args = [] ) {
$orderby = in_array( $args['orderby'], $whitelist_orderby, true ) ? $args['orderby'] : 'id';
$order = in_array( $args['order'], $whitelist_order, true ) ? $args['order'] : 'DESC';

$orderby = 'status' === $orderby ? 'calculated_status' : $orderby;
$orderby = "ORDER BY $orderby $order";

$limit = $args['number'] > 100 ? 100 : $args['number'];
Expand All @@ -66,6 +69,9 @@ public static function get_items( $args = [] ) {
$limit
);

$is_connected = Service::is_connected() ? 'true' : 'false';
$no_tests_left = intval( Subscription::get_remaining_tests() ) === 0 ? 'true' : 'false';

$query = "
SELECT
tests.id,
Expand All @@ -78,7 +84,17 @@ public static function get_items( $args = [] ) {
tests.next_run_date,
tests.last_comparison_date,
tests.is_running,
posts.post_title
posts.post_title,
CASE
WHEN $is_connected is not true THEN 'disconnected'
WHEN tests.current_alert_id is not null THEN 'has-alert'
WHEN tests.status > 0 and $no_tests_left THEN 'no_credit_left'
WHEN tests.service_test_id is null THEN 'post_not_published'
WHEN tests.base_screenshot_date is null THEN 'waiting'
WHEN tests.is_running > 0 THEN 'running'
WHEN tests.last_comparison_date is null THEN 'scheduled'
else 'passed'
END as calculated_status
FROM $tests_table as tests
INNER JOIN $wpdb->posts as posts ON posts.id = tests.post_id
$where
Expand Down

0 comments on commit 315e22e

Please sign in to comment.