Projekt

Obecné

Profil

Stáhnout (2.46 KB) Statistiky
| Větev: | Tag: | Revize:
1 d7feebff zabran
<?php
2
3
namespace App\Http\Controllers;
4
5 49b1d48f zabran
use App\User;
6 d7feebff zabran
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 49b1d48f zabran
            //$user_likes = User::find(Auth::id())->likesArtefacts();
31 d7feebff zabran
            foreach($artefacts as $item)
32
            {
33 49b1d48f zabran
                $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 d7feebff zabran
            }
37 947493de zabran
            //$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 d7feebff zabran
47
            $data = array(
48
                'title' => 'Charts',
49
                'artefacts' => $artefacts
50
            );
51 49b1d48f zabran
            return view('charts.index') -> with($data);
52 d7feebff zabran
        }
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 947493de zabran
    /*public function show()
69 d7feebff zabran
    {
70
        $artefacts = Artefact::all();
71 49b1d48f zabran
        //$user_likes = User::find(Auth::id())->likesArtefacts();
72 d7feebff zabran
        foreach($artefacts as $item)
73
        {
74 49b1d48f zabran
            $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 d7feebff zabran
        }
78
        $artefacts=$artefacts->sortByDesc('likes');
79
80
        $data = array(
81
            'title' => 'Charts',
82
            'artefacts' => $artefacts
83
        );
84
        return view('charts.index') -> with($data);
85 947493de zabran
    }*/
86 d7feebff zabran
87
}