|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use App\Helpers\Helper; |
|
6
|
|
|
use App\Http\Requests\GlossarySearchRequest; |
|
7
|
|
|
use App\Http\Requests\GlossaryStoreRequest; |
|
8
|
|
|
use App\Models\Glossary; |
|
9
|
|
|
use App\Services\GlossaryService; |
|
10
|
|
|
use Illuminate\Http\RedirectResponse; |
|
11
|
|
|
use Illuminate\View\View; |
|
12
|
|
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization; |
|
13
|
|
|
|
|
14
|
|
|
class GlossaryController extends Controller |
|
15
|
|
|
{ |
|
16
|
|
|
private GlossaryService $glossaryService; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* GlossaryController constructor. |
|
20
|
|
|
* |
|
21
|
|
|
* @param \App\Services\GlossaryService $glossaryService |
|
22
|
|
|
*/ |
|
23
|
|
|
public function __construct( |
|
24
|
|
|
GlossaryService $glossaryService |
|
25
|
|
|
) { |
|
26
|
|
|
$this->glossaryService = $glossaryService; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Show the resource. |
|
31
|
|
|
* |
|
32
|
|
|
* @param int $glossarySlug |
|
33
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\View\View |
|
34
|
|
|
*/ |
|
35
|
|
|
public function show(string $glossarySlug): View |
|
36
|
|
|
{ |
|
37
|
|
|
$glossaryTerm = $this->glossaryService->getBySlug($glossarySlug); |
|
38
|
|
|
$titleQuestion = $this->glossaryService->getGlossaryTermTitleQuestion($glossaryTerm); |
|
39
|
|
|
|
|
40
|
|
|
return view('glossaries.show', [ |
|
41
|
|
|
'glossaryTerm' => $glossaryTerm, |
|
42
|
|
|
'titleQuestion' => $titleQuestion, |
|
43
|
|
|
]); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Display a listing of the resource. |
|
48
|
|
|
* |
|
49
|
|
|
* @param \App\Http\Requests\GlossarySearchRequest $request |
|
50
|
|
|
* |
|
51
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\View\View |
|
52
|
|
|
*/ |
|
53
|
|
|
public function index(GlossarySearchRequest $request): View |
|
54
|
|
|
{ |
|
55
|
|
|
$searchParameters = Helper::getSearchParameters($request, Glossary::SEARCH_PARAMETERS); |
|
|
|
|
|
|
56
|
|
|
$glossaries = $this->glossaryService->getGlossaries(20, $searchParameters); |
|
57
|
|
|
$statuses = Glossary::PUBLISHING_STATUS; |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
return view('glossaries.index', [ |
|
60
|
|
|
'glossaries' => $glossaries, |
|
61
|
|
|
'searchParameters' => $searchParameters, |
|
62
|
|
|
'statuses' => $statuses, |
|
63
|
|
|
]); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Show the form for creating a new resource. |
|
68
|
|
|
* |
|
69
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\View\View |
|
70
|
|
|
*/ |
|
71
|
|
|
public function create(): View |
|
72
|
|
|
{ |
|
73
|
|
|
$countriesAvailableForTranslations = LaravelLocalization::getSupportedLocales(); |
|
74
|
|
|
return view('glossaries.create', [ |
|
75
|
|
|
'countriesAvailableForTranslations' => $countriesAvailableForTranslations, |
|
76
|
|
|
]); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Store a newly created resource in storage. |
|
81
|
|
|
* |
|
82
|
|
|
* @param \App\Http\Requests\GlossaryStoreRequest $request |
|
83
|
|
|
* |
|
84
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
85
|
|
|
*/ |
|
86
|
|
|
public function store(GlossaryStoreRequest $request): RedirectResponse |
|
87
|
|
|
{ |
|
88
|
|
|
$this->glossaryService->createGlossary($request); |
|
89
|
|
|
|
|
90
|
|
|
return redirect()->route('glossaries.index') |
|
91
|
|
|
->with('success', 'Tag created successfully'); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Show the form for editing the specified resource. |
|
96
|
|
|
* |
|
97
|
|
|
* @param int $glossaryId |
|
98
|
|
|
* |
|
99
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\View\View |
|
100
|
|
|
*/ |
|
101
|
|
|
public function edit(int $glossaryId): View |
|
102
|
|
|
{ |
|
103
|
|
|
$glossary = $this->glossaryService->getById($glossaryId); |
|
104
|
|
|
$countriesAvailableForTranslations = LaravelLocalization::getSupportedLocales(); |
|
105
|
|
|
|
|
106
|
|
|
return view('glossaries.edit', [ |
|
107
|
|
|
'glossary' => $glossary, |
|
108
|
|
|
'countriesAvailableForTranslations' => $countriesAvailableForTranslations, |
|
109
|
|
|
]); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Update the specified resource in storage. |
|
114
|
|
|
* |
|
115
|
|
|
* @param \App\Http\Requests\GlossaryStoreRequest $request |
|
116
|
|
|
* @param int $glossaryId |
|
117
|
|
|
* |
|
118
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
119
|
|
|
*/ |
|
120
|
|
|
public function update(GlossaryStoreRequest $request, int $glossaryId): RedirectResponse |
|
121
|
|
|
{ |
|
122
|
|
|
$this->glossaryService->updateGlossary($request, $glossaryId); |
|
123
|
|
|
|
|
124
|
|
|
return redirect()->route('glossaries.index') |
|
125
|
|
|
->with('success', 'Tag updated successfully'); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Remove the specified resource from storage. |
|
130
|
|
|
* |
|
131
|
|
|
* @param int $glossaryId |
|
132
|
|
|
* |
|
133
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
134
|
|
|
*/ |
|
135
|
|
|
public function destroy(int $glossaryId): RedirectResponse |
|
136
|
|
|
{ |
|
137
|
|
|
$this->glossaryService->deleteGlossary($glossaryId); |
|
138
|
|
|
|
|
139
|
|
|
return redirect()->route('glossaries.index') |
|
140
|
|
|
->with('success', 'Tag deleted successfully'); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|