commit 609126cb19ab3145203f9c0cd51ddedc37179ae2
Author: rizir01 <themurrayms@seznam.cz>
Date:   Wed May 27 14:55:16 2020 +0200

    Uprava sjednoceni templatu pro "Artefacts"
    
    Uprava a sjednoceni vsech stranek (vyjma charts) na stejny design zobrazeni artefaktu podle 'books.blade'. Mezi upravene stranky patri: artefact, category, categories, favartefacts.

diff --git a/app/Http/Controllers/ArtefactController.php b/app/Http/Controllers/ArtefactController.php
index 6c29071..73ba1ba 100644
--- a/app/Http/Controllers/ArtefactController.php
+++ b/app/Http/Controllers/ArtefactController.php
@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
 
 use App\Artefact;
 use App\ArtefactCategory;
+use App\Category;
 use App\User;
 use Illuminate\Contracts\View\Factory;
 use Illuminate\Http\RedirectResponse;
@@ -20,13 +21,16 @@ class ArtefactController extends Controller
     }
 
     /**
-     * Returns view of all artefacts.
+     * Prepare all necessary data for shown Artefact.
+     * These are current count of likes, if it set to
+     * a favorites by a logged user and all metadata
+     * connected to the artefact.
      *
-     * @return Factory|View
+     * @param       $artefacts  all artefacts
+     * @return      mixed       modified artefacts
      */
-    public function default()
+    public function prepData($artefacts)
     {
-        $artefacts = Artefact::simplePaginate(1);
         foreach($artefacts as $artefact)
         {
             $artefact['likes'] = Artefact::find($artefact->id)->users()->count();
@@ -41,6 +45,18 @@ class ArtefactController extends Controller
             $artefact['metadata'] = $metadata;
         }
 
+        return $artefacts;
+    }
+
+    /**
+     * Returns view of all artefacts.
+     *
+     * @return Factory|View
+     */
+    public function default()
+    {
+        $artefacts = Artefact::simplePaginate(1);
+        $artefacts = $this->prepData($artefacts);
         return view('artefact.default', ['artefacts' => $artefacts]);
     }
 
@@ -52,33 +68,23 @@ class ArtefactController extends Controller
      */
     public function showCategory($id)
     {
-        $categoryArtefacts = ArtefactCategory::where('category_id', $id)->get();
-        if(count($categoryArtefacts) > 0)
-        {
-            $artefacts = array();
-            foreach($categoryArtefacts as $ar)
-            {
-                array_push($artefacts, Artefact::where('id', $ar->artefact_id)->get());
-            }
-            return view('artefact.category', ['artefacts' => $artefacts]);
-        }
-        else
-        {
-            return view('artefact.category', ['artefacts' => array()]);
-        }
+        $artefacts = Category::find($id)->artefacts()->simplePaginate(1);
+        $artefacts = $this->prepData($artefacts);
+        return view('artefact.default', ['artefacts' => $artefacts]);
     }
 
     /**
-     * Returns view of artefacts related to the chosen category
+     * Returns view of artefacts related to the chosen categories
      *
      * @param $id string with categories ids
      * @return Factory|View
      */
     public function showCategories($id)
     {
+        //Parsing text for individual ids of categories
         $textWithIds  = $id;
         $pieces = explode(",", $textWithIds);
-        $artefacts = array();
+        $arrStrToInt = array();
         for($i = 0;$i < count($pieces); $i++)
         {
             if($pieces[$i] == null || !strcmp($pieces[$i], ""))
@@ -86,24 +92,23 @@ class ArtefactController extends Controller
                 continue;
             }
 
-            $categoryArtefacts = ArtefactCategory::where('category_id', $pieces[$i])->get();
-            if(count($categoryArtefacts) > 0)
-            {
-                foreach($categoryArtefacts as $ar)
-                {
-                    array_push($artefacts, Artefact::where('id', $ar->artefact_id)->get());
-                }
-            }
+            array_push($arrStrToInt, (int)$pieces[$i]);
         }
 
-        if(count($artefacts) > 0)
+        //Creating array of all artefacts ids
+        $arrArtIds = array();
+        foreach($arrStrToInt as $cat)
         {
-            return view('artefact.category', ['artefacts' => $artefacts]);
-        }
-        else
-        {
-            return view('artefact.category', ['artefacts' => array()]);
+            $tmpArtefacts = Category::find($cat)->artefacts()->get();
+            foreach($tmpArtefacts as $art)
+            {
+                array_push($arrArtIds, $art->id);
+            }
         }
+
+        $artefacts = Artefact::whereIn('id', $arrArtIds)->simplePaginate(1);
+        $artefacts = $this->prepData($artefacts);
+        return view('artefact.default', ['artefacts' => $artefacts]);
     }
 
     /**
@@ -114,11 +119,10 @@ class ArtefactController extends Controller
      */
     public function view($id)
     {
-        $artefact = Artefact::find($id);
-        $artefact['likes'] = Artefact::find($id)->users()->count();
-        $artefact['favourite'] = is_null(User::find(Auth::id())->likesArtefacts()->find($id)) ? false : true;
-
-        return view('artefact.view', ['artefact' => $artefact]);
+        $artefact = Artefact::find($id)->simplePaginate(1);
+        $artefact = $this->prepData($artefact);
+        //return view('artefact.view', ['artefact' => $artefact]);
+        return view('artefact.default', ['artefacts' => $artefact]);
     }
 
     /**
diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php
index ba06e0a..d6ff69f 100644
--- a/app/Http/Controllers/Auth/RegisterController.php
+++ b/app/Http/Controllers/Auth/RegisterController.php
@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
 use App\Mail\RegisterMail;
 use App\Providers\RouteServiceProvider;
 use App\User;
+use Illuminate\Routing\UrlGenerator;
 use Illuminate\Foundation\Auth\RegistersUsers;
 use Illuminate\Support\Facades\Hash;
 use Illuminate\Support\Facades\Mail;
@@ -70,7 +71,8 @@ class RegisterController extends Controller
         $vowels = array("/", "\\");
         $stringHModified = str_replace($vowels, "", $stringH);
 
-        Mail::to($data['email'])->send(new RegisterMail("http://localhost/verify/". $stringHModified));
+        //Mail::to($data['email'])->send(new RegisterMail("http://localhost/verify/". $stringHModified));
+        Mail::to($data['email'])->send(new RegisterMail(url("/verify/") . "/" . $stringHModified));//http://localhost/register/verify/..
 
         return User::create([
             'name' => $data['name'],
diff --git a/app/Http/Controllers/FavoriteArtefactsController.php b/app/Http/Controllers/FavoriteArtefactsController.php
index 383ca9d..6d050d5 100644
--- a/app/Http/Controllers/FavoriteArtefactsController.php
+++ b/app/Http/Controllers/FavoriteArtefactsController.php
@@ -12,11 +12,38 @@ use Illuminate\View\View;
 
 class FavoriteArtefactsController extends Controller
 {
+    const ORDER_COLUMN = 'page';
+
     public function __construct()
     {
         $this->middleware('auth');
     }
 
+    /**
+     * Prepare all necessary data for shown Artefact.
+     * These are current count of likes, if it set to
+     * a favorites by a logged user and all metadata
+     * connected to the artefact.
+     *
+     * @param       $artefacts  all artefacts
+     * @return      mixed       modified artefacts
+     */
+    public function prepData($artefacts)
+    {
+        foreach($artefacts as $artefact)
+        {
+            $artefact['likes'] = Artefact::find($artefact->id)->users()->count();
+            $artefact['favourite'] = is_null(User::find(Auth::id())->likesArtefacts()->find($artefact->id)) ? false : true;
+            $metadata = Artefact::find($artefact->id)->metadata()->orderBy(self::ORDER_COLUMN)->get();
+            foreach ($metadata as $item)
+            {
+                $item['favourite'] = is_null(User::find(Auth::id())->likesMetadata()->find($item->id)) ? false : true;
+            }
+            $artefact['metadata'] = $metadata;
+        }
+        return $artefacts;
+    }
+
     /**
      * Display a listing of the resource.
      *
@@ -27,26 +54,13 @@ class FavoriteArtefactsController extends Controller
         if(Auth::check())
         {
             $id = Auth::id();
-            $artefacts = User::find($id)->likesArtefacts()->get();
-            foreach($artefacts as $item)
-            {
-                $item['likes'] = Artefact::find($item->id)->users()->count();
-            }
-
-            $data = array(
-                'title' => 'Favorite artefacts',
-                'user' => $id,
-                'artefacts' => $artefacts
-            );
-            return view('favartefacts.index') -> with($data);
+            $artefacts = User::find($id)->likesArtefacts()->simplePaginate(1);
+            $artefacts = $this->prepData($artefacts);
+            return view('artefact.default', ['artefacts' => $artefacts]);
         }
         else
         {
-            $data = array(
-                'title' => 'Welcome to the MERLOT page',
-            );
-            //return view('index', compact('title'));
-            return view('pages.index') -> with($data);
+            return view('pages.index');
         }
     }
 
@@ -58,20 +72,9 @@ class FavoriteArtefactsController extends Controller
      */
     public function show($id)
     {
-        $artefacts = User::find($id)->likesArtefacts()->get();
-        foreach($artefacts as $item)
-        {
-            $item['likes'] = Artefact::find($item->id)->users()->count();
-        }
-
-        $data = array(
-            'title' => 'Favorite artefacts',
-            'id' => $id,
-            'user' => User::find($id),
-            'userId' => Auth::id(),
-            'artefacts' => $artefacts
-        );
-        return view('favartefacts.index') -> with($data);
+        $artefacts = User::find($id)->likesArtefacts()->simplePaginate(1);
+        $artefacts = $this->prepData($artefacts);
+        return view('artefact.default', ['artefacts' => $artefacts]);
     }
 
 }
diff --git a/resources/sass/_custom.scss b/resources/sass/_custom.scss
index 54874b1..0941525 100644
--- a/resources/sass/_custom.scss
+++ b/resources/sass/_custom.scss
@@ -800,7 +800,7 @@ body {
     //VERIFY - main text
     .ver-text{
 
-        margin-top: 20pt    ;
+        margin-top: 50pt;
 
         h2{
             text-align: center;
