Projekt

Obecné

Profil

Stáhnout (2.61 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.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
            ->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.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
            ->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.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
            ->where('zarizeni.id', '=', $id)
72
            ->orderBy('zarizeni.id')
73
            ->get();
74
    }
75

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

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

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

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