commit 097959268f0d60ff14f1fb4023fab74b9a40d6d3
Author: Adam Mištera <amistera@students.zcu.cz>
Date:   Fri Apr 17 15:31:11 2020 +0200

    Issue #7846 @3h
    [+] Vytvoření stránky oblíbených metadat
    [+] Refraktoring kódu, oprava objektů databáze
    [-] Odstranění nepotřebných objektů ArtefactCategory.php a ArtefactUser.php

diff --git a/app/ArtefactCategory.php b/app/ArtefactCategory.php
deleted file mode 100644
index b580cd3..0000000
--- a/app/ArtefactCategory.php
+++ /dev/null
@@ -1,24 +0,0 @@
-<?php
-
-namespace App;
-
-use Illuminate\Database\Eloquent\Model;
-
-class ArtefactCategory extends Model
-{
-    // Table Name
-    protected $table = 'artefact_category';//unnecessery?
-    // Primary Key
-    public $primaryKey = 'artefact_id';//unnecessery?
-
-    /**
-     * Indicates if the model should be timestamped.
-     *
-     * @var bool
-     */
-    public $timestamps = false;
-
-
-
-
-}
diff --git a/app/ArtefactUser.php b/app/ArtefactUser.php
deleted file mode 100644
index ca0a18c..0000000
--- a/app/ArtefactUser.php
+++ /dev/null
@@ -1,24 +0,0 @@
-<?php
-
-namespace App;
-
-use Illuminate\Database\Eloquent\Model;
-
-class ArtefactUser extends Model
-{
-    // Table Name
-    protected $table = 'artefact_user';//unnecessery?
-    // Primary Key
-    public $primaryKey = 'artefact_id';//unnecessery?
-
-    /**
-     * Indicates if the model should be timestamped.
-     *
-     * @var bool
-     */
-    public $timestamps = false;
-
-
-
-
-}
diff --git a/app/Http/Controllers/CategoriesController.php b/app/Http/Controllers/CategoriesController.php
index 463809c..314e60f 100644
--- a/app/Http/Controllers/CategoriesController.php
+++ b/app/Http/Controllers/CategoriesController.php
@@ -58,7 +58,7 @@ class CategoriesController extends Controller
             $categories = array();
             for($i = 1; $i <= $countCategory;$i++)
             {
-                array_push($categories, ArtefactCategory::where('category_id', $i)->get());
+                array_push($categories, Category::where('category_id', $i)->get());
             }
             $clusters = $this->calculateClusters($categories);
 
diff --git a/app/Http/Controllers/DetailsController.php b/app/Http/Controllers/DetailsController.php
index c2d0bf7..c9e45f5 100644
--- a/app/Http/Controllers/DetailsController.php
+++ b/app/Http/Controllers/DetailsController.php
@@ -39,7 +39,7 @@ class DetailsController extends Controller
         $data = array(
             'id' => $id,
             'arrArtefact' => Artefact::find($id),
-            'likes' => ArtefactUser::where('artefact_id', $id)->count(),
+            'likes' => Artefact::find($id)->users()->count(),
             'metadata' => Metadata::where('artefact_id', $id)->get()
         );
         return view('detail.index') -> with($data);
diff --git a/app/Http/Controllers/FavoriteArtefactsController.php b/app/Http/Controllers/FavoriteArtefactsController.php
index 986a8a5..6d5343d 100644
--- a/app/Http/Controllers/FavoriteArtefactsController.php
+++ b/app/Http/Controllers/FavoriteArtefactsController.php
@@ -21,20 +21,14 @@ class FavoriteArtefactsController extends Controller
      */
     public function index()
     {
-        if(isset(Auth::user()->id))
+        if(Auth::check())
         {
-            $userId = Auth::user()->id;
-            $list = ArtefactUser::where('user_id', $userId)->get();
-            $finalData = array();
-            foreach($list as $item)
-            {
-                array_push($finalData, Artefact::where('id', $item->artefact_id)->get());
-            }
+            $artefacts = User::find(Auth::id())->likesArtefacts()->get();
 
             $data = array(
                 'title' => 'Favorite artefacts',
-                'user' => User::find($userId),
-                'artefacts' => $finalData
+                'user' => Auth::user(),
+                'artefacts' => $artefacts
             );
             return view('favartefacts.index') -> with($data);
         }
@@ -56,19 +50,18 @@ class FavoriteArtefactsController extends Controller
      */
     public function show($id)
     {
-        $list = ArtefactUser::where('user_id', $id)->get();
-        $finalData = array();
-        foreach($list as $item)
+        $artefacts = [];
+        if (!is_null(User::find($id)))
         {
-            array_push($finalData, Artefact::where('id', $item->artefact_id)->get());
+            $artefacts = User::find($id)->likesArtefacts()->get();
         }
 
         $data = array(
             'title' => 'Favorite artefacts',
             'id' => $id,
-            'user' => User::find($id),
-            'userId' => Auth::user()->id,
-            'artefacts' => $finalData
+            'user' => Auth::user(),
+            'userId' => Auth::id(),
+            'artefacts' => $artefacts
         );
         return view('favartefacts.index') -> with($data);
     }
diff --git a/app/Http/Controllers/FavoriteMetadataController.php b/app/Http/Controllers/FavoriteMetadataController.php
new file mode 100644
index 0000000..0532f86
--- /dev/null
+++ b/app/Http/Controllers/FavoriteMetadataController.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Metadata;
+use App\User;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Auth;
+
+class FavoriteMetadataController extends Controller
+{
+    public function __construct()
+    {
+        $this->middleware('auth');
+    }
+
+    public function index()
+    {
+        $metadata = User::find(Auth::id())->likesMetadata()->get();
+
+        return view('favmetadata.index', ['metadata' => $metadata]);
+    }
+
+}
diff --git a/app/User.php b/app/User.php
index df7d69e..04182d3 100644
--- a/app/User.php
+++ b/app/User.php
@@ -47,7 +47,7 @@ class User extends Authenticatable
      */
     public function likesArtefacts()
     {
-        return $this->hasMany('App\Artefact');
+        return $this->belongsToMany('App\Artefact');
     }
 
     /**
@@ -55,6 +55,6 @@ class User extends Authenticatable
      */
     public function likesMetadata()
     {
-        return $this->hasMany('App\Metadata');
+        return $this->belongsToMany('App\Metadata');
     }
 }
diff --git a/public/images/Button_Arrow_Small.png b/public/images/Button_Arrow_Small.png
new file mode 100644
index 0000000..0870281
Binary files /dev/null and b/public/images/Button_Arrow_Small.png differ
diff --git a/public/js/app.js b/public/js/app.js
index ed8e575..4606f58 100644
--- a/public/js/app.js
+++ b/public/js/app.js
@@ -37119,8 +37119,8 @@ window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
 /*! no static exports found */
 /***/ (function(module, exports, __webpack_require__) {
 
-__webpack_require__(/*! D:\WorkSpaceASWI\task02\resources\js\app.js */"./resources/js/app.js");
-module.exports = __webpack_require__(/*! D:\WorkSpaceASWI\task02\resources\sass\app.scss */"./resources/sass/app.scss");
+__webpack_require__(/*! C:\Users\Adam\Documents\Dev\ASWI\aswi2020merlot\resources\js\app.js */"./resources/js/app.js");
+module.exports = __webpack_require__(/*! C:\Users\Adam\Documents\Dev\ASWI\aswi2020merlot\resources\sass\app.scss */"./resources/sass/app.scss");
 
 
 /***/ })
diff --git a/resources/views/favartefacts/index.blade.php b/resources/views/favartefacts/index.blade.php
index 8a0ffd6..586e2e6 100644
--- a/resources/views/favartefacts/index.blade.php
+++ b/resources/views/favartefacts/index.blade.php
@@ -29,8 +29,8 @@
                     <div class="card">
                         <svg class="bd-placeholder-img card-img-top" width="100%" height="180" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid slice" focusable="false" role="img" aria-label="Placeholder: Image cap"><title>Placeholder</title><rect width="100%" height="100%" fill="#868e96"></rect><text x="45%" y="50%" fill="#dee2e6" dy=".3em">Artefact image</text></svg>
                         <div class="card-body">
-                            <h5 class="card-title"><a href="{{ url('/artefact/' . $artefact[0]->id) }}">{{$artefact[0]->name}}</a> - {{$artefact[0]->author}}</h5>
-                            <h6 class="card-subtitle mb-2 text-muted">{{$artefact[0]->year}}, {{$artefact[0]->pages}} pages</h6>
+                            <h5 class="card-title"><a href="{{ url('/artefact/' . $artefact->id) }}">{{$artefact->name}}</a> - {{$artefact->author}}</h5>
+                            <h6 class="card-subtitle mb-2 text-muted">{{$artefact->year}}, {{$artefact->pages}} pages</h6>
                             <p class="card-text">
                                 Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
                                 Mauris dolor felis, sagittis at, luctus sed, aliquam non, tellus.
diff --git a/resources/views/favmetadata/index.blade.php b/resources/views/favmetadata/index.blade.php
new file mode 100644
index 0000000..50d70d8
--- /dev/null
+++ b/resources/views/favmetadata/index.blade.php
@@ -0,0 +1,46 @@
+@extends('layouts.app')
+
+@section('title', 'Favorite metadata')
+
+@section('breadcrumb')
+    <li class="breadcrumb-item"><a href="{{ url('/') }}">Home</a></li>
+    <li class="breadcrumb-item active" aria-current="page">Favorite metadata</li>
+@endsection
+
+@section('content')
+    <div class="jumbotron">
+        <div class="text-center">
+            <h1>Favorite metadata</h1>
+            <p>
+                Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
+                Mauris dolor felis, sagittis at, luctus sed, aliquam non, tellus.
+                Fusce tellus odio, dapibus id fermentum quis, suscipit id erat.
+                Morbi scelerisque luctus velit. Vivamus porttitor turpis ac leo.
+                Morbi scelerisque luctus velit.
+                Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+            </p>
+        </div>
+    </div>
+
+    <div class="metadata-area">
+        @if(count($metadata) > 0)
+            <ul class="list-group">
+                @foreach($metadata as $meta)
+                    <div class="note-area mb-3">
+                        <li class="list-group-item">
+                            On {{$meta->page}} page:<br>
+                            {{$meta->noteCZ}}<br>
+                            {{$meta->noteEN}}<br>
+                        </li>
+                    </div>
+                @endforeach
+            </ul>
+        @else
+            <ul class="list-group">
+                <li class="list-group-item">
+                    <h3>No notes for this BOOK were found!</h3>
+                </li>
+            </ul>
+        @endif
+    </div>
+@endsection
diff --git a/resources/views/inc/navbar.blade.php b/resources/views/inc/navbar.blade.php
index 3c25be8..6f54a0b 100644
--- a/resources/views/inc/navbar.blade.php
+++ b/resources/views/inc/navbar.blade.php
@@ -34,6 +34,8 @@
                         <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
                             <a class="dropdown-item" href="{{ url('/favartefacts') }}">Favorite artefacts</a>
 
+                            <a class="dropdown-item" href="{{ url('/favmetadata') }}">Favorite metadata</a>
+
                             <a class="dropdown-item" href="{{ route('logout') }}"
                                onclick="event.preventDefault();
                                                      document.getElementById('logout-form').submit();">
diff --git a/routes/web.php b/routes/web.php
index a2126bd..994b0dc 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -20,6 +20,7 @@ Route::get('/artefact/{id}', 'ArtefactController@view');
 Route::resource('/detail', 'DetailsController', array('only' => array('index', 'show')));
 Route::resource('/categories', 'CategoriesController', array('only' => array('index')));
 Route::resource('/favartefacts', 'FavoriteArtefactsController', array('only' => array('index', 'show')));
+Route::get('/favmetadata', 'FavoriteMetadataController@index');
 
 Auth::routes();
 
