Subversion-Projekte lars-tiefland.webanos.marine-sales.de

Revision

Revision 175 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
2 lars 1
<?php
2
 
176 lars 3
    namespace App\Http\Controllers\online_shop;
2 lars 4
 
176 lars 5
    use App\Http\Controllers\Controller;
2 lars 6
    use App\Http\Requests\ActionRequest;
7
    use App\Models\Action;
8
    use Illuminate\Contracts\Foundation\Application;
9
    use Illuminate\Contracts\View\Factory;
10
    use Illuminate\Contracts\View\View;
11
    use Illuminate\Http\RedirectResponse;
12
    use Illuminate\Http\Request;
13
    use App\Models\ActionCategory;
14
 
15
    class ActionController extends Controller
16
    {
17
        /**
18
         * Display a listing of the resource.
19
         *
20
         */
21
        public function index(): Factory|View|Application
22
        {
23
            //
24
            $actions = Action::orderBy( "rank" )->get();
25
            foreach ( $actions as $aId => $aktion )
26
            {
27
                $gVon = strtotime( $aktion->valid_from );
28
                $gBis = strtotime( $aktion->valid_to );
29
                $jetzt = time();
30
                if ( $jetzt >= $gVon && $jetzt <= $gBis )
31
                {
32
                    $status = 0;
33
                }
34
                elseif ( $jetzt < $gVon )
35
                {
36
                    $status = 1;
37
                }
38
                else
39
                {
40
                    $status = 2;
41
                }
42
                $aktion->status = $status;
43
 
44
            }
170 lars 45
            return view( 'online_shop.actions', [ "aktionen" => $actions, ] );
2 lars 46
        }
47
 
48
        /**
49
         * Show the form for creating a new resource.
50
         *
51
         */
52
        public function create(): Factory|View|Application
53
        {
54
            //
55
            $kategorienDB = ActionCategory::all()->flatten();
56
            $kategorien = array();
57
            foreach ( $kategorienDB as $kat )
58
            {
59
                $kategorien[$kat["id"]] = $kat["name"];
60
            }
61
            \View::share( [ "kategorien" => $kategorien ] );
170 lars 62
            return view( 'online_shop.action' );
2 lars 63
        }
64
 
65
        /**
66
         * Store a newly created resource in storage.
67
         *
68
         * @param Request $request
69
         * @return RedirectResponse
70
         */
71
        public function store( Request $request ): RedirectResponse
72
        {
73
            //
74
            $rules = [
75
                'name' => 'bail|max:255',
76
            ];
77
            $request->validate( $rules );
78
            $bu = new Action();
79
            $bu->update( $request->validated() );
80
            return redirect( "/actions" );
81
        }
82
 
83
        /**
84
         * Display the specified resource.
85
         *
86
         * @param int $id
87
         */
88
        public function show( int $id )
89
        {
90
            //
91
        }
92
 
93
        /**
94
         * Show the form for editing the specified resource.
95
         *
96
         * @param int $id
97
         * @return Factory|View|Application
98
         */
99
        public function edit( int $id ): Factory|View|Application
100
        {
101
            //
102
            $kategorienDB = ActionCategory::all()->flatten();
103
            $kategorien = array();
104
            foreach ( $kategorienDB as $kat )
105
            {
106
                $kategorien[$kat["id"]] = $kat["name"];
107
            }
108
            \View::share( [ "kategorien" => $kategorien, "lType" => "k", ] );
109
            $action = Action::find( $id );
170 lars 110
            return view( 'online_shop.action', [ "action" => $action, ] );
2 lars 111
        }
112
 
113
 
114
        /**
115
         * Update the specified resource in storage.
116
         *
117
         * @param ActionRequest $request
118
         * @param int $id
119
         * @return RedirectResponse
120
         */
121
        public function update( ActionRequest $request, int $id ): RedirectResponse
122
        {
123
            //
124
            $bu = Action::find( $id );
125
            $data = $request->validated();
126
 
127
            $configArr = $data["config"];
128
            if ( $data["navigation_yes"] )
129
            {
130
                $configArr["navigation"] = true;
131
 
132
                if ( $data["arrow_yes"] )
133
                {
134
                    $configArr["pfeile"] = true;
135
 
136
                    if ( $data["arrow_inside"] )
137
                    {
138
                        $configArr["pfeile_innen"] = true;
139
                    }
140
                    elseif ( $data["arrow_outside"] )
141
                    {
142
                        $configArr["pfeile_aussen"] = true;
143
                    }
144
                }
145
 
146
                if ( $data["circle_yes"] )
147
                {
148
                    $configArr["kreise"] = true;
149
 
150
                    if ( $data["circle_up"] )
151
                    {
152
                        $configArr["kreise_oben"] = true;
153
                    }
154
                    elseif ( $data["circle_down"] )
155
                    {
156
                        $configArr["kreise_unten"] = true;
157
                    }
158
                }
159
 
160
                if ( $data["box_yes"] )
161
                {
162
                    $configArr["boxen"] = true;
163
 
164
                    if ( $data["box_right"] )
165
                    {
166
                        $configArr["box_rechts"] = true;
167
                    }
168
                    elseif ( $data["box_left"] )
169
                    {
170
                        $configArr["box_links"] = true;
171
                    }
172
                    elseif ( $data["box_up"] )
173
                    {
174
                        $configArr["box_oben"] = true;
175
                    }
176
                    elseif ( $data["box_down"] )
177
                    {
178
                        $configArr["box_unten"] = true;
179
                    }
180
                }
181
            }
182
 
183
            if ( isset( $data["navigation_yes"] ) )
184
            {
185
                $configArr["navigation"] = 1;
186
 
187
                if ( isset( $data["arrow_yes"] ) )
188
                {
189
                    $configArr["pfeile"] = 1;
190
 
191
                    if ( $data["arrow_inside"] )
192
                    {
193
                        $configArr["pfeile_innen"] = 1;
194
                    }
195
                    else
196
                    {
197
                        $configArr["pfeile_innen"] = 0;
198
                    }
199
                    if ( $data["arrow_outside"] )
200
                    {
201
                        $configArr["pfeile_aussen"] = 1;
202
                    }
203
                    else
204
                    {
205
                        $configArr["pfeile_aussen"] = 0;
206
                    }
207
 
208
                }
209
                else
210
                {
211
                    $configArr["pfeile"] = 0;
212
                }
213
 
214
                if ( isset( $data["circle_yes"] ) )
215
                {
216
                    $configArr["kreise"] = 1;
217
 
218
                    if ( isset( $data["circle_up"] ) )
219
                    {
220
                        $configArr["kreise_oben"] = 1;
221
                    }
222
                    else
223
                    {
224
                        $configArr["kreise_oben"] = 0;
225
                    }
226
                    if ( isset( $data["circle_down"] ) )
227
                    {
228
                        $configArr["kreise_unten"] = 1;
229
                    }
230
                    else
231
                    {
232
                        $configArr["kreise_unten"] = 0;
233
                    }
234
                }
235
                else
236
                {
237
                    $configArr["kreise"] = 0;
238
                }
239
 
240
                if ( isset( $data["box_yes"] ) )
241
                {
242
                    $configArr["boxen"] = 1;
243
 
244
                    if ( $data["box_right"] )
245
                    {
246
                        $configArr["box_rechts"] = 1;
247
                    }
248
                    else
249
                    {
250
                        $configArr["box_rechts"] = 0;
251
                    }
252
                    if ( $data["box_left"] )
253
                    {
254
                        $configArr["box_links"] = 1;
255
                    }
256
                    else
257
                    {
258
                        $configArr["box_links"] = 0;
259
                    }
260
                    if ( $data["box_up"] )
261
                    {
262
                        $configArr["box_oben"] = 1;
263
                    }
264
                    else
265
                    {
266
                        $configArr["box_oben"] = 0;
267
                    }
268
                    if ( $data["box_down"] )
269
                    {
270
                        $configArr["box_unten"] = 1;
271
                    }
272
                    else
273
                    {
274
                        $configArr["box_unten"] = 0;
275
                    }
276
                }
277
                else
278
                {
279
                    $configArr["boxen"] = 0;
280
                }
281
            }
282
            else
283
            {
284
                $configArr["navigation"] = 0;
285
            }
286
            $data["config"] = serialize( $configArr );
287
            $bu->update( $data );
288
            return redirect( "/actions" );
289
        }
290
 
291
        /**
292
         * Remove the specified resource from storage.
293
         *
294
         * @param int $id
295
         * @return RedirectResponse
296
         */
297
        public function destroy( int $id ): RedirectResponse
298
        {
299
            //
300
            $bu = Action::find( $id );
301
            $bu->delete();
302
            return redirect( "/actions" );
303
        }
304
    }