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

Revision

Revision 26 | Revision 28 | 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;
12
 
13
    class ActionController extends Controller
14
    {
15
        /**
16
         * Display a listing of the resource.
17
         *
18
         */
19
        public function index(): Factory|View|Application
20
        {
21
            //
22
            $actions = Action::orderBy( "rank" )->get();
23
            foreach ( $actions as $aId => $aktion )
24
            {
25
                $gVon = strtotime( $aktion->valid_from );
26
                $gBis = strtotime( $aktion->valid_to );
27
                $jetzt = time();
28
                if ( $jetzt >= $gVon && $jetzt <= $gBis )
29
                {
30
                    $status = 0;
31
                }
32
                elseif ( $jetzt < $gVon )
33
                {
34
                    $status = 1;
35
                }
36
                else
37
                {
38
                    $status = 2;
39
                }
40
                $aktion->status = $status;
41
 
42
            }
26 lars 43
            return view( 'actions', [ "aktionen" => $actions, ] );
24 lars 44
        }
45
 
46
        /**
47
         * Show the form for creating a new resource.
48
         *
49
         */
50
        public function create(): Factory|View|Application
51
        {
52
            //
26 lars 53
            return view( 'action' );
24 lars 54
        }
55
 
56
        /**
57
         * Store a newly created resource in storage.
58
         *
59
         * @param Request $request
60
         * @return RedirectResponse
61
         */
62
        public function store( Request $request ): RedirectResponse
63
        {
64
            //
65
            $rules = [
66
                'name' => 'bail|max:255',
67
            ];
68
            $request->validate( $rules );
69
            $bu = new Action();
70
            $bu->update( $request->validated() );
27 lars 71
            return redirect( "//actions" );
24 lars 72
        }
73
 
74
        /**
75
         * Display the specified resource.
76
         *
77
         * @param int $id
78
         */
79
        public function show( int $id )
80
        {
81
            //
82
        }
83
 
84
        /**
85
         * Show the form for editing the specified resource.
86
         *
87
         * @param int $id
88
         * @return Factory|View|Application
89
         */
90
        public function edit( int $id ): Factory|View|Application
91
        {
92
            //
93
            \View::share( "lType", "k" );
94
            $action = Action::find( $id );
26 lars 95
            return view( 'action', [ "action" => $action, ] );
24 lars 96
        }
97
 
98
 
99
        /**
100
         * Update the specified resource in storage.
101
         *
102
         * @param ActionRequest $request
103
         * @param int $id
104
         * @return RedirectResponse
105
         */
106
        public function update( ActionRequest $request, int $id ): RedirectResponse
107
        {
108
            //
109
            $rules = [
110
                'name' => 'bail|max:255',
111
            ];
112
            $request->validate( $rules );
113
            $bu = Action::find( $id );
114
            $data = $request->validated();
115
            $bu->update( $data );
27 lars 116
            return redirect( "//actions" );
24 lars 117
        }
118
 
119
        /**
120
         * Remove the specified resource from storage.
121
         *
122
         * @param int $id
123
         * @return RedirectResponse
124
         */
125
        public function destroy( int $id ): RedirectResponse
126
        {
127
            //
128
            $bu = Action::find( $id );
129
            $bu->delete();
27 lars 130
            return redirect( "//actions" );
24 lars 131
        }
132
    }