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

Revision

Revision 113 | 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
            //
113 lars 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 ] );
26 lars 61
            return view( 'action' );
24 lars 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() );
28 lars 79
            return redirect( "/actions" );
24 lars 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
            //
109 lars 101
            $kategorienDB = ActionCategory::all()->flatten();
102
            $kategorien = array();
103
            foreach ( $kategorienDB as $kat )
104
            {
105
                $kategorien[$kat["id"]] = $kat["name"];
106
            }
114 lars 107
            \View::share( [ "kategorien" => $kategorien, "lType" => "k", ] );
24 lars 108
            $action = Action::find( $id );
26 lars 109
            return view( 'action', [ "action" => $action, ] );
24 lars 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
            $rules = [
124
                'name' => 'bail|max:255',
125
            ];
126
            $request->validate( $rules );
127
            $bu = Action::find( $id );
128
            $data = $request->validated();
129
            $bu->update( $data );
28 lars 130
            return redirect( "/actions" );
24 lars 131
        }
132
 
133
        /**
134
         * Remove the specified resource from storage.
135
         *
136
         * @param int $id
137
         * @return RedirectResponse
138
         */
139
        public function destroy( int $id ): RedirectResponse
140
        {
141
            //
142
            $bu = Action::find( $id );
143
            $bu->delete();
28 lars 144
            return redirect( "/actions" );
24 lars 145
        }
146
    }