1 |
c66c7237
|
rizir01
|
<?php
|
2 |
|
|
|
3 |
|
|
namespace App\Http\Controllers;
|
4 |
|
|
|
5 |
|
|
use App\ArtefactUser;
|
6 |
1bcdcb05
|
Adam Mištera
|
use App\User;
|
7 |
c66c7237
|
rizir01
|
use Illuminate\Http\Request;
|
8 |
|
|
use App\Metadata;
|
9 |
|
|
use App\Artefact;
|
10 |
1bcdcb05
|
Adam Mištera
|
use Illuminate\Support\Facades\Auth;
|
11 |
c66c7237
|
rizir01
|
|
12 |
|
|
class DetailsController extends Controller
|
13 |
|
|
{
|
14 |
1bcdcb05
|
Adam Mištera
|
const ORDER_COLUMN = 'page';
|
15 |
|
|
|
16 |
21570473
|
Adam Mištera
|
public function __construct()
|
17 |
|
|
{
|
18 |
|
|
$this->middleware('auth');
|
19 |
|
|
}
|
20 |
|
|
|
21 |
c66c7237
|
rizir01
|
/**
|
22 |
|
|
* Display a listing of the resource.
|
23 |
|
|
*
|
24 |
|
|
* @return \Illuminate\Http\Response
|
25 |
|
|
*/
|
26 |
|
|
public function index()
|
27 |
|
|
{
|
28 |
|
|
$data = array(
|
29 |
|
|
'title' => 'Welcome to the MERLOT page',
|
30 |
|
|
);
|
31 |
|
|
//return view('index', compact('title'));
|
32 |
|
|
return view('index') -> with($data);
|
33 |
|
|
}
|
34 |
|
|
|
35 |
|
|
/**
|
36 |
|
|
* Display the specified resource.
|
37 |
|
|
*
|
38 |
|
|
* @param int $id
|
39 |
1bcdcb05
|
Adam Mištera
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
40 |
c66c7237
|
rizir01
|
*/
|
41 |
|
|
public function show($id)
|
42 |
|
|
{
|
43 |
1bcdcb05
|
Adam Mištera
|
if (is_null(Artefact::find($id)))
|
44 |
|
|
{
|
45 |
|
|
return view('detail.index', ['metadata' => []]);
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
$metadata = Artefact::find($id)->metadata()->orderBy(self::ORDER_COLUMN)->get();
|
49 |
|
|
foreach($metadata as $item)
|
50 |
|
|
{
|
51 |
|
|
$item['favourite'] = is_null(User::find(Auth::id())->likesMetadata()->find($item->id)) ? false : true;
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
return view('detail.index', ['metadata' => $metadata]);
|
55 |
c66c7237
|
rizir01
|
}
|
56 |
|
|
|
57 |
1bcdcb05
|
Adam Mištera
|
/**
|
58 |
|
|
* Likes metadata given by its id.
|
59 |
|
|
*
|
60 |
|
|
* @param $id int id of metadata
|
61 |
|
|
* @return \Illuminate\Http\RedirectResponse
|
62 |
|
|
*/
|
63 |
|
|
public function like($id)
|
64 |
|
|
{
|
65 |
|
|
$user = User::find(Auth::id());
|
66 |
|
|
$metadata = Metadata::find($id);
|
67 |
|
|
|
68 |
|
|
$user->likesMetadata()->attach($metadata);
|
69 |
|
|
|
70 |
|
|
return back()->withInput();
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
/**
|
74 |
|
|
* Unlikes metadata given by its id.
|
75 |
|
|
*
|
76 |
|
|
* @param $id int id of metadata
|
77 |
|
|
* @return \Illuminate\Http\RedirectResponse
|
78 |
|
|
*/
|
79 |
|
|
public function unlike($id)
|
80 |
|
|
{
|
81 |
|
|
$user = User::find(Auth::id());
|
82 |
|
|
$metadata = Metadata::find($id);
|
83 |
|
|
|
84 |
|
|
$user->likesMetadata()->detach($metadata);
|
85 |
|
|
|
86 |
|
|
return back()->withInput();
|
87 |
|
|
}
|
88 |
c66c7237
|
rizir01
|
}
|