]> gitweb.hamatoma.de Git - gadeku.git/commitdiff
V 0.1.3 Neu:Reviews
authorCeline <celine_kappeler@gmx.de>
Wed, 3 Apr 2024 19:59:50 +0000 (21:59 +0200)
committerCeline <celine_kappeler@gmx.de>
Wed, 3 Apr 2024 19:59:50 +0000 (21:59 +0200)
CHANGELOG.md
app/Http/Controllers/ReviewController.php [new file with mode: 0644]
app/Models/Review.php [new file with mode: 0644]
database/migrations/2024_03_09_194857_create_reviews_table.php [new file with mode: 0644]
resources/views/review/create.blade.php [new file with mode: 0644]
resources/views/review/edit.blade.php [new file with mode: 0644]
resources/views/review/index.blade.php [new file with mode: 0644]
resources/views/review/show.blade.php [new file with mode: 0644]
routes/web.php

index 191a869cc4687a9eb10eaa136cd00504bf6b07bc..b442109041f345921d68b124c03069fa3ec473ef 100644 (file)
@@ -1,3 +1,6 @@
+# V 0.1.3 Neu:Reviews
+
+
 # V 0.1.2 Grammatik
 
 ## Changed
diff --git a/app/Http/Controllers/ReviewController.php b/app/Http/Controllers/ReviewController.php
new file mode 100644 (file)
index 0000000..7f044b2
--- /dev/null
@@ -0,0 +1,210 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Route;
+use Illuminate\Support\Facades\Validator;
+use App\Models\Review;
+use App\Models\SProperty;
+use App\Helpers\ContextLaraKnife;
+use App\Helpers\ViewHelper;
+use App\Helpers\DbHelper;
+use App\Helpers\Helper;
+use App\Helpers\Pagination;
+
+class ReviewController extends Controller
+{
+    /**
+     * Show the form for creating a new resource.
+     */
+    public function create(Request $request)
+    {
+        if ($request->btnSubmit === 'btnCancel') {
+            $rc = redirect('/review-index');
+        } else {
+            $fields = $request->all();
+            if (count($fields) === 0) {
+                $fields = [
+                    'nickname' => '',
+                    'stars' => '',
+                    'title' => '',
+                    'comment' => '',
+                    'email' => ''
+                ];
+            }
+            $context = new ContextLaraKnife($request, $fields);     
+            $rc = view('review.create', [
+                'context' => $context,
+                ]);
+        }
+        return $rc;
+    }
+    /**
+     * Show the form for editing the specified resource.
+     */
+    public function edit(Review $review, Request $request)
+    {
+        if ($request->btnSubmit === 'btnCancel') {
+            $rc = redirect('/review-index');
+        } else {
+            $fields = $request->all();
+            if (count($fields) === 0) {
+                $fields = [
+                    'nickname' => '',
+                    'stars' => '',
+                    'title' => '',
+                    'comment' => '',
+                    'email' => ''
+                    ];
+            }
+            $context = new ContextLaraKnife($request, null, $review);
+            $rc = view('review.edit', [
+                'context' => $context,
+                ]);
+        }
+        return $rc;
+    }
+    /**
+     * Remove the specified resource from storage.
+     */
+    public function destroy(Review $review, Request $request)
+    {
+        if ($request->btnSubmit === 'btnDelete') {
+            $review->delete();
+        }
+        return redirect('/review-index');
+    }
+    /**
+     * Display the database records of the resource.
+     */
+    public function index(Request $request)
+    {
+        if ($request->btnSubmit === 'btnNew') {
+            return redirect('/review-create');
+        } else {
+            $sql = 'SELECT t0.*'
+                . ' FROM reviews t0'
+                ;
+            $parameters = [];
+            $fields = $request->all();
+            if (count($fields) == 0) {
+                $fields = [
+                'nickname' => '',
+                'stars' => '',
+                'title' => '',
+                'comment' => '',
+                'email' => '',
+                '_sortParams' => 'id:asc' 
+                                . ';nickname:desc'
+                ];
+            } else {
+                $conditions = [];
+                ViewHelper::addConditionPattern($conditions, $parameters, 'nickname');
+                ViewHelper::addConditionPattern($conditions, $parameters, 'title');
+                ViewHelper::addConditionPattern($conditions, $parameters, 'comment');
+                ViewHelper::addConditionPattern($conditions, $parameters, 'email');
+                ViewHelper::addConditionComparism($conditions, $parameters, 'stars', null, '=');
+                $sql = DbHelper::addConditions($sql, $conditions);
+            }
+            $sql = DbHelper::addOrderBy($sql, $fields['_sortParams']);
+            $pagination = new Pagination($sql, $parameters, $fields);
+            $records = $pagination->records;
+            $context = new ContextLaraKnife($request, $fields);
+            return view('review.index', [
+                'context' => $context,
+                'records' => $records,
+                'pagination' => $pagination
+            ]);
+        }
+    }
+    /**
+     * Returns the validation rules.
+     * @return array<string, string> The validation rules.
+     */
+    private function rules(bool $isCreate=false): array
+    {
+        $rc = [
+            'nickname' => 'required',
+            'stars' => 'required|integer|min:1|max:5',
+            'title' => 'required',
+            'comment' => '',
+            'email' => 'required|email'
+        ];
+        return $rc;
+    }
+    public static function routes()
+    {
+        Route::get('/review-index', [ReviewController::class, 'index'])->middleware('auth');
+        Route::post('/review-index', [ReviewController::class, 'index'])->middleware('auth');
+        Route::get('/review-create', [ReviewController::class, 'create'])->middleware('auth');
+        Route::put('/review-store', [ReviewController::class, 'store'])->middleware('auth');
+        Route::post('/review-edit/{review}', [ReviewController::class, 'edit'])->middleware('auth');
+        Route::get('/review-edit/{review}', [ReviewController::class, 'edit'])->middleware('auth');
+        Route::post('/review-update/{review}', [ReviewController::class, 'update'])->middleware('auth');
+        Route::get('/review-show/{review}/delete', [ReviewController::class, 'show'])->middleware('auth');
+        Route::delete('/review-show/{review}/delete', [ReviewController::class, 'destroy'])->middleware('auth');
+    }
+    /**
+     * Display the specified resource.
+     */
+    public function show(Review $review, Request $request)
+    {
+        if ($request->btnSubmit === 'btnCancel') {
+            $rc = redirect('/review-index')->middleware('auth');
+        } else {
+            $context = new ContextLaraKnife($request, null, $review);
+            $rc = view('review.show', [
+                'context' => $context,
+                'mode' => 'delete'
+                ]);
+        }
+        return $rc;
+    }
+
+    /**
+     * Store a newly created resource in storage.
+     */
+    public function store(Request $request)
+    {
+        $rc = null;
+        if ($request->btnSubmit === 'btnStore') {
+            $fields = $request->all();
+            $validator = Validator::make($fields, $this->rules(true));
+            if ($validator->fails()) {
+                $rc = back()->withErrors($validator)->withInput();
+            } else {
+                $validated = $validator->validated();
+            $validated['comment'] = strip_tags($validated['comment']);
+                Review::create($validated);
+            }
+        }
+        if ($rc == null){
+            $rc = redirect('/review-index');
+        }
+        return $rc;
+    }
+    /**
+     * Update the specified resource in storage.
+     */
+    public function update(Review $review, Request $request)
+    {
+        $rc = null;
+        if ($request->btnSubmit === 'btnStore') {
+            $fields = $request->all();
+            $validator = Validator::make($fields, $this->rules(false));
+            if ($validator->fails()) {
+                $rc = back()->withErrors($validator)->withInput();
+            } else {
+                $validated = $validator->validated();
+                $validated['comment'] = strip_tags($validated['comment']);
+                $review->update($validated);
+            }
+        }
+        if ($rc == null){
+            $rc = redirect('/review-index');
+        }
+        return $rc;
+    }
+}
diff --git a/app/Models/Review.php b/app/Models/Review.php
new file mode 100644 (file)
index 0000000..32c14ee
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\DB;
+use Hamatoma\Laraknife\ViewHelpers;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+
+class Review extends Model
+{
+    use HasFactory;
+    protected $table = 'reviews';
+    protected $fillable = [
+        'nickname',
+        'stars',
+        'title',
+        'comment',
+        'email'
+    ];
+}
diff --git a/database/migrations/2024_03_09_194857_create_reviews_table.php b/database/migrations/2024_03_09_194857_create_reviews_table.php
new file mode 100644 (file)
index 0000000..c280482
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration {
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        Schema::create('reviews', function (Blueprint $table) {
+            $table->id();
+            $table->timestamps();
+            $table->string('nickname');
+            $table->integer('stars');
+            $table->string('title');
+            $table->text('comment');
+            $table->string('email')->nullable();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::dropIfExists('reviews');
+    }
+};
diff --git a/resources/views/review/create.blade.php b/resources/views/review/create.blade.php
new file mode 100644 (file)
index 0000000..5471bd0
--- /dev/null
@@ -0,0 +1,16 @@
+@extends('layouts.backend')
+
+@section('content')
+    <form id="review-create" action="/review-store" method="POST">
+        @csrf
+        @method('PUT')
+        <x-laraknife.panels.create title="{{ __('Creation of a Review') }}">
+            <x-laraknife.forms.string position="first" name="nickname" label="Nickname" value="{{ $context->valueOf('nickname') }}" width2="4" />
+            <x-laraknife.forms.string position="last" name="email" label="Email" type="email" value="{{ $context->valueOf('email') }}" width2="4" />
+            <x-laraknife.forms.string position="alone" name="stars" label="Stars" type="integer" value="{{ $context->valueOf('stars') }}" width2="4" />
+            <x-laraknife.forms.string position="alone" name="title" label="Title" value="{{ $context->valueOf('title') }}" width2="10" />
+        <x-laraknife.forms.text position="alone" name="comment" label="Comment" value="{{ $context->valueOf('comment') }}" width2="10" rows="10" />
+            
+</x-laraknife.panels.create>
+    </form>
+@endsection
diff --git a/resources/views/review/edit.blade.php b/resources/views/review/edit.blade.php
new file mode 100644 (file)
index 0000000..d6f4ac0
--- /dev/null
@@ -0,0 +1,14 @@
+@extends('layouts.backend')
+
+@section('content')
+    <form id="review-edit" action="/review-update/{{ $context->model->id  }}" method="POST">
+        @csrf
+        <x-laraknife.panels.edit title="{{ __('Change of a Review') }}">
+            <x-laraknife.forms.string position="first" name="nickname" label="Nickname" value="{{ $context->valueOf('nickname') }}" width2="4" />
+            <x-laraknife.forms.string position="last" name="email" label="Email" type="email" value="{{ $context->valueOf('email') }}" width2="4" />
+            <x-laraknife.forms.string position="alone" name="stars" label="Stars" value="{{ $context->valueOf('stars') }}" width2="4" />
+            <x-laraknife.forms.string position="alone" name="title" label="Title" value="{{ $context->valueOf('title') }}" width2="10" />
+            <x-laraknife.forms.text position="alone" name="comment" label="Comment" value="{{ $context->valueOf('comment') }}" width2="10" rows="10" />
+        </x-laraknife.panels.edit>
+    </form>
+@endsection
diff --git a/resources/views/review/index.blade.php b/resources/views/review/index.blade.php
new file mode 100644 (file)
index 0000000..3bd3c6e
--- /dev/null
@@ -0,0 +1,40 @@
+@extends('layouts.backend')
+
+@section('content')
+<form id="review-index" action="/review-index" method="POST">
+    @csrf
+    <x-laraknife.panels.index title="{{ __('Reviews') }}">
+      <x-laraknife.panels.filter legend="{{ $pagination->legendText() }}">
+      <x-laraknife.forms.string position="first" name="text" label="Text" value="{{ $context->valueOf('text') }}" width2="4" />
+      <x-laraknife.forms.string position="last" name="stars" label="Stars" value="{{ $context->valueOf('stars') }}" width2="4" />
+      </x-laraknife.panels.filter>
+      <x-laraknife.panels.index-button buttonType="new"/>
+      <x-laraknife.panels.sortable-table :context="$context" :pagination="$pagination">
+        <thead>
+          <tr>
+            <th></th>
+            <th sortId="nickname">{{__('Nickname')}}</th>
+            <th sortId="stars">{{__('Stars')}}</th>
+            <th sortId="title">{{__('Title')}}</th>
+            <th sortId="comment">{{__('Comment')}}</th>
+            <th sortId="email">{{__('Email')}}</th>
+            <th></th>
+          </tr>
+        </thead>
+        <tbody>
+@foreach ($records as $review)
+        <tr>
+            <td><x-laraknife.icons.change-record module="review" no="{{ $review->id }}" /></td>
+              <td>{{$review->nickname}}</td>
+              <td>{{$review->stars}}</td>
+              <td>{{$review->title}}</td>
+              <td>{{$review->comment}}</td>
+              <td>{{$review->email}}</td>
+            <td><x-laraknife.icons.delete-record module="review" no="{{ $review->id }}" /></td>
+        </tr>
+@endforeach
+      </tbody>
+    </x-laraknife.panels.sortable-table>
+  </x-laraknife.panels.index>
+</form>
+@endsection
diff --git a/resources/views/review/show.blade.php b/resources/views/review/show.blade.php
new file mode 100644 (file)
index 0000000..89f4bc2
--- /dev/null
@@ -0,0 +1,17 @@
+@extends('layouts.backend')
+
+@section('content')
+    <form id="review-show" action="/review-show/{{ $context->model->id }}/{{ $mode }}" method="POST">
+        @csrf
+        @if($mode === 'delete')
+        @method('DELETE')
+        @endif
+        <x-laraknife.panels.show title="{{ __($mode !== 'delete' ? 'A Review' : 'Deletion of a Review') }}" mode="{{$mode}}">
+            <x-laraknife.forms.string position="first" name="nickname" label="Nickname" value="{{ $context->valueOf('nickname') }}" width2="4" attribute="readonly" />
+            <x-laraknife.forms.string position="last" name="email" label="Email" value="{{ $context->valueOf('email') }}" width2="4" attribute="readonly" />
+            <x-laraknife.forms.string position="alone" name="stars" label="Stars" value="{{ $context->valueOf('stars') }}" width2="4" attribute="readonly" />
+            <x-laraknife.forms.string position="alone" name="title" label="Title" value="{{ $context->valueOf('title') }}" width2="10" attribute="readonly" />
+            <x-laraknife.forms.text position="alone" name="comment" label="Comment" value="{{ $context->valueOf('comment') }}" width2="10" attribute="readonly" rows="10" />
+        </x-laraknife.panels.show>
+    </form>
+@endsection
index 04b4f16dd060f31915f0fca4b7dc82ac34a7d8e3..1d9b99a110d7e1ad2509092d7b40be886717e59f 100644 (file)
@@ -1,17 +1,18 @@
 <?php
 
 use Illuminate\Support\Facades\Route;
-use App\Http\Controllers\RoleController;
-use App\Http\Controllers\UserController;
-use App\Http\Controllers\SPropertyController;
-use App\Http\Controllers\MenuitemController;
-use App\Http\Controllers\NoteController;
 use App\Http\Controllers\FileController;
-use App\Http\Controllers\WordController;
+use App\Http\Controllers\NoteController;
 use App\Http\Controllers\NounController;
+use App\Http\Controllers\RoleController;
+use App\Http\Controllers\TermController;
+use App\Http\Controllers\UserController;
 use App\Http\Controllers\VerbController;
+use App\Http\Controllers\WordController;
 use App\Http\Controllers\PhraseController;
-use App\Http\Controllers\TermController;
+use App\Http\Controllers\ReviewController;
+use App\Http\Controllers\MenuitemController;
+use App\Http\Controllers\SPropertyController;
 
 Route::get('/', function () {
     return redirect('/menuitem-menu_main');
@@ -30,3 +31,4 @@ NounController::routes();
 VerbController::routes();
 
 PhraseController::routes();
+ReviewController::routes();