Constraint::notEquals(Test::STATUS_CANCELLED), "location_id" => array_column($locations, "id"), "dts_start" => $customer->getYearCycleConstraint(TIMEZONE), ]); $test_counts = []; foreach($tests as $test) { if(!isset($test_counts[$test->location_id])) { $test_counts[$test->location_id] = 0; } if($test->isCompleted()) { $test_counts[$test->location_id]++; } } $latest_tests = $customer->getLatestTestByLocation(); $dt_start = $project->getDateTimeStart(); $dt_deadline = $project->getDateTimeDeadline(); $dt_report = $project->getDateTimeReport() ?: null; $date_report = $dt_report ? $dt_report->format("Y-m-d") : ""; $date_invoice = $project->invoice_date; $name_readonly = $project->id ? "" : "readonly"; $autogen_checked = $project->id ? "" : "checked"; // Figure out which locations are selected $tests = []; $location_test = []; if($project->id) { $tests = $project->getTests(); foreach($tests as $test) { $location_test[$test->location_id] = $test; } } $selected_locations = array_filter($locations, static function(Location $l) use ($location_ids) { return in_array($l->id, $location_ids, false); }); $deselected_locations = array_filter($locations, static function(Location $l) use ($location_ids) { return !in_array($l->id, $location_ids, false); }); /** * @param Location[] $locations * @param bool $selected * @return void */ $output_locations = static function(array $locations, bool $selected) use ($location_test, $test_counts, $customer, $latest_tests, $user) { foreach($locations as $location) { $address = $location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]); $filter_parts = array_filter([ $address, $location->name ]); $filter = strtolower(implode("", $filter_parts)); $button_class = $selected ? "danger" : "success"; $button_text = $selected ? "Deselect" : "Select"; $icon = $selected ? "times" : "check"; $test = $location_test[$location->id] ?? null; $test_status = $test_class = ""; if($test) { $test_status = $test->getStatusText(); $test_class = $test->getStatusClass(); } ?>