Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 143e4121

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

#6638: Upraveno vyhledavani zarizeni podle adresy.

Zobrazit rozdíly:

backend/app/Http/Controllers/DeviceController.php
16 16
class DeviceController extends Controller
17 17
{
18 18
    public function getDevice(Request $request) {
19
        $town = null;
20
        $street = null;
19
        $address = null;
21 20
        $showDirection=0;
22 21
        if ($request->has('address')) {
23 22
            $address = $request->input('address');
24
            // todo: what is a format of address ?
25
            $addressParts = explode(";", $address);
26
            if (count($addressParts) == 2) {
27
                $town = $addressParts[0];
28
                $street = $addressParts[1];
29
            }
30 23
        }
31 24

  
32 25
        if ($request->has('showDirection')) {
33 26
            $showDirection = ($request->input('showDirection') === 1);
34 27
        }
35 28

  
36
        return Zarizeni::findByAddressJoinAddress($street, $town);
29
        return Zarizeni::findByAddressJoinAddress($address);
37 30
    }
38 31

  
39 32
    /**
backend/app/Model/Zarizeni.php
34 34
        return DB::table('zarizeni')
35 35
            ->join('ulice', 'zarizeni.ulice_id', '=', 'ulice.id')
36 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')
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')
38 43
            ->get();
39 44
    }
40 45

  
41 46
    /**
42 47
     * Vrati zarizeni nalezene podle adresy (mesto+ulice).
43
     * Mesto a ulice jsou vraceny spolu se zarizenim.
44 48
     *
45
     * @param $street Nazev ulice.
46
     * @param $town Nazev mesta.
49
     * @param $address Adresa, jsou vraceny zaznamy u kterych ulice, nebo mesto odpovida adrese.
47 50
     * @return mixed
48 51
     */
49
    public static function findByAddressJoinAddress($street, $town) {
52
    public static function findByAddressJoinAddress($address) {
50 53
        return DB::table('zarizeni')
51 54
            ->join('ulice', 'zarizeni.ulice_id', '=', 'ulice.id')
52 55
            ->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
            ->select('zarizeni.id as id',
57
                'zarizeni.smer_popis as name',
58
                'ulice.nazev as street',
59
                'ulice.id as street_id',
60
                'mesto.nazev as town',
61
                'mesto.id as town_id')
62
            ->where('ulice.nazev', 'like', '%'.$address.'%')
63
            ->orWhere('mesto.nazev', 'like', '%'.$address.'%')
56 64
            ->get();
57 65
    }
58 66

  

Také k dispozici: Unified diff