1
|
<?php
|
2
|
|
3
|
namespace App\Http\Controllers;
|
4
|
|
5
|
use App\User;
|
6
|
use Illuminate\Contracts\Foundation\Application;
|
7
|
use Illuminate\Contracts\View\Factory;
|
8
|
use Illuminate\Support\Facades\Auth;
|
9
|
use App\Artefact;
|
10
|
use App\Http\Controllers\Image;
|
11
|
use Illuminate\View\View;
|
12
|
|
13
|
class ChartsController extends Controller
|
14
|
{
|
15
|
public function __construct()
|
16
|
{
|
17
|
$this->middleware('auth');
|
18
|
}
|
19
|
|
20
|
/**
|
21
|
* Display a listing of the resource.
|
22
|
*
|
23
|
* @return Application|Factory|View
|
24
|
*/
|
25
|
public function index()
|
26
|
{
|
27
|
if(Auth::check())
|
28
|
{
|
29
|
$artefacts = Artefact::all();
|
30
|
//$user_likes = User::find(Auth::id())->likesArtefacts();
|
31
|
foreach($artefacts as $item)
|
32
|
{
|
33
|
$id = $item->id;
|
34
|
$item['likes'] = Artefact::find($id)->users()->count();
|
35
|
$item['favourite'] = is_null(User::find(Auth::id())->likesArtefacts()->find($id)) ? false : true;
|
36
|
}
|
37
|
//$artefacts->keyBy('id');
|
38
|
/*$selected = [];
|
39
|
for($i=0;$i<10;$i++){
|
40
|
$max = $artefacts->where('likes', $artefacts->max('likes'));
|
41
|
$selected[$i] = $max->first();
|
42
|
$artefacts->forget($max->keys()->first());
|
43
|
}
|
44
|
$artefacts=$selected;*/
|
45
|
$artefacts=$artefacts->sortByDesc('likes')->take(10);
|
46
|
|
47
|
$data = array(
|
48
|
'title' => 'Charts',
|
49
|
'artefacts' => $artefacts
|
50
|
);
|
51
|
return view('charts.index') -> with($data);
|
52
|
}
|
53
|
else
|
54
|
{
|
55
|
$data = array(
|
56
|
'title' => 'Welcome to the MERLOT page',
|
57
|
);
|
58
|
//return view('index', compact('title'));
|
59
|
return view('pages.index') -> with($data);
|
60
|
}
|
61
|
}
|
62
|
|
63
|
/**
|
64
|
* Display the specified resource.
|
65
|
*
|
66
|
* @return Application|Factory|View
|
67
|
*/
|
68
|
/*public function show()
|
69
|
{
|
70
|
$artefacts = Artefact::all();
|
71
|
//$user_likes = User::find(Auth::id())->likesArtefacts();
|
72
|
foreach($artefacts as $item)
|
73
|
{
|
74
|
$id = $item->id;
|
75
|
$item['likes'] = Artefact::find($id)->users()->count();
|
76
|
$item['favourite'] = is_null(User::find(Auth::id())->likesArtefacts()->find($id)) ? false : true;
|
77
|
}
|
78
|
$artefacts=$artefacts->sortByDesc('likes');
|
79
|
|
80
|
$data = array(
|
81
|
'title' => 'Charts',
|
82
|
'artefacts' => $artefacts
|
83
|
);
|
84
|
return view('charts.index') -> with($data);
|
85
|
}*/
|
86
|
|
87
|
}
|