Revize 609126cb
Přidáno uživatelem Jiří Noháč před téměř 5 roky(ů)
app/Http/Controllers/ArtefactController.php | ||
---|---|---|
4 | 4 |
|
5 | 5 |
use App\Artefact; |
6 | 6 |
use App\ArtefactCategory; |
7 |
use App\Category; |
|
7 | 8 |
use App\User; |
8 | 9 |
use Illuminate\Contracts\View\Factory; |
9 | 10 |
use Illuminate\Http\RedirectResponse; |
... | ... | |
20 | 21 |
} |
21 | 22 |
|
22 | 23 |
/** |
23 |
* Returns view of all artefacts. |
|
24 |
* Prepare all necessary data for shown Artefact. |
|
25 |
* These are current count of likes, if it set to |
|
26 |
* a favorites by a logged user and all metadata |
|
27 |
* connected to the artefact. |
|
24 | 28 |
* |
25 |
* @return Factory|View |
|
29 |
* @param $artefacts all artefacts |
|
30 |
* @return mixed modified artefacts |
|
26 | 31 |
*/ |
27 |
public function default()
|
|
32 |
public function prepData($artefacts)
|
|
28 | 33 |
{ |
29 |
$artefacts = Artefact::simplePaginate(1); |
|
30 | 34 |
foreach($artefacts as $artefact) |
31 | 35 |
{ |
32 | 36 |
$artefact['likes'] = Artefact::find($artefact->id)->users()->count(); |
... | ... | |
41 | 45 |
$artefact['metadata'] = $metadata; |
42 | 46 |
} |
43 | 47 |
|
48 |
return $artefacts; |
|
49 |
} |
|
50 |
|
|
51 |
/** |
|
52 |
* Returns view of all artefacts. |
|
53 |
* |
|
54 |
* @return Factory|View |
|
55 |
*/ |
|
56 |
public function default() |
|
57 |
{ |
|
58 |
$artefacts = Artefact::simplePaginate(1); |
|
59 |
$artefacts = $this->prepData($artefacts); |
|
44 | 60 |
return view('artefact.default', ['artefacts' => $artefacts]); |
45 | 61 |
} |
46 | 62 |
|
... | ... | |
52 | 68 |
*/ |
53 | 69 |
public function showCategory($id) |
54 | 70 |
{ |
55 |
$categoryArtefacts = ArtefactCategory::where('category_id', $id)->get(); |
|
56 |
if(count($categoryArtefacts) > 0) |
|
57 |
{ |
|
58 |
$artefacts = array(); |
|
59 |
foreach($categoryArtefacts as $ar) |
|
60 |
{ |
|
61 |
array_push($artefacts, Artefact::where('id', $ar->artefact_id)->get()); |
|
62 |
} |
|
63 |
return view('artefact.category', ['artefacts' => $artefacts]); |
|
64 |
} |
|
65 |
else |
|
66 |
{ |
|
67 |
return view('artefact.category', ['artefacts' => array()]); |
|
68 |
} |
|
71 |
$artefacts = Category::find($id)->artefacts()->simplePaginate(1); |
|
72 |
$artefacts = $this->prepData($artefacts); |
|
73 |
return view('artefact.default', ['artefacts' => $artefacts]); |
|
69 | 74 |
} |
70 | 75 |
|
71 | 76 |
/** |
72 |
* Returns view of artefacts related to the chosen category
|
|
77 |
* Returns view of artefacts related to the chosen categories
|
|
73 | 78 |
* |
74 | 79 |
* @param $id string with categories ids |
75 | 80 |
* @return Factory|View |
76 | 81 |
*/ |
77 | 82 |
public function showCategories($id) |
78 | 83 |
{ |
84 |
//Parsing text for individual ids of categories |
|
79 | 85 |
$textWithIds = $id; |
80 | 86 |
$pieces = explode(",", $textWithIds); |
81 |
$artefacts = array();
|
|
87 |
$arrStrToInt = array();
|
|
82 | 88 |
for($i = 0;$i < count($pieces); $i++) |
83 | 89 |
{ |
84 | 90 |
if($pieces[$i] == null || !strcmp($pieces[$i], "")) |
... | ... | |
86 | 92 |
continue; |
87 | 93 |
} |
88 | 94 |
|
89 |
$categoryArtefacts = ArtefactCategory::where('category_id', $pieces[$i])->get(); |
|
90 |
if(count($categoryArtefacts) > 0) |
|
91 |
{ |
|
92 |
foreach($categoryArtefacts as $ar) |
|
93 |
{ |
|
94 |
array_push($artefacts, Artefact::where('id', $ar->artefact_id)->get()); |
|
95 |
} |
|
96 |
} |
|
95 |
array_push($arrStrToInt, (int)$pieces[$i]); |
|
97 | 96 |
} |
98 | 97 |
|
99 |
if(count($artefacts) > 0) |
|
98 |
//Creating array of all artefacts ids |
|
99 |
$arrArtIds = array(); |
|
100 |
foreach($arrStrToInt as $cat) |
|
100 | 101 |
{ |
101 |
return view('artefact.category', ['artefacts' => $artefacts]);
|
|
102 |
}
|
|
103 |
else
|
|
104 |
{
|
|
105 |
return view('artefact.category', ['artefacts' => array()]);
|
|
102 |
$tmpArtefacts = Category::find($cat)->artefacts()->get();
|
|
103 |
foreach($tmpArtefacts as $art)
|
|
104 |
{
|
|
105 |
array_push($arrArtIds, $art->id);
|
|
106 |
}
|
|
106 | 107 |
} |
108 |
|
|
109 |
$artefacts = Artefact::whereIn('id', $arrArtIds)->simplePaginate(1); |
|
110 |
$artefacts = $this->prepData($artefacts); |
|
111 |
return view('artefact.default', ['artefacts' => $artefacts]); |
|
107 | 112 |
} |
108 | 113 |
|
109 | 114 |
/** |
... | ... | |
114 | 119 |
*/ |
115 | 120 |
public function view($id) |
116 | 121 |
{ |
117 |
$artefact = Artefact::find($id); |
|
118 |
$artefact['likes'] = Artefact::find($id)->users()->count(); |
|
119 |
$artefact['favourite'] = is_null(User::find(Auth::id())->likesArtefacts()->find($id)) ? false : true; |
|
120 |
|
|
121 |
return view('artefact.view', ['artefact' => $artefact]); |
|
122 |
$artefact = Artefact::find($id)->simplePaginate(1); |
|
123 |
$artefact = $this->prepData($artefact); |
|
124 |
//return view('artefact.view', ['artefact' => $artefact]); |
|
125 |
return view('artefact.default', ['artefacts' => $artefact]); |
|
122 | 126 |
} |
123 | 127 |
|
124 | 128 |
/** |
Také k dispozici: Unified diff
Uprava sjednoceni templatu pro "Artefacts"
Uprava a sjednoceni vsech stranek (vyjma charts) na stejny design zobrazeni artefaktu podle 'books.blade'. Mezi upravene stranky patri: artefact, category, categories, favartefacts.