fuel-stats/app/controllers/DashboardController.php

43 lines
1.2 KiB
PHP
Raw Permalink Normal View History

<?php
class DashboardController extends Controller {
public function index() {
2024-12-31 15:53:15 +01:00
$vehicle = new Vehicle();
$vehicles = $vehicle->getVehiclesByUser($_SESSION['user']['id']);
2025-01-05 21:24:55 +01:00
$default_car = $vehicle->getDefaultVehicle($_SESSION['user']['id']);
$refuel = new Refuel();
$data = [
"date" => [],
"price" => [],
];
$raw_data = $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']);
}
$latest_record = [
'name',
'liters',
'price_per_liter',
'total_price',
'created_at'
];
$latest_record = $refuel->latest_one($_SESSION['user']['id'])[0];
$this->view('dashboard/index', [
'title' => 'Dashboard',
2024-12-31 15:53:15 +01:00
'vehicles' => $vehicles,
2025-01-05 21:24:55 +01:00
'date_price_data' => $data,
'default_car' => $default_car,
'latest_record' => $latest_record,
]);
}
public function reroute(){
$this->redirect('/dashboard');
}
}