1
|
<?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
|
public static function getAllJoinAddress() {
|
34
|
return DB::table('zarizeni')
|
35
|
->join('ulice', 'zarizeni.ulice_id', '=', 'ulice.id')
|
36
|
->join('mesto', 'ulice.mesto_id', '=', 'mesto.id')
|
37
|
->select('zarizeni.id as id',
|
38
|
'zarizeni.smer_popis as name',
|
39
|
'ulice.nazev as street',
|
40
|
'ulice.id as street_id',
|
41
|
'ulice.lat as lat',
|
42
|
'ulice.lng as lng',
|
43
|
'mesto.nazev as town',
|
44
|
'mesto.id as town_id')
|
45
|
->get();
|
46
|
}
|
47
|
|
48
|
/**
|
49
|
* Vrati zarizeni nalezene podle adresy (mesto+ulice).
|
50
|
*
|
51
|
* @param $address Adresa, jsou vraceny zaznamy u kterych ulice, nebo mesto odpovida adrese.
|
52
|
* @param $showDirection 1 pokud má být rozlišen směr zařízení.
|
53
|
* @return mixed
|
54
|
*/
|
55
|
public static function findByAddressJoinAddress($address, $showDirection) {
|
56
|
$query = DB::table('zarizeni')
|
57
|
->join('ulice', 'zarizeni.ulice_id', '=', 'ulice.id')
|
58
|
->join('mesto', 'ulice.mesto_id', '=', 'mesto.id')
|
59
|
->select('zarizeni.id as id',
|
60
|
'zarizeni.smer_popis as name',
|
61
|
'ulice.nazev as street',
|
62
|
'ulice.id as street_id',
|
63
|
'ulice.lat as lat',
|
64
|
'ulice.lng as lng',
|
65
|
'mesto.nazev as town',
|
66
|
'mesto.id as town_id')
|
67
|
->where('ulice.nazev', 'like', '%'.$address.'%')
|
68
|
->orWhere('mesto.nazev', 'like', '%'.$address.'%');
|
69
|
|
70
|
if (!$showDirection) {
|
71
|
$query = $query->groupBy('zarizeni.ulice_id');
|
72
|
}
|
73
|
|
74
|
|
75
|
return $query->get();
|
76
|
}
|
77
|
|
78
|
/**
|
79
|
* Vrati zarizeni se zadanym id.
|
80
|
* Mesto a ulice jsou vraceny spolu se zarizenim.
|
81
|
*
|
82
|
* @param $id Id zarizeni.
|
83
|
* @return mixed
|
84
|
*/
|
85
|
public static function findByIdJoinAddress($id) {
|
86
|
return DB::table('zarizeni')
|
87
|
->join('ulice', 'zarizeni.ulice_id', '=', 'ulice.id')
|
88
|
->join('mesto', 'ulice.mesto_id', '=', 'mesto.id')
|
89
|
->select('zarizeni.id as id',
|
90
|
'zarizeni.smer_popis as name',
|
91
|
'ulice.nazev as street',
|
92
|
'ulice.id as street_id',
|
93
|
'ulice.lat as lat',
|
94
|
'ulice.lng as lng',
|
95
|
'mesto.nazev as town',
|
96
|
'mesto.id as town_id')
|
97
|
->where('zarizeni.id', '=', $id)
|
98
|
->orderBy('zarizeni.id')
|
99
|
->get();
|
100
|
}
|
101
|
|
102
|
/**
|
103
|
* Databazovy klic.
|
104
|
*
|
105
|
* @var long
|
106
|
*/
|
107
|
public $id;
|
108
|
|
109
|
/**
|
110
|
* Popis smeru zarizeni.
|
111
|
*
|
112
|
* @var string
|
113
|
*/
|
114
|
public $smer_popis;
|
115
|
|
116
|
/**
|
117
|
* Stav zarizeni.
|
118
|
*
|
119
|
* @var integer
|
120
|
*/
|
121
|
public $stav;
|
122
|
|
123
|
public function ulice() {
|
124
|
return $this->belongsTo('App\Model\Ulice');
|
125
|
}
|
126
|
}
|