commit b50f8ebd01c489973f96d29931eb038335125697
Author: Cajova-Houba <tkmushroomer@gmail.com>
Date:   Sun Apr 22 21:26:43 2018 +0200

    #6638: Vypnuti kontroly cizich klicu v sql script ktery nahrava data. Pridani entit mesto,ulice,zarizeni. Implementace api ktere vraci zarizeni s adresou.

diff --git a/backend/app/Http/Controllers/DeviceController.php b/backend/app/Http/Controllers/DeviceController.php
index 34dbe54..e65aba5 100644
--- a/backend/app/Http/Controllers/DeviceController.php
+++ b/backend/app/Http/Controllers/DeviceController.php
@@ -9,6 +9,7 @@
 namespace App\Http\Controllers;
 
 use App\Model\Device;
+use App\Model\Zarizeni;
 use Illuminate\Http\Request;
 
 class DeviceController extends Controller
@@ -30,7 +31,8 @@ class DeviceController extends Controller
         $device->street = $address;
         $device->town = $address;
 
-        return response()->json($device);
+//        return response()->json($device);
+        return Zarizeni::findByAddressJoinAddress('Česká Kubice', 'Česká Kubice');
     }
 
     /**
@@ -48,13 +50,10 @@ class DeviceController extends Controller
      */
     public function getDeviceById(Request $request, $id) {
 
+        return Zarizeni::findByIdJoinAddress($id);
+    }
 
-        $device = new Device();
-        $device->id = $id;
-        $device->name = 'device';
-        $device->street = 'street';
-        $device->town = 'town';
-
-        return response()->json($device);
+    public function getAll() {
+        return Zarizeni::getAllJoinAddress();
     }
 }
diff --git a/backend/app/Http/Controllers/LocationController.php b/backend/app/Http/Controllers/LocationController.php
index 9d086ce..dcca920 100644
--- a/backend/app/Http/Controllers/LocationController.php
+++ b/backend/app/Http/Controllers/LocationController.php
@@ -10,6 +10,7 @@ namespace App\Http\Controllers;
 
 
 use App\Model\Location;
+use App\Model\Mesto;
 
 class LocationController extends Controller
 {
@@ -33,4 +34,11 @@ class LocationController extends Controller
     {
         return response()->json(Location::withData(array("Česká Kubice, směr od Německa", "Česká Kubice", "Česká Kubice", "KP055", "5")));
     }
+
+    /**
+     * Vrati vsechna mesta.
+     */
+    public function getCities() {
+        return Mesto::with('zarizeni')->get();
+    }
 }
\ No newline at end of file
diff --git a/backend/app/Http/routes.php b/backend/app/Http/routes.php
index 42c91f0..71c94c4 100644
--- a/backend/app/Http/routes.php
+++ b/backend/app/Http/routes.php
@@ -24,6 +24,8 @@ $app->get('/', function ()  {
  */
 $app->get($apiUrlRoot.'devices', 'DeviceController@getDevice');
 
+$app->get($apiUrlRoot.'devices/all', 'DeviceController@getAll');
+
 /**
  * Parametry v url:
  * dateFrom
@@ -38,3 +40,6 @@ $app->get($apiUrlRoot.'devices/{id}', 'DeviceController@getDeviceById');
  * Vrati vsechny typy aut.
  */
 $app->get($apiUrlRoot.'vehicles', 'VehicleController@getAll');
+
+$app->get($apiUrlRoot.'cities', 'LocationController@getCities');
+
diff --git a/backend/app/Model/BaseModel.php b/backend/app/Model/BaseModel.php
new file mode 100644
index 0000000..349643e
--- /dev/null
+++ b/backend/app/Model/BaseModel.php
@@ -0,0 +1,25 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Zdenda
+ * Date: 22.4.2018
+ * Time: 20:05
+ */
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Zakladni trida pro vsechny modely pouzite v projektu.
+ * Obsahuje konfiguraci spolecnou pro vsechny modely (zatim jen $timestamps).
+ *
+ * @package App\Model
+ */
+class BaseModel extends Model
+{
+    /**
+     * Kvuli ORM frameworku, aby nepredpokladal existenci sloupcu
+     */
+    public $timestamps = false;
+}
\ No newline at end of file
diff --git a/backend/app/Model/Mesto.php b/backend/app/Model/Mesto.php
new file mode 100644
index 0000000..2b8a2e8
--- /dev/null
+++ b/backend/app/Model/Mesto.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Zdenda
+ * Date: 22.4.2018
+ * Time: 19:51
+ */
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Entita reprezentujici tabulku mesto v databazi.
+ * @package App\Model
+ */
+class Mesto extends BaseModel
+{
+    /**
+     * Nazev tabulky tak jak je v databazi.
+     *
+     * @var string
+     */
+    protected $table = 'mesto';
+
+    /**
+     * Databazovy klic.
+     */
+    public $id;
+
+    /**
+     * Nazev mesta.
+     */
+    public $nazev;
+
+    /**
+     * Ulice prirazene mestu.
+     */
+    public function ulice() {
+        return $this->hasMany('App\Model\Ulice');
+    }
+
+    public function zarizeni() {
+        return $this->hasManyThrough('App\Model\Zarizeni', 'App\Model\Ulice');
+    }
+}
\ No newline at end of file
diff --git a/backend/app/Model/Ulice.php b/backend/app/Model/Ulice.php
new file mode 100644
index 0000000..051bbb0
--- /dev/null
+++ b/backend/app/Model/Ulice.php
@@ -0,0 +1,47 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Zdenda
+ * Date: 22.4.2018
+ * Time: 20:08
+ */
+
+namespace App\Model;
+
+
+/**
+ * Trida reprezentujici entitu ulice.
+ * @package App\Model
+ */
+class Ulice extends BaseModel
+{
+    /**
+     * Nazev tabulky.
+     * @var string
+     */
+    protected $table = 'ulice';
+
+    /**
+     * Databazovy klic.
+     */
+    public $id;
+
+    /**
+     * Nazev ulice.
+     */
+    public $nazev;
+
+    /**
+     * 1:N relace s entitou mesto.
+     *
+     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+     */
+    public function mesto() {
+        return $this->belongsTo('App\Model\Mesto');
+    }
+
+
+    public function zarizeni() {
+        return $this->hasMany('App\Model\Zarizeni');
+    }
+}
\ No newline at end of file
diff --git a/backend/app/Model/Zarizeni.php b/backend/app/Model/Zarizeni.php
new file mode 100644
index 0000000..646dff6
--- /dev/null
+++ b/backend/app/Model/Zarizeni.php
@@ -0,0 +1,99 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Zdenda
+ * Date: 22.4.2018
+ * Time: 20:21
+ */
+
+namespace App\Model;
+
+use Illuminate\Support\Facades\DB;
+
+/**
+ * Trida reprezentujici entitu zarizeni.
+ * @package App\Model
+ */
+class Zarizeni extends BaseModel
+{
+
+    /**
+     * Jmeno tabulky v databazi.
+     *
+     * @var string
+     */
+    protected $table = 'zarizeni';
+
+    /**
+     * Vrati vsechna zarizeni.
+     * Mesto a ulice jsou vraceny spolu se zarizenim.
+     *
+     * @return mixed
+     */
+    public static function getAllJoinAddress() {
+        return DB::table('zarizeni')
+            ->join('ulice', 'zarizeni.ulice_id', '=', 'ulice.id')
+            ->join('mesto', 'ulice.mesto_id', '=', 'mesto.id')
+            ->select('zarizeni.*', 'ulice.nazev as ulice_nazev', 'ulice.id as ulice_id', 'mesto.nazev as mesto_nazev', 'mesto.id as mesto_id')
+            ->get();
+    }
+
+    /**
+     * Vrati zarizeni nalezene podle adresy (mesto+ulice).
+     * Mesto a ulice jsou vraceny spolu se zarizenim.
+     *
+     * @param $street Nazev ulice.
+     * @param $town Nazev mesta.
+     * @return mixed
+     */
+    public static function findByAddressJoinAddress($street, $town) {
+        return DB::table('zarizeni')
+            ->join('ulice', 'zarizeni.ulice_id', '=', 'ulice.id')
+            ->join('mesto', 'ulice.mesto_id', '=', 'mesto.id')
+            ->select('zarizeni.*', 'ulice.nazev as ulice_nazev', 'ulice.id as ulice_id', 'mesto.nazev as mesto_nazev', 'mesto.id as mesto_id')
+            ->where('ulice.nazev', '=', $street)
+            ->where('mesto.nazev', '=', $town)
+            ->get();
+    }
+
+    /**
+     * Vrati zarizeni se zadanym id.
+     * Mesto a ulice jsou vraceny spolu se zarizenim.
+     *
+     * @param $id Id zarizeni.
+     * @return mixed
+     */
+    public static function findByIdJoinAddress($id) {
+        return DB::table('zarizeni')
+            ->join('ulice', 'zarizeni.ulice_id', '=', 'ulice.id')
+            ->join('mesto', 'ulice.mesto_id', '=', 'mesto.id')
+            ->select('zarizeni.*', 'ulice.nazev as ulice_nazev', 'ulice.id as ulice_id', 'mesto.nazev as mesto_nazev', 'mesto.id as mesto_id')
+            ->where('zarizeni.id', '=', $id)
+            ->get();
+    }
+
+    /**
+     * Databazovy klic.
+     *
+     * @var long
+     */
+    public $id;
+
+    /**
+     * Popis smeru zarizeni.
+     *
+     * @var string
+     */
+    public $smer_popis;
+
+    /**
+     * Stav zarizeni.
+     *
+     * @var integer
+     */
+    public $stav;
+
+    public function ulice() {
+        return $this->belongsTo('App\Model\Ulice');
+    }
+}
\ No newline at end of file
diff --git a/db/v2__10_04_2018.sql b/db/v2__10_04_2018.sql
index 62e34c6..90456d7 100644
--- a/db/v2__10_04_2018.sql
+++ b/db/v2__10_04_2018.sql
@@ -9,7 +9,7 @@
 
 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
 SET time_zone = "+00:00";
-
+SET FOREIGN_KEY_CHECKS=0;
 
 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
 /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
@@ -22,15 +22,6 @@ SET time_zone = "+00:00";
 
 -- --------------------------------------------------------
 
---
--- Struktura tabulky `mesto`
---
-
-CREATE TABLE IF NOT EXISTS `mesto` (
-  `id` bigint(20) NOT NULL AUTO_INCREMENT,
-  `nazev` varchar(100) NOT NULL,
-  PRIMARY KEY (`id`)
-) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=57 ;
 
 --
 -- Vypisuji data pro tabulku `mesto`
@@ -96,18 +87,6 @@ INSERT INTO `mesto` (`id`, `nazev`) VALUES
 
 -- --------------------------------------------------------
 
---
--- Struktura tabulky `ulice`
---
-
-CREATE TABLE IF NOT EXISTS `ulice` (
-  `id` bigint(20) NOT NULL AUTO_INCREMENT,
-  `nazev` varchar(255) NOT NULL,
-  `mesto_id` bigint(20) NOT NULL,
-  PRIMARY KEY (`id`),
-  KEY `fk_ulice_mesto_idx` (`mesto_id`)
-) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=88 ;
-
 --
 -- Vypisuji data pro tabulku `ulice`
 --
@@ -203,16 +182,6 @@ INSERT INTO `ulice` (`id`, `nazev`, `mesto_id`) VALUES
 
 -- --------------------------------------------------------
 
---
--- Struktura tabulky `vozidla`
---
-
-CREATE TABLE IF NOT EXISTS `vozidla` (
-  `id` bigint(20) NOT NULL COMMENT 'Odpovídá číslu skupiny vozidla (TypVozidla10 v csv souboru s daty). Hodnoty 0-10.',
-  `nazev` varchar(45) NOT NULL,
-  PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
 --
 -- Vypisuji data pro tabulku `vozidla`
 --
@@ -232,19 +201,6 @@ INSERT INTO `vozidla` (`id`, `nazev`) VALUES
 
 -- --------------------------------------------------------
 
---
--- Struktura tabulky `zarizeni`
---
-
-CREATE TABLE IF NOT EXISTS `zarizeni` (
-  `id` varchar(20) NOT NULL COMMENT 'Odpovídá idDevice v location.csv.',
-  `smer_popis` varchar(255) NOT NULL COMMENT 'Odpovídá Name v locations.csv.',
-  `stav` int(11) NOT NULL,
-  `ulice_id` bigint(20) NOT NULL,
-  PRIMARY KEY (`id`),
-  KEY `fk_zarizeni_ulice1_idx` (`ulice_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
 --
 -- Vypisuji data pro tabulku `zarizeni`
 --
@@ -356,21 +312,6 @@ INSERT INTO `zarizeni` (`id`, `smer_popis`, `stav`, `ulice_id`) VALUES
 
 -- --------------------------------------------------------
 
---
--- Struktura tabulky `zaznam`
---
-
-CREATE TABLE IF NOT EXISTS `zaznam` (
-  `id` bigint(20) NOT NULL AUTO_INCREMENT,
-  `vozidla_pocet` int(11) NOT NULL,
-  `rychlost_prumer` double NOT NULL,
-  `vozidla_id` bigint(20) NOT NULL,
-  `zaznam_cas_id` bigint(20) NOT NULL,
-  PRIMARY KEY (`id`),
-  KEY `fk_zaznam_vozidla1_idx` (`vozidla_id`),
-  KEY `fk_zaznam_zaznam_cas1_idx` (`zaznam_cas_id`)
-) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=39000 ;
-
 --
 -- Vypisuji data pro tabulku `zaznam`
 --
@@ -39401,20 +39342,6 @@ INSERT INTO `zaznam` (`id`, `vozidla_pocet`, `rychlost_prumer`, `vozidla_id`, `z
 
 -- --------------------------------------------------------
 
---
--- Struktura tabulky `zaznam_cas`
---
-
-CREATE TABLE IF NOT EXISTS `zaznam_cas` (
-  `id` bigint(20) NOT NULL AUTO_INCREMENT,
-  `datetime_od` datetime NOT NULL,
-  `datetime_do` datetime NOT NULL,
-  `smer` int(11) NOT NULL COMMENT '1 nebo 2 viz struktura idDetektor v csv souboru s daty.',
-  `zarizeni_id` varchar(20) NOT NULL,
-  PRIMARY KEY (`id`),
-  KEY `fk_zaznam_cas_zarizeni1_idx` (`zarizeni_id`)
-) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=17055 ;
-
 --
 -- Vypisuji data pro tabulku `zaznam_cas`
 --
@@ -56496,35 +56423,9 @@ INSERT INTO `zaznam_cas` (`id`, `datetime_od`, `datetime_do`, `smer`, `zarizeni_
 (17053, '2018-04-10 23:15:00', '2018-04-10 23:30:00', 1, '202'),
 (17054, '2018-04-10 23:45:00', '2018-04-11 00:00:00', 2, '202');
 
---
--- Omezení pro exportované tabulky
---
-
---
--- Omezení pro tabulku `ulice`
---
-ALTER TABLE `ulice`
-  ADD CONSTRAINT `fk_ulice_mesto` FOREIGN KEY (`mesto_id`) REFERENCES `mesto` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;
-
---
--- Omezení pro tabulku `zarizeni`
---
-ALTER TABLE `zarizeni`
-  ADD CONSTRAINT `fk_zarizeni_ulice1` FOREIGN KEY (`ulice_id`) REFERENCES `ulice` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;
-
---
--- Omezení pro tabulku `zaznam`
---
-ALTER TABLE `zaznam`
-  ADD CONSTRAINT `fk_zaznam_vozidla1` FOREIGN KEY (`vozidla_id`) REFERENCES `vozidla` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
-  ADD CONSTRAINT `fk_zaznam_zaznam_cas1` FOREIGN KEY (`zaznam_cas_id`) REFERENCES `zaznam_cas` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;
-
---
--- Omezení pro tabulku `zaznam_cas`
---
-ALTER TABLE `zaznam_cas`
-  ADD CONSTRAINT `fk_zaznam_cas_zarizeni1` FOREIGN KEY (`zarizeni_id`) REFERENCES `zarizeni` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;
 
+  
+SET FOREIGN_KEY_CHECKS=1;
 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
 /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
