Updated: Improved vehicle and refuel data handling on dashboard
All checks were successful
Build and Deploy Zola Website / build_and_deploy (push) Successful in 14s

Updated:
- DashboardController now fetches latest refuel record only for the default vehicle
- VehicleController - first created vehicle is now set as default automatically
- Refuel model - latest_one() now accepts vehicle_id instead of user_id
- Dashboard view - improved handling when no vehicles or refuel records exist
- CSS styles - adjusted dashboard layout and global action padding
This commit is contained in:
2025-02-01 18:38:49 +01:00
parent f90c707435
commit 7517bcb78f
8 changed files with 52 additions and 17 deletions

View File

@@ -3,8 +3,7 @@ class DashboardController extends Controller {
public function index() {
$vehicle = new Vehicle();
$vehicles = $vehicle->getVehiclesByUser($_SESSION['user']['id']);
$default_car = $vehicle->getDefaultVehicle($_SESSION['user']['id']);
$default_car = $vehicle->getDefaultVehicle($_SESSION['user']['id']) ?? null;
$refuel = new Refuel();
$data = [
@@ -13,7 +12,7 @@ class DashboardController extends Controller {
"mileage" => [],
"liters" => []
];
$raw_data = $refuel->latest_data($default_car['id'], 5);
$raw_data = $default_car ? $refuel->latest_data($default_car['id'], 5) : [];
foreach($raw_data as $one) {
array_push($data['date'], date('d. m.', strtotime($one['created_at'])));
array_push($data['price'], $one['price_per_liter']);
@@ -21,7 +20,8 @@ class DashboardController extends Controller {
array_push($data['liters'], $one['liters']);
}
$latest_record = $refuel->latest_one($_SESSION['user']['id'])[0];
$latest_data = $default_car ? $refuel->latest_one($default_car['id']) : [];
$latest_record = !empty($latest_data) ? $latest_data[0] : null;
$this->view('dashboard/index', [
'title' => 'Dashboard',