|
|
@@ -111,66 +111,21 @@ if($submit) {
|
|
|
}
|
|
|
|
|
|
$tests = Test::query($test_nvp);
|
|
|
- $test_count = count($tests);
|
|
|
|
|
|
- // Get test values
|
|
|
- $test_ids = array_column($tests, "id");
|
|
|
- $test_values = TestValue::query([
|
|
|
- "test_id" => $test_ids,
|
|
|
- ]);
|
|
|
-
|
|
|
- $test_values_map = [];
|
|
|
- foreach($test_values as $test_value) {
|
|
|
- $test_id = $test_value->test_id;
|
|
|
- $name = $test_value->name;
|
|
|
-
|
|
|
- if(!isset($test_values_map[$test_id])) {
|
|
|
- $test_values_map[$test_id] = new stdClass;
|
|
|
- }
|
|
|
-
|
|
|
- $test_values_map[$test_id]->{$name} = $test_value->value;
|
|
|
- }
|
|
|
-
|
|
|
- // Load users
|
|
|
- User::load(array_column($tests, "tester_id"));
|
|
|
-
|
|
|
- // Load locations
|
|
|
- $locations = Location::load(array_column($tests, "location_id"));
|
|
|
-
|
|
|
- // Get region and area manager IDs
|
|
|
- $regions = array_filter(array_column($locations, "region"));
|
|
|
- $area_managers = array_filter(array_column($locations, "area_manager"));
|
|
|
-
|
|
|
- uksort($regions, "strnatcasecmp");
|
|
|
- uksort($area_managers, "strnatcasecmp");
|
|
|
-
|
|
|
- foreach($regions as $region) {
|
|
|
- $region_data[$region] = [];
|
|
|
- }
|
|
|
-
|
|
|
- foreach($area_managers as $area_manager) {
|
|
|
- $area_manager_data[$area_manager] = [];
|
|
|
- }
|
|
|
-
|
|
|
- $has_regions = !empty($region_data);
|
|
|
- $has_area_managers = !empty($area_manager_data);
|
|
|
-
|
|
|
- foreach($locations as $location) {
|
|
|
- if($has_regions && !$location->region) $locations_missing_region[] = $location;
|
|
|
- if($has_area_managers && !$location->area_manager) $locations_missing_area_manager[] = $location;
|
|
|
- }
|
|
|
+ $test_result_set = new TestResultSet($tests);
|
|
|
|
|
|
// Calculate date ranges
|
|
|
$min_year = date("Y");
|
|
|
$max_year = date("Y");
|
|
|
|
|
|
- $min_unix = strtotime("$min_year-01-01 UTC");
|
|
|
- $max_unix = strtotime("$max_year-12-31 23:59:59 UTC");
|
|
|
-
|
|
|
switch($date_range) {
|
|
|
case "ytd":
|
|
|
+ default:
|
|
|
// Nothing to do
|
|
|
$date_range_label = "YTD";
|
|
|
+
|
|
|
+ $min_dts = "$min_year-01-01";
|
|
|
+ $max_dts = "$max_year-12-31 23:59:59";
|
|
|
break;
|
|
|
|
|
|
case "unbound":
|
|
|
@@ -184,7 +139,12 @@ if($submit) {
|
|
|
if($year < $min_year) $min_year = $year;
|
|
|
if($year > $max_year) $max_year = $year;
|
|
|
}
|
|
|
+
|
|
|
$date_range_label = "$min_year - $max_year";
|
|
|
+
|
|
|
+ $min_dts = "$min_year-01-01";
|
|
|
+ $max_dts = "$max_year-12-31 23:59:59";
|
|
|
+
|
|
|
break;
|
|
|
|
|
|
case "custom":
|
|
|
@@ -198,44 +158,69 @@ if($submit) {
|
|
|
list($min_year, $min_month, $min_day) = explode("-", $date_start);
|
|
|
list($max_year, $max_month, $max_day) = explode("-", $date_end);
|
|
|
|
|
|
- $min_unix = strtotime("{$date_start} 00:00:00 UTC");
|
|
|
- $max_unix = strtotime("{$date_end} 23:59:59 UTC");
|
|
|
+ $min_dts = "{$date_start} 00:00:00";
|
|
|
+ $max_dts = "{$date_end} 23:59:59";
|
|
|
|
|
|
- $date_range_label = date("d/m/Y", $min_unix) . " - " . date("d/m/Y", $max_unix);
|
|
|
+ $date_range_label = "{$min_day}/{$min_month}/{$min_year} - {$max_day}/{$max_month}/{$max_year}";
|
|
|
|
|
|
if(preg_match("/01-01$/", $date_start) && preg_match("/12-31$/", $date_end)) {
|
|
|
+ $date_range_label = $min_year == $max_year ? $min_year : "{$min_year} - {$max_year}";
|
|
|
+ }
|
|
|
|
|
|
- if($min_year == $max_year) {
|
|
|
- $date_range_label = $min_year;
|
|
|
- }
|
|
|
- else {
|
|
|
- $date_range_label = "{$min_year} - {$max_year}";
|
|
|
- }
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ $tests = $test_result_set->filterByDateRange($min_dts, $max_dts);
|
|
|
|
|
|
+ // Get test values
|
|
|
+ $test_ids = array_column($tests, "id");
|
|
|
+ $test_values = TestValue::query([
|
|
|
+ "test_id" => $test_ids,
|
|
|
+ ]);
|
|
|
|
|
|
- break;
|
|
|
+ $test_values_map = [];
|
|
|
+ foreach($test_values as $test_value) {
|
|
|
+ $test_id = $test_value->test_id;
|
|
|
+ $name = $test_value->name;
|
|
|
+
|
|
|
+ if(!isset($test_values_map[$test_id])) {
|
|
|
+ $test_values_map[$test_id] = new stdClass;
|
|
|
+ }
|
|
|
+
|
|
|
+ $test_values_map[$test_id]->{$name} = $test_value->value;
|
|
|
}
|
|
|
|
|
|
- // Check if date range is same year
|
|
|
- $same_year = ($min_year == $max_year);
|
|
|
+ // Load users
|
|
|
+ User::load(array_column($tests, "tester_id"));
|
|
|
+
|
|
|
+ // Load locations
|
|
|
+ $locations = Location::load(array_column($tests, "location_id"));
|
|
|
|
|
|
- // Filter tests based on date range
|
|
|
- $tests = array_filter($tests, function(Test $test) use ($min_unix, $max_unix) {
|
|
|
+ // Get region and area manager IDs
|
|
|
+ $regions = array_filter(array_column($locations, "region"));
|
|
|
+ $area_managers = array_filter(array_column($locations, "area_manager"));
|
|
|
|
|
|
- $project = $test->getProject();
|
|
|
+ uksort($regions, "strnatcasecmp");
|
|
|
+ uksort($area_managers, "strnatcasecmp");
|
|
|
|
|
|
- $dts = $project->dts_report ?: $test->dts_start;
|
|
|
+ foreach($regions as $region) {
|
|
|
+ $region_data[$region] = [];
|
|
|
+ }
|
|
|
|
|
|
- $dt = new DateTime($dts . " UTC");
|
|
|
- $unix = $dt->format("U");
|
|
|
+ foreach($area_managers as $area_manager) {
|
|
|
+ $area_manager_data[$area_manager] = [];
|
|
|
+ }
|
|
|
|
|
|
- if($unix < $min_unix) return false;
|
|
|
- if($unix > $max_unix) return false;
|
|
|
+ $has_regions = !empty($region_data);
|
|
|
+ $has_area_managers = !empty($area_manager_data);
|
|
|
|
|
|
- return true;
|
|
|
- });
|
|
|
+ foreach($locations as $location) {
|
|
|
+ if($has_regions && !$location->region) $locations_missing_region[] = $location;
|
|
|
+ if($has_area_managers && !$location->area_manager) $locations_missing_area_manager[] = $location;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Check if date range is same year
|
|
|
+ $same_year = ($min_year == $max_year);
|
|
|
|
|
|
// Empty data objects hook
|
|
|
require $template->getProcessingFilePath("reports_create_empty_objects.php");
|