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

Revision

Revision 28 | Revision 105 | 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;
104 lars 12
    use App\Models\ActionType;
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
            //
104 lars 54
            \View::share( [ "kategorien" => ActionType::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" );
96
            $action = Action::find( $id );
26 lars 97
            return view( 'action', [ "action" => $action, ] );
24 lars 98
        }
99
 
100
 
101
        /**
102
         * Update the specified resource in storage.
103
         *
104
         * @param ActionRequest $request
105
         * @param int $id
106
         * @return RedirectResponse
107
         */
108
        public function update( ActionRequest $request, int $id ): RedirectResponse
109
        {
110
            //
111
            $rules = [
112
                'name' => 'bail|max:255',
113
            ];
114
            $request->validate( $rules );
115
            $bu = Action::find( $id );
116
            $data = $request->validated();
117
            $bu->update( $data );
28 lars 118
            return redirect( "/actions" );
24 lars 119
        }
120
 
121
        /**
122
         * Remove the specified resource from storage.
123
         *
124
         * @param int $id
125
         * @return RedirectResponse
126
         */
127
        public function destroy( int $id ): RedirectResponse
128
        {
129
            //
130
            $bu = Action::find( $id );
131
            $bu->delete();
28 lars 132
            return redirect( "/actions" );
24 lars 133
        }
134
    }