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