1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\TechTips; |
4
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
6
|
|
|
|
7
|
|
|
use App\Domains\Users\UserFavs; |
8
|
|
|
use App\Domains\Users\GetUserStats; |
9
|
|
|
use App\Domains\TechTips\SetTechTips; |
10
|
|
|
use App\Domains\TechTips\GetTechTips; |
11
|
|
|
use App\Domains\TechTips\GetTechTipTypes; |
12
|
|
|
use App\Domains\Equipment\GetEquipmentData; |
13
|
|
|
|
14
|
|
|
use App\Http\Requests\TechTipNewTipRequest; |
15
|
|
|
use App\Http\Requests\TechTipSearchRequest; |
16
|
|
|
use App\Http\Requests\TechTipEditTipRequest; |
17
|
|
|
use App\Http\Requests\TechTipProcessImageRequest; |
18
|
|
|
|
19
|
|
|
class TechTipsController extends Controller |
20
|
|
|
{ |
21
|
78 |
|
public function __construct() |
22
|
|
|
{ |
23
|
78 |
|
$this->middleware('auth'); |
24
|
78 |
|
} |
25
|
|
|
|
26
|
|
|
// Tech Tips landing page |
27
|
2 |
|
public function index() |
28
|
|
|
{ |
29
|
2 |
|
return view('tips.index', [ |
30
|
2 |
|
'tipTypes' => (new GetTechTipTypes)->execute(true), |
31
|
2 |
|
'sysTypes' => (new GetEquipmentData)->getAllEquipmentWithDataList(), |
32
|
|
|
]); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
// Search for an existing tip - If no paramaters, return all tips |
36
|
8 |
|
public function search(TechTipSearchRequest $request) |
37
|
|
|
{ |
38
|
8 |
|
return (new GetTechTips)->searchTips($request); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
// Process an image that is attached to a tech tip |
42
|
4 |
|
public function processImage(TechTipProcessImageRequest $request) |
43
|
|
|
{ |
44
|
4 |
|
$this->authorize('hasAccess', 'Create Tech Tip'); |
45
|
|
|
|
46
|
2 |
|
$imgLocation = (new SetTechTips)->processTipImage($request); |
47
|
2 |
|
return response()->json(['location' => $imgLocation]); |
48
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
// Create a new Tech Tip form |
52
|
4 |
|
public function create() |
53
|
|
|
{ |
54
|
4 |
|
$this->authorize('hasAccess', 'Create Tech Tip'); |
55
|
|
|
|
56
|
2 |
|
return view('tips.create', [ |
57
|
2 |
|
'tipTypes' => (new GetTechTipTypes)->execute(true), |
58
|
2 |
|
'sysTypes' => (new GetEquipmentData)->getAllEquipmentWithDataList(), |
59
|
|
|
]); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
// Submit the form to create a new tech tip |
63
|
6 |
|
public function store(TechTipNewTipRequest $request) |
64
|
|
|
{ |
65
|
6 |
|
$this->authorize('hasAccess', 'Create Tech Tip'); |
66
|
|
|
|
67
|
4 |
|
$tipData = (new SetTechTips)->processNewTip($request); |
68
|
4 |
|
return response()->json(['success' => $tipData]); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
// Details controller - will move to the show controller with just the tech tip id |
72
|
2 |
|
public function details($id) |
73
|
|
|
{ |
74
|
2 |
|
$tipData = (new GetTechTips)->getTipDetails($id); |
75
|
|
|
|
76
|
2 |
|
if($tipData['details'] === null) |
77
|
|
|
{ |
78
|
|
|
return view('tips.tipNotFound'); |
79
|
|
|
} |
80
|
|
|
|
81
|
2 |
|
return view('tips.details', [ |
82
|
2 |
|
'details' => $tipData->toJson(), |
83
|
2 |
|
'isFav' => (new GetUserStats)->checkForTechTipFav($id) ? 'true' : 'false', // empty($isFav) ? 'false' : 'true', |
84
|
|
|
]); |
85
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
// Show the details about the tech tip |
89
|
|
|
public function show($id) |
90
|
|
|
{ |
91
|
|
|
$tipData = (new GetTechTips)->getTipDetails($id); |
92
|
|
|
|
93
|
|
|
return view('tips.details', [ |
94
|
|
|
'details' => $tipData['data'], |
95
|
|
|
'isFav' => (new GetUserStats)->checkForTechTipFav($id) ? 'true' : 'false', // empty($isFav) ? 'false' : 'true', |
96
|
|
|
'files' => $tipData['files'], |
97
|
|
|
]); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
// Add or remove this tip as a favorite of the user |
101
|
|
|
public function toggleFav($action, $id) |
102
|
|
|
{ |
103
|
|
|
(new UserFavs)->updateTechTipFav($id); |
104
|
|
|
return response()->json(['success' => true]); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
// Edit an existing tech tip |
108
|
6 |
|
public function edit($id) |
109
|
|
|
{ |
110
|
6 |
|
$this->authorize('hasAccess', 'Edit Tech Tip'); |
111
|
|
|
|
112
|
4 |
|
$tipData = (new GetTechTips)->getTipDetails($id); |
113
|
4 |
|
if(!$tipData['details']) |
114
|
|
|
{ |
115
|
2 |
|
return view('tips.tipNotFound'); |
116
|
|
|
} |
117
|
|
|
|
118
|
2 |
|
return view('tips.editTip', [ |
119
|
2 |
|
'tipTypes' => (new GetTechTipTypes)->execute(true), |
120
|
2 |
|
'sysTypes' => (new GetEquipmentData)->getAllEquipmentWithDataList(), |
121
|
2 |
|
'tipData' => $tipData, |
122
|
|
|
]); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
// Store the edited Tech Tip |
126
|
6 |
|
public function update(TechTipEditTipRequest $request, $id) |
127
|
|
|
{ |
128
|
6 |
|
$this->authorize('hasAccess', 'Edit Tech Tip'); |
129
|
|
|
|
130
|
4 |
|
(new SetTechTips)->processEditTip($request, $id); |
131
|
|
|
|
132
|
4 |
|
return response()->json(['success' => true]); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
// Soft delet the Tech Tip |
136
|
4 |
|
public function destroy($id) |
137
|
|
|
{ |
138
|
4 |
|
$this->authorize('hasAccess', 'Delete Tech Tip'); |
139
|
|
|
|
140
|
2 |
|
(new SetTechTips)->deleteTip($id); |
141
|
2 |
|
return response()->json(['success' => true]); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|