commit f71bf8bd194fde267e1a2e19a0e86da1157b88a5
Author: Cajova-Houba <tkmushroomer@gmail.com>
Date:   Sat May 12 09:42:12 2018 +0200

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

diff --git a/backend/app/Http/Controllers/DeviceController.php b/backend/app/Http/Controllers/DeviceController.php
index 05a5113..8903d9b 100644
--- a/backend/app/Http/Controllers/DeviceController.php
+++ b/backend/app/Http/Controllers/DeviceController.php
@@ -15,18 +15,28 @@ use Illuminate\Http\Request;
 
 class DeviceController extends Controller
 {
+    // nazvy moznych url parametru
+    const ADDRESS_PARAM = 'address';
+    const SHOW_DIRECTION_PARAM = 'showDirection';
+    const DATE_FROM_PARAM = 'dateFrom';
+    const DATE_TO_PARAM = 'dateTo';
+    const TIME_FROM_PARAM = 'timeFrom';
+    const TIME_FROM_TO = 'timeTo';
+    const DIRECTION_PARAM = 'direction';
+
+
     public function getDevice(Request $request) {
         $address = null;
         $showDirection=0;
-        if ($request->has('address')) {
-            $address = $request->input('address');
+        if ($request->has(ADDRESS_PARAM)) {
+            $address = $request->input(ADDRESS_PARAM);
         }
 
-        if ($request->has('showDirection')) {
-            $showDirection = ($request->input('showDirection') === 1);
+        if ($request->has(SHOW_DIRECTION_PARAM) && $request->input(SHOW_DIRECTION_PARAM) == '1') {
+            $showDirection = 1;
         }
 
-        $device = Zarizeni::findByAddressJoinAddress($address);
+        $device = Zarizeni::findByAddressJoinAddress($address, $showDirection);
         if ($device == null || count($device) == 0) {
             return response('Not found.', 404);
         }
@@ -56,20 +66,20 @@ class DeviceController extends Controller
         $direction = null;
 
         // nacti parametry
-        if ($request->has('dateFrom')) {
-            $dateFrom = $request->input('dateFrom');
+        if ($request->has(DATE_FROM_PARAM)) {
+            $dateFrom = $request->input(DATE_FROM_PARAM);
         }
-        if ($request->has('dateTo')) {
-            $dateTo = $request->input('dateTo');
+        if ($request->has(DATE_TO_PARAM)) {
+            $dateTo = $request->input(DATE_TO_PARAM);
         }
-        if ($request->has('timeFrom')) {
-            $timeFrom = $request->input('timeFrom');
+        if ($request->has(TIME_FROM_PARAM)) {
+            $timeFrom = $request->input(TIME_FROM_PARAM);
         }
-        if ($request->has('timeTo')) {
-            $timeTo = $request->input('timeTo');
+        if ($request->has(TIME_TO_PARAM)) {
+            $timeTo = $request->input(TIME_TO_PARAM);
         }
-        if ($request->has('direction')) {
-            $direction = $request->input('direction');
+        if ($request->has(DIRECTION_PARAM)) {
+            $direction = $request->input(DIRECTION_PARAM);
         }
 
         $device = Zarizeni::findByIdJoinAddress($id);
diff --git a/backend/app/Model/Zarizeni.php b/backend/app/Model/Zarizeni.php
index db64338..e5e0400 100644
--- a/backend/app/Model/Zarizeni.php
+++ b/backend/app/Model/Zarizeni.php
@@ -47,10 +47,11 @@ class Zarizeni extends BaseModel
      * Vrati zarizeni nalezene podle adresy (mesto+ulice).
      *
      * @param $address Adresa, jsou vraceny zaznamy u kterych ulice, nebo mesto odpovida adrese.
+     * @param $showDirection 1 pokud má být rozlišen směr zařízení.
      * @return mixed
      */
-    public static function findByAddressJoinAddress($address) {
-        return DB::table('zarizeni')
+    public static function findByAddressJoinAddress($address, $showDirection) {
+        $query = DB::table('zarizeni')
             ->join('ulice', 'zarizeni.ulice_id', '=', 'ulice.id')
             ->join('mesto', 'ulice.mesto_id', '=', 'mesto.id')
             ->select('zarizeni.id as id',
@@ -60,8 +61,14 @@ class Zarizeni extends BaseModel
                 'mesto.nazev as town',
                 'mesto.id as town_id')
             ->where('ulice.nazev', 'like', '%'.$address.'%')
-            ->orWhere('mesto.nazev', 'like', '%'.$address.'%')
-            ->get();
+            ->orWhere('mesto.nazev', 'like', '%'.$address.'%');
+
+        if (!$showDirection) {
+            $query = $query->groupBy('zarizeni.ulice_id');
+        }
+
+
+        return $query->get();
     }
 
     /**
