Revize d58f0fda
Přidáno uživatelem Cajova-Houba před téměř 7 roky(ů)
backend/app/Http/Controllers/DeviceController.php | ||
---|---|---|
10 | 10 |
|
11 | 11 |
use App\Model\Device; |
12 | 12 |
use App\Model\Zarizeni; |
13 |
use App\Model\Zaznam; |
|
13 | 14 |
use Illuminate\Http\Request; |
14 | 15 |
|
15 | 16 |
class DeviceController extends Controller |
16 | 17 |
{ |
17 | 18 |
public function getDevice(Request $request) { |
18 |
$address=''; |
|
19 |
$town = null; |
|
20 |
$street = null; |
|
19 | 21 |
$showDirection=0; |
20 | 22 |
if ($request->has('address')) { |
21 | 23 |
$address = $request->input('address'); |
24 |
// todo: what is a format of address ? |
|
25 |
$addressParts = explode(";", $address); |
|
26 |
if (count($addressParts) == 2) { |
|
27 |
$town = $addressParts[0]; |
|
28 |
$street = $addressParts[1]; |
|
29 |
} |
|
22 | 30 |
} |
23 | 31 |
|
24 | 32 |
if ($request->has('showDirection')) { |
25 | 33 |
$showDirection = ($request->input('showDirection') === 1); |
26 | 34 |
} |
27 | 35 |
|
28 |
$device = new Device(); |
|
29 |
$device->id = 1; |
|
30 |
$device->name = 'device'; |
|
31 |
$device->street = $address; |
|
32 |
$device->town = $address; |
|
33 |
|
|
34 |
// return response()->json($device); |
|
35 |
return Zarizeni::findByAddressJoinAddress('Česká Kubice', 'Česká Kubice'); |
|
36 |
return Zarizeni::findByAddressJoinAddress($street, $town); |
|
36 | 37 |
} |
37 | 38 |
|
38 | 39 |
/** |
... | ... | |
50 | 51 |
*/ |
51 | 52 |
public function getDeviceById(Request $request, $id) { |
52 | 53 |
|
53 |
return Zarizeni::findByIdJoinAddress($id); |
|
54 |
$dateFrom = null; |
|
55 |
$dateTo = null; |
|
56 |
$timeFrom = null; |
|
57 |
$timeTo = null; |
|
58 |
$direction = null; |
|
59 |
|
|
60 |
// nacti parametry |
|
61 |
if ($request->has('dateFrom')) { |
|
62 |
$dateFrom = $request->input('dateFrom'); |
|
63 |
} |
|
64 |
if ($request->has('dateTo')) { |
|
65 |
$dateTo = $request->input('dateTo'); |
|
66 |
} |
|
67 |
if ($request->has('timeFrom')) { |
|
68 |
$timeFrom = $request->input('timeFrom'); |
|
69 |
} |
|
70 |
if ($request->has('timeTo')) { |
|
71 |
$timeTo = $request->input('timeTo'); |
|
72 |
} |
|
73 |
if ($request->has('direction')) { |
|
74 |
$direction = $request->input('direction'); |
|
75 |
} |
|
76 |
|
|
77 |
$device = Zarizeni::findByIdJoinAddress($id); |
|
78 |
if ($device != null) { |
|
79 |
$device[0]->traffic = Zaznam::findByDevice($id, $dateFrom, $dateTo, $timeFrom, $timeTo, $direction); |
|
80 |
} |
|
81 |
|
|
82 |
return $device; |
|
54 | 83 |
} |
55 | 84 |
|
56 | 85 |
public function getAll() { |
57 | 86 |
return Zarizeni::getAllJoinAddress(); |
58 | 87 |
} |
88 |
|
|
89 |
public function lastDay() { |
|
90 |
return Zaznam::lastInsertedDate(); |
|
91 |
} |
|
59 | 92 |
} |
backend/app/Http/Controllers/VehicleController.php | ||
---|---|---|
10 | 10 |
|
11 | 11 |
|
12 | 12 |
use App\Model\Vehicle; |
13 |
use App\Model\Vozidlo; |
|
13 | 14 |
|
14 | 15 |
class VehicleController extends Controller |
15 | 16 |
{ |
... | ... | |
17 | 18 |
* Vrati vsechny typy vozidel. |
18 | 19 |
*/ |
19 | 20 |
public function getAll() { |
20 |
$vehicles = [ |
|
21 |
0 => Vehicle::create(0, 'neznámé'), |
|
22 |
1 => Vehicle::create(1, 'motocykl'), |
|
23 |
2 => Vehicle::create(2, 'osobní auto'), |
|
24 |
3 => Vehicle::create(4, 'dodávka') |
|
25 |
]; |
|
26 |
|
|
27 |
return $vehicles; |
|
21 |
return Vozidlo::all(); |
|
28 | 22 |
} |
29 | 23 |
} |
backend/app/Http/routes.php | ||
---|---|---|
36 | 36 |
*/ |
37 | 37 |
$app->get($apiUrlRoot.'devices/{id}', 'DeviceController@getDeviceById'); |
38 | 38 |
|
39 |
//$app->get($apiUrlRoot.'devices/lastday', 'DeviceController@lastDay'); |
|
40 |
|
|
39 | 41 |
/** |
40 | 42 |
* Vrati vsechny typy aut. |
41 | 43 |
*/ |
backend/app/Model/Device.php | ||
---|---|---|
1 |
<?php |
|
2 |
/** |
|
3 |
* Created by PhpStorm. |
|
4 |
* User: Zdenda |
|
5 |
* Date: 20.4.2018 |
|
6 |
* Time: 20:08 |
|
7 |
*/ |
|
8 |
|
|
9 |
namespace App\Model; |
|
10 |
|
|
11 |
|
|
12 |
class Device |
|
13 |
{ |
|
14 |
public $id; |
|
15 |
public $street; |
|
16 |
public $town; |
|
17 |
public $name; |
|
18 |
|
|
19 |
public function __construct() { |
|
20 |
} |
|
21 |
} |
backend/app/Model/Location.php | ||
---|---|---|
1 |
<?php |
|
2 |
/** |
|
3 |
* Created by PhpStorm. |
|
4 |
* User: Zdenda |
|
5 |
* Date: 16.4.2018 |
|
6 |
* Time: 13:22 |
|
7 |
*/ |
|
8 |
|
|
9 |
namespace App\Model; |
|
10 |
|
|
11 |
|
|
12 |
class Location |
|
13 |
{ |
|
14 |
public $id; |
|
15 |
public $name; |
|
16 |
public $town; |
|
17 |
public $street; |
|
18 |
public $device; |
|
19 |
public $area; |
|
20 |
|
|
21 |
public function __construct() { |
|
22 |
} |
|
23 |
|
|
24 |
/** |
|
25 |
* Vytvori novou instance lokace a naplni ji daty. Id je nastaveno na 0. |
|
26 |
* |
|
27 |
* @param $data Pole cislovane od nuly obsahujici data, kterymi bude naplnena nova instance. |
|
28 |
* Format: [0] = name, [1] = town, [2] = street, [3] = device, [4] = area |
|
29 |
* @return Location |
|
30 |
*/ |
|
31 |
public static function withData($data) { |
|
32 |
$instance = new self(); |
|
33 |
$instance ->id = 0; |
|
34 |
$instance ->name = $data[0]; |
|
35 |
$instance ->town = $data[1]; |
|
36 |
$instance ->street = $data[2]; |
|
37 |
$instance ->device = $data[3]; |
|
38 |
$instance ->area = $data[4]; |
|
39 |
|
|
40 |
return $instance; |
|
41 |
} |
|
42 |
|
|
43 |
public function toString() { |
|
44 |
return "<td>".$this->name."</td>"."<td>".$this->town."</td>"."<td>".$this->street."</td>". |
|
45 |
"<td>".$this->device."</td>"."<td>".$this->area."</td>"; |
|
46 |
} |
|
47 |
} |
backend/app/Model/Vehicle.php | ||
---|---|---|
1 |
<?php |
|
2 |
/** |
|
3 |
* Created by PhpStorm. |
|
4 |
* User: Zdenda |
|
5 |
* Date: 20.4.2018 |
|
6 |
* Time: 20:25 |
|
7 |
*/ |
|
8 |
|
|
9 |
namespace App\Model; |
|
10 |
|
|
11 |
|
|
12 |
class Vehicle |
|
13 |
{ |
|
14 |
public $id; |
|
15 |
public $name; |
|
16 |
|
|
17 |
public static function create($id, $name) { |
|
18 |
$inst = new Vehicle(); |
|
19 |
$inst->id = $id; |
|
20 |
$inst->name = $name; |
|
21 |
|
|
22 |
return $inst; |
|
23 |
} |
|
24 |
} |
backend/app/Model/Vozidlo.php | ||
---|---|---|
1 |
<?php |
|
2 |
/** |
|
3 |
* Created by PhpStorm. |
|
4 |
* User: Zdenda |
|
5 |
* Date: 23.4.2018 |
|
6 |
* Time: 14:57 |
|
7 |
*/ |
|
8 |
|
|
9 |
namespace App\Model; |
|
10 |
|
|
11 |
|
|
12 |
/** |
|
13 |
* Trida reprezentujici entitu vozidlo. |
|
14 |
* |
|
15 |
* @package App\Model |
|
16 |
*/ |
|
17 |
class Vozidlo extends BaseModel |
|
18 |
{ |
|
19 |
/** |
|
20 |
* Nazev tabulky v databazi. |
|
21 |
* @var string |
|
22 |
*/ |
|
23 |
protected $table = 'vozidlo'; |
|
24 |
} |
backend/app/Model/Zarizeni.php | ||
---|---|---|
34 | 34 |
return DB::table('zarizeni') |
35 | 35 |
->join('ulice', 'zarizeni.ulice_id', '=', 'ulice.id') |
36 | 36 |
->join('mesto', 'ulice.mesto_id', '=', 'mesto.id') |
37 |
->select('zarizeni.*', 'ulice.nazev as ulice_nazev', 'ulice.id as ulice_id', 'mesto.nazev as mesto_nazev', 'mesto.id as mesto_id')
|
|
37 |
->select('zarizeni.id as id', 'zarizeni.smer_popis as name', 'ulice.nazev as street', 'ulice.id as street_id', 'mesto.nazev as town', 'mesto.id as town_id')
|
|
38 | 38 |
->get(); |
39 | 39 |
} |
40 | 40 |
|
... | ... | |
50 | 50 |
return DB::table('zarizeni') |
51 | 51 |
->join('ulice', 'zarizeni.ulice_id', '=', 'ulice.id') |
52 | 52 |
->join('mesto', 'ulice.mesto_id', '=', 'mesto.id') |
53 |
->select('zarizeni.*', 'ulice.nazev as ulice_nazev', 'ulice.id as ulice_id', 'mesto.nazev as mesto_nazev', 'mesto.id as mesto_id')
|
|
53 |
->select('zarizeni.id as id', 'zarizeni.smer_popis as name', 'ulice.nazev as street', 'ulice.id as street_id', 'mesto.nazev as town', 'mesto.id as town_id')
|
|
54 | 54 |
->where('ulice.nazev', '=', $street) |
55 | 55 |
->where('mesto.nazev', '=', $town) |
56 | 56 |
->get(); |
... | ... | |
67 | 67 |
return DB::table('zarizeni') |
68 | 68 |
->join('ulice', 'zarizeni.ulice_id', '=', 'ulice.id') |
69 | 69 |
->join('mesto', 'ulice.mesto_id', '=', 'mesto.id') |
70 |
->select('zarizeni.*', 'ulice.nazev as ulice_nazev', 'ulice.id as ulice_id', 'mesto.nazev as mesto_nazev', 'mesto.id as mesto_id')
|
|
70 |
->select('zarizeni.id as id', 'zarizeni.smer_popis as name', 'ulice.nazev as street', 'ulice.id as street_id', 'mesto.nazev as town', 'mesto.id as town_id')
|
|
71 | 71 |
->where('zarizeni.id', '=', $id) |
72 |
->orderBy('zarizeni.id') |
|
72 | 73 |
->get(); |
73 | 74 |
} |
74 | 75 |
|
backend/app/Model/Zaznam.php | ||
---|---|---|
1 |
<?php |
|
2 |
/** |
|
3 |
* Created by PhpStorm. |
|
4 |
* User: Zdenda |
|
5 |
* Date: 23.4.2018 |
|
6 |
* Time: 12:47 |
|
7 |
*/ |
|
8 |
|
|
9 |
namespace App\Model; |
|
10 |
|
|
11 |
use Illuminate\Support\Facades\DB; |
|
12 |
|
|
13 |
|
|
14 |
/** |
|
15 |
* Trida reprezentujici entitu zarizeni v databazi. |
|
16 |
* @package App\Model |
|
17 |
*/ |
|
18 |
class Zaznam extends BaseModel |
|
19 |
{ |
|
20 |
protected $table = 'zaznam'; |
|
21 |
|
|
22 |
/** |
|
23 |
* Vrati posledni datum pro ktere existuji nejake zaznamy. |
|
24 |
*/ |
|
25 |
public static function lastInsertedDate() { |
|
26 |
return DB::table('zaznam_cas')->select(DB::raw('max(date(datetime_od)) as last_day'))->get(); |
|
27 |
} |
|
28 |
|
|
29 |
/** |
|
30 |
* Vrati zaznamy pro urcite zarizeni. |
|
31 |
* Typ vozidla je vracen s kazdym zaznamem. |
|
32 |
* |
|
33 |
* @param $deviceId Id zarizeni pro ktere budou vraceny zaznamy. |
|
34 |
* @param $dateFrom Pocatecni datum. Null znamená poledni vlozeny den. |
|
35 |
* @param $dateTo Koncove datum. Null znamena posledni vlozeny den. |
|
36 |
* @param $timeFrom Pocatecni cas. Null znamena 00:00. |
|
37 |
* @param $timeTo Koncovy cas. Null znamena 23:59. |
|
38 |
* @param $direction Pozadovany smer. Null znamena oba smery. |
|
39 |
*/ |
|
40 |
public static function findByDevice($deviceId, $dateFrom, $dateTo, $timeFrom, $timeTo, $direction) { |
|
41 |
$dateTimeFrom = null; |
|
42 |
$dateTimeTo = null; |
|
43 |
$lastDate = null; |
|
44 |
$dir = null; |
|
45 |
|
|
46 |
// jedno z omezujicich dat je null => ziskej posledni vlozene datum |
|
47 |
if ($dateFrom == null || $dateTo == null) { |
|
48 |
$lastDate = Zaznam::lastInsertedDate(); |
|
49 |
if ($lastDate == null) { |
|
50 |
// database is empty |
|
51 |
// todo: error codes |
|
52 |
return "no-data"; |
|
53 |
} else { |
|
54 |
$lastDate = $lastDate[0]->last_day; |
|
55 |
} |
|
56 |
} |
|
57 |
if ($dateFrom == null) { |
|
58 |
$dateFrom = $lastDate; |
|
59 |
} |
|
60 |
if ($dateTo == null) { |
|
61 |
$dateTo = $lastDate; |
|
62 |
} |
|
63 |
// omezujici casy |
|
64 |
if ($timeFrom == null) { |
|
65 |
$timeFrom = '00:00:00'; |
|
66 |
} |
|
67 |
if ($timeTo == null) { |
|
68 |
$timeTo = '23:59:59'; |
|
69 |
} |
|
70 |
$dateTimeFrom = date('Y-m-d H:i:s', strtotime("$dateFrom $timeFrom")); |
|
71 |
$dateTimeTo = date('Y-m-d H:i:s', strtotime("$dateTo $timeTo")); |
|
72 |
|
|
73 |
|
|
74 |
// vytvoreni query - vsechno to dat dohromady |
|
75 |
$query = DB::table('zaznam') |
|
76 |
->join('zaznam_cas', 'zaznam.zaznam_cas_id', '=', 'zaznam_cas.id') |
|
77 |
->join('vozidlo', 'zaznam.vozidlo_id', '=', 'vozidlo.id') |
|
78 |
->select('zaznam_cas.datetime_od as datetimeFrom', |
|
79 |
'zaznam_cas.datetime_do as datetimeTo', |
|
80 |
'zaznam_cas.smer as direction', |
|
81 |
'zaznam.rychlost_prumer as speedAverage', |
|
82 |
'vozidlo.nazev as typeVehicle', |
|
83 |
'vozidlo.id as numberVehicle') |
|
84 |
->where('zaznam_cas.datetime_od', '>=', $dateTimeFrom) |
|
85 |
->where('zaznam_cas.datetime_do', '<=', $dateTimeTo) |
|
86 |
->where('zaznam_cas.zarizeni_id', '=', $deviceId); |
|
87 |
|
|
88 |
if($direction != null) { |
|
89 |
$query = $query->where('zaznam_cas.smer', '=', $direction); |
|
90 |
} |
|
91 |
|
|
92 |
return $query->get(); |
|
93 |
} |
|
94 |
} |
backend/bootstrap/app.php | ||
---|---|---|
23 | 23 |
realpath(__DIR__.'/../') |
24 | 24 |
); |
25 | 25 |
|
26 |
// $app->withFacades();
|
|
26 |
$app->withFacades(); |
|
27 | 27 |
|
28 |
// $app->withEloquent();
|
|
28 |
$app->withEloquent(); |
|
29 | 29 |
|
30 | 30 |
/* |
31 | 31 |
|-------------------------------------------------------------------------- |
db/v3__vozidlo_rename.sql | ||
---|---|---|
1 |
-- prejmenovani tabulky vozidla |
|
2 |
rename table `prujezd_vozidel`.`vozidla` to `prujezd_vozidel`.`vozidlo`; |
|
3 |
|
|
4 |
-- update ciziho klice |
|
5 |
alter table `prujezd_vozidel`.`zaznam` change column `vozidla_id` `vozidlo_id` bigint(20); |
Také k dispozici: Unified diff
#6638: Prejmenovana tabulka vozidla na vozidlo. Pridana zbyla implementace rest api. Pridany zbyle modely.