1 |
b50f8ebd
|
Cajova-Houba
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
* Created by PhpStorm.
|
4 |
|
|
* User: Zdenda
|
5 |
|
|
* Date: 22.4.2018
|
6 |
|
|
* Time: 20:21
|
7 |
|
|
*/
|
8 |
|
|
|
9 |
|
|
namespace App\Model;
|
10 |
|
|
|
11 |
|
|
use Illuminate\Support\Facades\DB;
|
12 |
|
|
|
13 |
|
|
/**
|
14 |
|
|
* Trida reprezentujici entitu zarizeni.
|
15 |
|
|
* @package App\Model
|
16 |
|
|
*/
|
17 |
|
|
class Zarizeni extends BaseModel
|
18 |
|
|
{
|
19 |
|
|
|
20 |
|
|
/**
|
21 |
|
|
* Jmeno tabulky v databazi.
|
22 |
|
|
*
|
23 |
|
|
* @var string
|
24 |
|
|
*/
|
25 |
|
|
protected $table = 'zarizeni';
|
26 |
|
|
|
27 |
|
|
/**
|
28 |
|
|
* Vrati vsechna zarizeni.
|
29 |
|
|
* Mesto a ulice jsou vraceny spolu se zarizenim.
|
30 |
|
|
*
|
31 |
|
|
* @return mixed
|
32 |
|
|
*/
|
33 |
01f99166
|
Jan Kohlíček
|
public static function getAllJoinAddress()
|
34 |
|
|
{
|
35 |
b50f8ebd
|
Cajova-Houba
|
return DB::table('zarizeni')
|
36 |
|
|
->join('ulice', 'zarizeni.ulice_id', '=', 'ulice.id')
|
37 |
|
|
->join('mesto', 'ulice.mesto_id', '=', 'mesto.id')
|
38 |
143e4121
|
Cajova-Houba
|
->select('zarizeni.id as id',
|
39 |
|
|
'zarizeni.smer_popis as name',
|
40 |
|
|
'ulice.nazev as street',
|
41 |
|
|
'ulice.id as street_id',
|
42 |
1adda1a9
|
Cajova-Houba
|
'ulice.zem_sirka as lat',
|
43 |
|
|
'ulice.zem_delka as lng',
|
44 |
143e4121
|
Cajova-Houba
|
'mesto.nazev as town',
|
45 |
|
|
'mesto.id as town_id')
|
46 |
b50f8ebd
|
Cajova-Houba
|
->get();
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
/**
|
50 |
|
|
* Vrati zarizeni nalezene podle adresy (mesto+ulice).
|
51 |
|
|
*
|
52 |
143e4121
|
Cajova-Houba
|
* @param $address Adresa, jsou vraceny zaznamy u kterych ulice, nebo mesto odpovida adrese.
|
53 |
f71bf8bd
|
Cajova-Houba
|
* @param $showDirection 1 pokud má být rozlišen směr zařízení.
|
54 |
b50f8ebd
|
Cajova-Houba
|
* @return mixed
|
55 |
|
|
*/
|
56 |
01f99166
|
Jan Kohlíček
|
public static function findByAddressJoinAddress($address, $showDirection)
|
57 |
|
|
{
|
58 |
cd5a5e83
|
Cajova-Houba
|
if (empty($address)) {
|
59 |
|
|
Zarizeni::getAllJoinAddress();
|
60 |
|
|
}
|
61 |
|
|
|
62 |
f71bf8bd
|
Cajova-Houba
|
$query = DB::table('zarizeni')
|
63 |
b50f8ebd
|
Cajova-Houba
|
->join('ulice', 'zarizeni.ulice_id', '=', 'ulice.id')
|
64 |
|
|
->join('mesto', 'ulice.mesto_id', '=', 'mesto.id')
|
65 |
fb12df6d
|
Jan Kohlíček
|
->select(DB::Raw('zarizeni.id as id,
|
66 |
|
|
zarizeni.smer_popis as name,
|
67 |
|
|
ulice.nazev as street,
|
68 |
|
|
ulice.id as street_id,
|
69 |
|
|
ulice.zem_sirka as lat,
|
70 |
|
|
ulice.zem_delka as lng,
|
71 |
|
|
mesto.nazev as town,
|
72 |
|
|
mesto.id as town_id,' .
|
73 |
|
|
($showDirection ? 'zaznam_cas.smer as direction' : 'null as direction')));
|
74 |
f71bf8bd
|
Cajova-Houba
|
|
75 |
fb12df6d
|
Jan Kohlíček
|
if (!empty($address)) {
|
76 |
|
|
$query = $query->where('ulice.nazev', 'like', '%' . $address . '%')
|
77 |
|
|
->orWhere('mesto.nazev', 'like', '%' . $address . '%')
|
78 |
|
|
->orWhere('zarizeni.smer_popis', 'like', '%' . $address . '%');
|
79 |
f71bf8bd
|
Cajova-Houba
|
}
|
80 |
|
|
|
81 |
fb12df6d
|
Jan Kohlíček
|
if ($showDirection) {
|
82 |
|
|
$query = $query->join('zaznam_cas', 'zaznam_cas.zarizeni_id', '=', 'zarizeni.id')
|
83 |
|
|
->groupBy('zarizeni.id', 'zaznam_cas.smer');
|
84 |
|
|
}
|
85 |
f71bf8bd
|
Cajova-Houba
|
|
86 |
|
|
return $query->get();
|
87 |
b50f8ebd
|
Cajova-Houba
|
}
|
88 |
|
|
|
89 |
|
|
/**
|
90 |
|
|
* Vrati zarizeni se zadanym id.
|
91 |
|
|
* Mesto a ulice jsou vraceny spolu se zarizenim.
|
92 |
|
|
*
|
93 |
|
|
* @param $id Id zarizeni.
|
94 |
|
|
* @return mixed
|
95 |
|
|
*/
|
96 |
01f99166
|
Jan Kohlíček
|
public static function findByIdJoinAddress($id)
|
97 |
|
|
{
|
98 |
b50f8ebd
|
Cajova-Houba
|
return DB::table('zarizeni')
|
99 |
|
|
->join('ulice', 'zarizeni.ulice_id', '=', 'ulice.id')
|
100 |
|
|
->join('mesto', 'ulice.mesto_id', '=', 'mesto.id')
|
101 |
4877913b
|
Cajova-Houba
|
->select('zarizeni.id as id',
|
102 |
|
|
'zarizeni.smer_popis as name',
|
103 |
|
|
'ulice.nazev as street',
|
104 |
|
|
'ulice.id as street_id',
|
105 |
1adda1a9
|
Cajova-Houba
|
'ulice.zem_sirka as lat',
|
106 |
|
|
'ulice.zem_delka as lng',
|
107 |
4877913b
|
Cajova-Houba
|
'mesto.nazev as town',
|
108 |
|
|
'mesto.id as town_id')
|
109 |
b50f8ebd
|
Cajova-Houba
|
->where('zarizeni.id', '=', $id)
|
110 |
d58f0fda
|
Cajova-Houba
|
->orderBy('zarizeni.id')
|
111 |
0b27c108
|
Jan Kohlíček
|
->first();
|
112 |
b50f8ebd
|
Cajova-Houba
|
}
|
113 |
|
|
|
114 |
|
|
/**
|
115 |
|
|
* Databazovy klic.
|
116 |
|
|
*
|
117 |
|
|
* @var long
|
118 |
|
|
*/
|
119 |
|
|
public $id;
|
120 |
|
|
|
121 |
|
|
/**
|
122 |
|
|
* Popis smeru zarizeni.
|
123 |
|
|
*
|
124 |
|
|
* @var string
|
125 |
|
|
*/
|
126 |
|
|
public $smer_popis;
|
127 |
|
|
|
128 |
|
|
/**
|
129 |
|
|
* Stav zarizeni.
|
130 |
|
|
*
|
131 |
|
|
* @var integer
|
132 |
|
|
*/
|
133 |
|
|
public $stav;
|
134 |
|
|
|
135 |
01f99166
|
Jan Kohlíček
|
public function ulice()
|
136 |
|
|
{
|
137 |
b50f8ebd
|
Cajova-Houba
|
return $this->belongsTo('App\Model\Ulice');
|
138 |
|
|
}
|
139 |
|
|
}
|