Revize 09795926
Přidáno uživatelem Adam Mištera před téměř 5 roky(ů)
app/ArtefactCategory.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
namespace App; |
|
4 |
|
|
5 |
use Illuminate\Database\Eloquent\Model; |
|
6 |
|
|
7 |
class ArtefactCategory extends Model |
|
8 |
{ |
|
9 |
// Table Name |
|
10 |
protected $table = 'artefact_category';//unnecessery? |
|
11 |
// Primary Key |
|
12 |
public $primaryKey = 'artefact_id';//unnecessery? |
|
13 |
|
|
14 |
/** |
|
15 |
* Indicates if the model should be timestamped. |
|
16 |
* |
|
17 |
* @var bool |
|
18 |
*/ |
|
19 |
public $timestamps = false; |
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
} |
app/ArtefactUser.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
namespace App; |
|
4 |
|
|
5 |
use Illuminate\Database\Eloquent\Model; |
|
6 |
|
|
7 |
class ArtefactUser extends Model |
|
8 |
{ |
|
9 |
// Table Name |
|
10 |
protected $table = 'artefact_user';//unnecessery? |
|
11 |
// Primary Key |
|
12 |
public $primaryKey = 'artefact_id';//unnecessery? |
|
13 |
|
|
14 |
/** |
|
15 |
* Indicates if the model should be timestamped. |
|
16 |
* |
|
17 |
* @var bool |
|
18 |
*/ |
|
19 |
public $timestamps = false; |
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
} |
app/Http/Controllers/CategoriesController.php | ||
---|---|---|
58 | 58 |
$categories = array(); |
59 | 59 |
for($i = 1; $i <= $countCategory;$i++) |
60 | 60 |
{ |
61 |
array_push($categories, ArtefactCategory::where('category_id', $i)->get());
|
|
61 |
array_push($categories, Category::where('category_id', $i)->get()); |
|
62 | 62 |
} |
63 | 63 |
$clusters = $this->calculateClusters($categories); |
64 | 64 |
|
app/Http/Controllers/DetailsController.php | ||
---|---|---|
39 | 39 |
$data = array( |
40 | 40 |
'id' => $id, |
41 | 41 |
'arrArtefact' => Artefact::find($id), |
42 |
'likes' => ArtefactUser::where('artefact_id', $id)->count(),
|
|
42 |
'likes' => Artefact::find($id)->users()->count(),
|
|
43 | 43 |
'metadata' => Metadata::where('artefact_id', $id)->get() |
44 | 44 |
); |
45 | 45 |
return view('detail.index') -> with($data); |
app/Http/Controllers/FavoriteArtefactsController.php | ||
---|---|---|
21 | 21 |
*/ |
22 | 22 |
public function index() |
23 | 23 |
{ |
24 |
if(isset(Auth::user()->id))
|
|
24 |
if(Auth::check())
|
|
25 | 25 |
{ |
26 |
$userId = Auth::user()->id; |
|
27 |
$list = ArtefactUser::where('user_id', $userId)->get(); |
|
28 |
$finalData = array(); |
|
29 |
foreach($list as $item) |
|
30 |
{ |
|
31 |
array_push($finalData, Artefact::where('id', $item->artefact_id)->get()); |
|
32 |
} |
|
26 |
$artefacts = User::find(Auth::id())->likesArtefacts()->get(); |
|
33 | 27 |
|
34 | 28 |
$data = array( |
35 | 29 |
'title' => 'Favorite artefacts', |
36 |
'user' => User::find($userId),
|
|
37 |
'artefacts' => $finalData
|
|
30 |
'user' => Auth::user(),
|
|
31 |
'artefacts' => $artefacts
|
|
38 | 32 |
); |
39 | 33 |
return view('favartefacts.index') -> with($data); |
40 | 34 |
} |
... | ... | |
56 | 50 |
*/ |
57 | 51 |
public function show($id) |
58 | 52 |
{ |
59 |
$list = ArtefactUser::where('user_id', $id)->get(); |
|
60 |
$finalData = array(); |
|
61 |
foreach($list as $item) |
|
53 |
$artefacts = []; |
|
54 |
if (!is_null(User::find($id))) |
|
62 | 55 |
{ |
63 |
array_push($finalData, Artefact::where('id', $item->artefact_id)->get());
|
|
56 |
$artefacts = User::find($id)->likesArtefacts()->get();
|
|
64 | 57 |
} |
65 | 58 |
|
66 | 59 |
$data = array( |
67 | 60 |
'title' => 'Favorite artefacts', |
68 | 61 |
'id' => $id, |
69 |
'user' => User::find($id),
|
|
70 |
'userId' => Auth::user()->id,
|
|
71 |
'artefacts' => $finalData
|
|
62 |
'user' => Auth::user(),
|
|
63 |
'userId' => Auth::id(),
|
|
64 |
'artefacts' => $artefacts
|
|
72 | 65 |
); |
73 | 66 |
return view('favartefacts.index') -> with($data); |
74 | 67 |
} |
app/Http/Controllers/FavoriteMetadataController.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
namespace App\Http\Controllers; |
|
4 |
|
|
5 |
use App\Metadata; |
|
6 |
use App\User; |
|
7 |
use Illuminate\Http\Request; |
|
8 |
use Illuminate\Support\Facades\Auth; |
|
9 |
|
|
10 |
class FavoriteMetadataController extends Controller |
|
11 |
{ |
|
12 |
public function __construct() |
|
13 |
{ |
|
14 |
$this->middleware('auth'); |
|
15 |
} |
|
16 |
|
|
17 |
public function index() |
|
18 |
{ |
|
19 |
$metadata = User::find(Auth::id())->likesMetadata()->get(); |
|
20 |
|
|
21 |
return view('favmetadata.index', ['metadata' => $metadata]); |
|
22 |
} |
|
23 |
|
|
24 |
} |
app/User.php | ||
---|---|---|
47 | 47 |
*/ |
48 | 48 |
public function likesArtefacts() |
49 | 49 |
{ |
50 |
return $this->hasMany('App\Artefact');
|
|
50 |
return $this->belongsToMany('App\Artefact');
|
|
51 | 51 |
} |
52 | 52 |
|
53 | 53 |
/** |
... | ... | |
55 | 55 |
*/ |
56 | 56 |
public function likesMetadata() |
57 | 57 |
{ |
58 |
return $this->hasMany('App\Metadata');
|
|
58 |
return $this->belongsToMany('App\Metadata');
|
|
59 | 59 |
} |
60 | 60 |
} |
public/js/app.js | ||
---|---|---|
37119 | 37119 |
/*! no static exports found */ |
37120 | 37120 |
/***/ (function(module, exports, __webpack_require__) { |
37121 | 37121 |
|
37122 |
__webpack_require__(/*! D:\WorkSpaceASWI\task02\resources\js\app.js */"./resources/js/app.js");
|
|
37123 |
module.exports = __webpack_require__(/*! D:\WorkSpaceASWI\task02\resources\sass\app.scss */"./resources/sass/app.scss");
|
|
37122 |
__webpack_require__(/*! C:\Users\Adam\Documents\Dev\ASWI\aswi2020merlot\resources\js\app.js */"./resources/js/app.js");
|
|
37123 |
module.exports = __webpack_require__(/*! C:\Users\Adam\Documents\Dev\ASWI\aswi2020merlot\resources\sass\app.scss */"./resources/sass/app.scss");
|
|
37124 | 37124 |
|
37125 | 37125 |
|
37126 | 37126 |
/***/ }) |
resources/views/favartefacts/index.blade.php | ||
---|---|---|
29 | 29 |
<div class="card"> |
30 | 30 |
<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> |
31 | 31 |
<div class="card-body"> |
32 |
<h5 class="card-title"><a href="{{ url('/artefact/' . $artefact[0]->id) }}">{{$artefact[0]->name}}</a> - {{$artefact[0]->author}}</h5>
|
|
33 |
<h6 class="card-subtitle mb-2 text-muted">{{$artefact[0]->year}}, {{$artefact[0]->pages}} pages</h6>
|
|
32 |
<h5 class="card-title"><a href="{{ url('/artefact/' . $artefact->id) }}">{{$artefact->name}}</a> - {{$artefact->author}}</h5>
|
|
33 |
<h6 class="card-subtitle mb-2 text-muted">{{$artefact->year}}, {{$artefact->pages}} pages</h6>
|
|
34 | 34 |
<p class="card-text"> |
35 | 35 |
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. |
36 | 36 |
Mauris dolor felis, sagittis at, luctus sed, aliquam non, tellus. |
resources/views/favmetadata/index.blade.php | ||
---|---|---|
1 |
@extends('layouts.app') |
|
2 |
|
|
3 |
@section('title', 'Favorite metadata') |
|
4 |
|
|
5 |
@section('breadcrumb') |
|
6 |
<li class="breadcrumb-item"><a href="{{ url('/') }}">Home</a></li> |
|
7 |
<li class="breadcrumb-item active" aria-current="page">Favorite metadata</li> |
|
8 |
@endsection |
|
9 |
|
|
10 |
@section('content') |
|
11 |
<div class="jumbotron"> |
|
12 |
<div class="text-center"> |
|
13 |
<h1>Favorite metadata</h1> |
|
14 |
<p> |
|
15 |
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. |
|
16 |
Mauris dolor felis, sagittis at, luctus sed, aliquam non, tellus. |
|
17 |
Fusce tellus odio, dapibus id fermentum quis, suscipit id erat. |
|
18 |
Morbi scelerisque luctus velit. Vivamus porttitor turpis ac leo. |
|
19 |
Morbi scelerisque luctus velit. |
|
20 |
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. |
|
21 |
</p> |
|
22 |
</div> |
|
23 |
</div> |
|
24 |
|
|
25 |
<div class="metadata-area"> |
|
26 |
@if(count($metadata) > 0) |
|
27 |
<ul class="list-group"> |
|
28 |
@foreach($metadata as $meta) |
|
29 |
<div class="note-area mb-3"> |
|
30 |
<li class="list-group-item"> |
|
31 |
On {{$meta->page}} page:<br> |
|
32 |
{{$meta->noteCZ}}<br> |
|
33 |
{{$meta->noteEN}}<br> |
|
34 |
</li> |
|
35 |
</div> |
|
36 |
@endforeach |
|
37 |
</ul> |
|
38 |
@else |
|
39 |
<ul class="list-group"> |
|
40 |
<li class="list-group-item"> |
|
41 |
<h3>No notes for this BOOK were found!</h3> |
|
42 |
</li> |
|
43 |
</ul> |
|
44 |
@endif |
|
45 |
</div> |
|
46 |
@endsection |
resources/views/inc/navbar.blade.php | ||
---|---|---|
34 | 34 |
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown"> |
35 | 35 |
<a class="dropdown-item" href="{{ url('/favartefacts') }}">Favorite artefacts</a> |
36 | 36 |
|
37 |
<a class="dropdown-item" href="{{ url('/favmetadata') }}">Favorite metadata</a> |
|
38 |
|
|
37 | 39 |
<a class="dropdown-item" href="{{ route('logout') }}" |
38 | 40 |
onclick="event.preventDefault(); |
39 | 41 |
document.getElementById('logout-form').submit();"> |
routes/web.php | ||
---|---|---|
20 | 20 |
Route::resource('/detail', 'DetailsController', array('only' => array('index', 'show'))); |
21 | 21 |
Route::resource('/categories', 'CategoriesController', array('only' => array('index'))); |
22 | 22 |
Route::resource('/favartefacts', 'FavoriteArtefactsController', array('only' => array('index', 'show'))); |
23 |
Route::get('/favmetadata', 'FavoriteMetadataController@index'); |
|
23 | 24 |
|
24 | 25 |
Auth::routes(); |
25 | 26 |
|
Také k dispozici: Unified diff
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