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

Revision

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