Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 75508baf

Přidáno uživatelem Marek Lovčí před asi 4 roky(ů)

Merge origin/develop into master

Zobrazit rozdíly:

app/Http/Controllers/FavoriteArtefactsController.php
2 2

  
3 3
namespace App\Http\Controllers;
4 4

  
5
use App\ArtefactUser;
5
use Illuminate\Contracts\Foundation\Application;
6
use Illuminate\Contracts\View\Factory;
6 7
use Illuminate\Support\Facades\Auth;
7 8
use App\User;
8 9
use App\Artefact;
9 10
use App\Http\Controllers\Image;
11
use Illuminate\View\View;
10 12

  
11 13
class FavoriteArtefactsController extends Controller
12 14
{
15
    const ORDER_COLUMN = 'page';
16

  
13 17
    public function __construct()
14 18
    {
15 19
        $this->middleware('auth');
16 20
    }
17 21

  
22
    /**
23
     * Prepare all necessary data for shown Artefact.
24
     * These are current count of likes, if it set to
25
     * a favorites by a logged user and all metadata
26
     * connected to the artefact.
27
     *
28
     * @param       $artefacts  all artefacts
29
     * @return      mixed       modified artefacts
30
     */
31
    public function prepData($artefacts)
32
    {
33
        foreach($artefacts as $artefact)
34
        {
35
            $artefact['likes'] = Artefact::find($artefact->id)->users()->count();
36
            $artefact['favourite'] = is_null(User::find(Auth::id())->likesArtefacts()->find($artefact->id)) ? false : true;
37
            $metadata = Artefact::find($artefact->id)->metadata()->orderBy(self::ORDER_COLUMN)->get();
38
            foreach ($metadata as $item)
39
            {
40
                $item['favourite'] = is_null(User::find(Auth::id())->likesMetadata()->find($item->id)) ? false : true;
41
            }
42
            $artefact['metadata'] = $metadata;
43
        }
44
        return $artefacts;
45
    }
46

  
18 47
    /**
19 48
     * Display a listing of the resource.
20 49
     *
21
     * @return \Illuminate\Http\Response
50
     * @return Application|Factory|View
22 51
     */
23 52
    public function index()
24 53
    {
25 54
        if(Auth::check())
26 55
        {
27 56
            $id = Auth::id();
28
            $artefacts = User::find($id)->likesArtefacts()->get();
29
            foreach($artefacts as $item)
30
            {
31
                $item['likes'] = Artefact::find($item->id)->users()->count();
32
            }
33

  
34
            $data = array(
35
                'title' => 'Favorite artefacts',
36
                'user' => $id,
37
                'artefacts' => $artefacts
38
            );
39
            return view('favartefacts.index') -> with($data);
57
            $artefacts = User::find($id)->likesArtefacts()->simplePaginate(1);
58
            $artefacts = $this->prepData($artefacts);
59
            return view('artefact.default', ['artefacts' => $artefacts]);
40 60
        }
41 61
        else
42 62
        {
43
            $data = array(
44
                'title' => 'Welcome to the MERLOT page',
45
            );
46
            //return view('index', compact('title'));
47
            return view('pages.index') -> with($data);
63
            return view('pages.index');
48 64
        }
49 65
    }
50 66

  
......
52 68
     * Display the specified resource.
53 69
     *
54 70
     * @param  int  $id
55
     * @return \Illuminate\Http\Response
71
     * @return Application|Factory|View
56 72
     */
57 73
    public function show($id)
58 74
    {
59
        $artefacts = User::find($id)->likesArtefacts()->get();
60
        foreach($artefacts as $item)
61
        {
62
            $item['likes'] = Artefact::find($item->id)->users()->count();
63
        }
64

  
65

  
66
        $data = array(
67
            'title' => 'Favorite artefacts',
68
            'id' => $id,
69
            'user' => User::find($id),
70
            'userId' => Auth::id(),
71
            'artefacts' => $artefacts
72
        );
73
        return view('favartefacts.index') -> with($data);
75
        $artefacts = User::find($id)->likesArtefacts()->simplePaginate(1);
76
        $artefacts = $this->prepData($artefacts);
77
        return view('artefact.default', ['artefacts' => $artefacts]);
74 78
    }
75 79

  
76 80
}

Také k dispozici: Unified diff