Projekt

Obecné

Profil

Stáhnout (2.5 KB) Statistiky
| Větev: | Revize:
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.*', 'ulice.nazev as ulice_nazev', 'ulice.id as ulice_id', 'mesto.nazev as mesto_nazev', 'mesto.id as mesto_id')
38
            ->get();
39
    }
40

    
41
    /**
42
     * Vrati zarizeni nalezene podle adresy (mesto+ulice).
43
     * Mesto a ulice jsou vraceny spolu se zarizenim.
44
     *
45
     * @param $street Nazev ulice.
46
     * @param $town Nazev mesta.
47
     * @return mixed
48
     */
49
    public static function findByAddressJoinAddress($street, $town) {
50
        return DB::table('zarizeni')
51
            ->join('ulice', 'zarizeni.ulice_id', '=', 'ulice.id')
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')
54
            ->where('ulice.nazev', '=', $street)
55
            ->where('mesto.nazev', '=', $town)
56
            ->get();
57
    }
58

    
59
    /**
60
     * Vrati zarizeni se zadanym id.
61
     * Mesto a ulice jsou vraceny spolu se zarizenim.
62
     *
63
     * @param $id Id zarizeni.
64
     * @return mixed
65
     */
66
    public static function findByIdJoinAddress($id) {
67
        return DB::table('zarizeni')
68
            ->join('ulice', 'zarizeni.ulice_id', '=', 'ulice.id')
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')
71
            ->where('zarizeni.id', '=', $id)
72
            ->get();
73
    }
74

    
75
    /**
76
     * Databazovy klic.
77
     *
78
     * @var long
79
     */
80
    public $id;
81

    
82
    /**
83
     * Popis smeru zarizeni.
84
     *
85
     * @var string
86
     */
87
    public $smer_popis;
88

    
89
    /**
90
     * Stav zarizeni.
91
     *
92
     * @var integer
93
     */
94
    public $stav;
95

    
96
    public function ulice() {
97
        return $this->belongsTo('App\Model\Ulice');
98
    }
99
}
(7-7/7)