Projekt

Obecné

Profil

« Předchozí | Další » 

Revize f71bf8bd

Přidáno uživatelem Cajova-Houba před asi 7 roky(ů)

refs #6842: Pridani rozliseni smeru do query pro ziskani zarizeni. Nazvy url parametru presunuty do konstant.

Zobrazit rozdíly:

backend/app/Http/Controllers/DeviceController.php
15 15

  
16 16
class DeviceController extends Controller
17 17
{
18
    // nazvy moznych url parametru
19
    const ADDRESS_PARAM = 'address';
20
    const SHOW_DIRECTION_PARAM = 'showDirection';
21
    const DATE_FROM_PARAM = 'dateFrom';
22
    const DATE_TO_PARAM = 'dateTo';
23
    const TIME_FROM_PARAM = 'timeFrom';
24
    const TIME_FROM_TO = 'timeTo';
25
    const DIRECTION_PARAM = 'direction';
26

  
27

  
18 28
    public function getDevice(Request $request) {
19 29
        $address = null;
20 30
        $showDirection=0;
21
        if ($request->has('address')) {
22
            $address = $request->input('address');
31
        if ($request->has(ADDRESS_PARAM)) {
32
            $address = $request->input(ADDRESS_PARAM);
23 33
        }
24 34

  
25
        if ($request->has('showDirection')) {
26
            $showDirection = ($request->input('showDirection') === 1);
35
        if ($request->has(SHOW_DIRECTION_PARAM) && $request->input(SHOW_DIRECTION_PARAM) == '1') {
36
            $showDirection = 1;
27 37
        }
28 38

  
29
        $device = Zarizeni::findByAddressJoinAddress($address);
39
        $device = Zarizeni::findByAddressJoinAddress($address, $showDirection);
30 40
        if ($device == null || count($device) == 0) {
31 41
            return response('Not found.', 404);
32 42
        }
......
56 66
        $direction = null;
57 67

  
58 68
        // nacti parametry
59
        if ($request->has('dateFrom')) {
60
            $dateFrom = $request->input('dateFrom');
69
        if ($request->has(DATE_FROM_PARAM)) {
70
            $dateFrom = $request->input(DATE_FROM_PARAM);
61 71
        }
62
        if ($request->has('dateTo')) {
63
            $dateTo = $request->input('dateTo');
72
        if ($request->has(DATE_TO_PARAM)) {
73
            $dateTo = $request->input(DATE_TO_PARAM);
64 74
        }
65
        if ($request->has('timeFrom')) {
66
            $timeFrom = $request->input('timeFrom');
75
        if ($request->has(TIME_FROM_PARAM)) {
76
            $timeFrom = $request->input(TIME_FROM_PARAM);
67 77
        }
68
        if ($request->has('timeTo')) {
69
            $timeTo = $request->input('timeTo');
78
        if ($request->has(TIME_TO_PARAM)) {
79
            $timeTo = $request->input(TIME_TO_PARAM);
70 80
        }
71
        if ($request->has('direction')) {
72
            $direction = $request->input('direction');
81
        if ($request->has(DIRECTION_PARAM)) {
82
            $direction = $request->input(DIRECTION_PARAM);
73 83
        }
74 84

  
75 85
        $device = Zarizeni::findByIdJoinAddress($id);
backend/app/Model/Zarizeni.php
47 47
     * Vrati zarizeni nalezene podle adresy (mesto+ulice).
48 48
     *
49 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í.
50 51
     * @return mixed
51 52
     */
52
    public static function findByAddressJoinAddress($address) {
53
        return DB::table('zarizeni')
53
    public static function findByAddressJoinAddress($address, $showDirection) {
54
        $query = DB::table('zarizeni')
54 55
            ->join('ulice', 'zarizeni.ulice_id', '=', 'ulice.id')
55 56
            ->join('mesto', 'ulice.mesto_id', '=', 'mesto.id')
56 57
            ->select('zarizeni.id as id',
......
60 61
                'mesto.nazev as town',
61 62
                'mesto.id as town_id')
62 63
            ->where('ulice.nazev', 'like', '%'.$address.'%')
63
            ->orWhere('mesto.nazev', 'like', '%'.$address.'%')
64
            ->get();
64
            ->orWhere('mesto.nazev', 'like', '%'.$address.'%');
65

  
66
        if (!$showDirection) {
67
            $query = $query->groupBy('zarizeni.ulice_id');
68
        }
69

  
70

  
71
        return $query->get();
65 72
    }
66 73

  
67 74
    /**

Také k dispozici: Unified diff