Subversion-Projekte lars-tiefland.webanos.zeldi.de

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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