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

Revision

Revision 109 | Revision 112 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
24 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;
108 lars 12
    use App\Models\ActionCategory;
24 lars 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
            }
26 lars 44
            return view( 'actions', [ "aktionen" => $actions, ] );
24 lars 45
        }
46
 
47
        /**
48
         * Show the form for creating a new resource.
49
         *
50
         */
51
        public function create(): Factory|View|Application
52
        {
53
            //
108 lars 54
            \View::share( [ "kategorien" => ActionCategory::all()->flatten() ] );
26 lars 55
            return view( 'action' );
24 lars 56
        }
57
 
58
        /**
59
         * Store a newly created resource in storage.
60
         *
61
         * @param Request $request
62
         * @return RedirectResponse
63
         */
64
        public function store( Request $request ): RedirectResponse
65
        {
66
            //
67
            $rules = [
68
                'name' => 'bail|max:255',
69
            ];
70
            $request->validate( $rules );
71
            $bu = new Action();
72
            $bu->update( $request->validated() );
28 lars 73
            return redirect( "/actions" );
24 lars 74
        }
75
 
76
        /**
77
         * Display the specified resource.
78
         *
79
         * @param int $id
80
         */
81
        public function show( int $id )
82
        {
83
            //
84
        }
85
 
86
        /**
87
         * Show the form for editing the specified resource.
88
         *
89
         * @param int $id
90
         * @return Factory|View|Application
91
         */
92
        public function edit( int $id ): Factory|View|Application
93
        {
94
            //
95
            \View::share( "lType", "k" );
109 lars 96
            $kategorienDB = ActionCategory::all()->flatten();
97
            $kategorien = array();
98
            foreach ( $kategorienDB as $kat )
99
            {
100
                $kategorien[$kat["id"]] = $kat["name"];
101
            }
106 lars 102
            \View::share( [ "kategorien" => $kategorien ] );
24 lars 103
            $action = Action::find( $id );
111 lars 104
            dump( $action );
26 lars 105
            return view( 'action', [ "action" => $action, ] );
24 lars 106
        }
107
 
108
 
109
        /**
110
         * Update the specified resource in storage.
111
         *
112
         * @param ActionRequest $request
113
         * @param int $id
114
         * @return RedirectResponse
115
         */
116
        public function update( ActionRequest $request, int $id ): RedirectResponse
117
        {
118
            //
119
            $rules = [
120
                'name' => 'bail|max:255',
121
            ];
122
            $request->validate( $rules );
123
            $bu = Action::find( $id );
124
            $data = $request->validated();
125
            $bu->update( $data );
28 lars 126
            return redirect( "/actions" );
24 lars 127
        }
128
 
129
        /**
130
         * Remove the specified resource from storage.
131
         *
132
         * @param int $id
133
         * @return RedirectResponse
134
         */
135
        public function destroy( int $id ): RedirectResponse
136
        {
137
            //
138
            $bu = Action::find( $id );
139
            $bu->delete();
28 lars 140
            return redirect( "/actions" );
24 lars 141
        }
142
    }