|
|
@@ -15,8 +15,10 @@ $customer_slug = Util::slug($customer->name);
|
|
|
|
|
|
$sorts = [
|
|
|
"name" => "Name",
|
|
|
- "last-added" => "Last Added",
|
|
|
"internal-id" => "Internal ID",
|
|
|
+ "last-added" => "Most recently added first",
|
|
|
+ "test-count" => "Highest test count first",
|
|
|
+ "retest-count" => "Highest retest count first",
|
|
|
];
|
|
|
|
|
|
$page_title = "$customer->name Locations";
|
|
|
@@ -78,16 +80,39 @@ switch($sort) {
|
|
|
$query_sort = "id";
|
|
|
$order = "desc";
|
|
|
break;
|
|
|
+
|
|
|
+ case "test-count":
|
|
|
+ $query_sort = "test_count";
|
|
|
+ $order = "desc";
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "retest-count":
|
|
|
+ $query_sort = "retest_count";
|
|
|
+ $order = "desc";
|
|
|
+ break;
|
|
|
+
|
|
|
default:
|
|
|
$query_sort = "name";
|
|
|
$order = "asc";
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
-$locations = Location::query($nvp, ["sort" => $query_sort, "order" => $order]);
|
|
|
+[$date_start, $date_end] = $customer->getYearCycleDates();
|
|
|
+
|
|
|
+$sql = "SELECT `location`.*, COUNT(`test`.`id`) AS `test_count`, SUM(IF(`test`.`retest` = 1, 1, 0)) AS `retest_count`
|
|
|
+ FROM `location`
|
|
|
+ LEFT JOIN `test` ON `test`.`location_id`=`location`.`id` AND `dts_start` BETWEEN '$date_start' AND '$date_end'
|
|
|
+ WHERE `customer_id`='$customer->id' GROUP BY `location`.`id`
|
|
|
+ ORDER BY $query_sort $order
|
|
|
+";
|
|
|
+
|
|
|
+$locations = Location::findBySql($sql);
|
|
|
+
|
|
|
+
|
|
|
+//$locations = Location::query($nvp, ["sort" => $query_sort, "order" => $order]);
|
|
|
|
|
|
-if($sort == "internal-id") {
|
|
|
- usort($locations, function($a, $b) {
|
|
|
+if($sort === "internal-id") {
|
|
|
+ usort($locations, static function(Location $a, Location $b) {
|
|
|
return strnatcasecmp($a->internal_id, $b->internal_id);
|
|
|
});
|
|
|
}
|