diff --git a/.gitignore b/.gitignore index 7e0a0db..e6438ce 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ /node_modules /integration/node_modules /public/hot +public/uploads/* +!public/uploads/.gitkeep /public/storage /storage/*.key /vendor diff --git a/app/Http/Controllers/Bo/ArticlesController.php b/app/Http/Controllers/Bo/ArticlesController.php index 5ef14fd..9d50a77 100644 --- a/app/Http/Controllers/Bo/ArticlesController.php +++ b/app/Http/Controllers/Bo/ArticlesController.php @@ -27,8 +27,8 @@ class ArticlesController extends Controller { $request->validate([ 'title' => 'required|max:100', - 'picture' => 'required|image|mimes:jpeg,png,jpg|max:2048|dimensions:width=340,height=340', - 'picture_r' => 'required|image|mimes:jpeg,png,jpg|max:2048|dimensions:width=780,height=508', + 'picture' => 'required|image|mimes:jpeg,png,jpg|max:2048|dimensions:max-width=340,max-height=340', + 'picture_r' => 'required|image|mimes:jpeg,png,jpg|max:2048|dimensions:max-width=780,max-height=508', 'content' => 'required', ]); @@ -39,19 +39,6 @@ class ArticlesController extends Controller $content = $request->content; $categoryId = $request->category; $status = 0; - $notification = $request->notification === null ? 0 : 1; - - if ($categoryId === "4") { - $question = $request->question; - $multipleResponse = $request->multiple_response === null ? 0 : 1; - $stopPoll = $request->stop_poll === null ? 0 : 1; - $answers = $request->answers; - - $request->validate([ - 'question' => 'required|max:255', - 'answers' => 'required', - ]); - } $imageName = Str::slug($title) .'-le-gaulois-' . date('d-m-Y') . '.' . $picture->extension(); $picture->move(public_path('uploads/images/articles/' . date('Y') . '/' . date('m')), $imageName); @@ -65,23 +52,8 @@ class ArticlesController extends Controller $a->picture_r = 'uploads/images/articles/' . date('Y') . '/' . date('m') . '/' . $imageName_r; $a->content = $content; $a->category_id = $categoryId; - if ($categoryId === "4") { - $a->question = $question; - $a->multiple_response = $multipleResponse; - $a->stop_poll = $stopPoll; - } $a->status = $status; - $a->notification = $notification; $a->save(); - if ($categoryId === "4") { - foreach ($answers as $answer) { - if (!empty($answer)) { - $a->answers()->create([ - 'answer' => $answer, - ]); - } - } - } return redirect()->route('bo.articles.index'); } @@ -110,19 +82,6 @@ class ArticlesController extends Controller $content = $request->content; $categoryId = $request->category; $status = $request->status === null ? 0 : 1; - $notification = $request->notification === null ? 0 : 1; - - if ($categoryId === "4") { - $question = $request->question; - $multipleResponse = $request->multiple_response === null ? 0 : 1; - $stopPoll = $request->stop_poll === null ? 0 : 1; - $answers = $request->answers; - - $request->validate([ - 'question' => 'required|max:255', - 'answers' => 'required', - ]); - } if ($picture !== NULL && $picture_r !== NULL){ $request->validate([ @@ -162,26 +121,7 @@ class ArticlesController extends Controller $a->picture_r = 'uploads/images/articles/' . date('Y') . '/' . date('m') . '/' . $imageName_r; $a->content = $content; $a->category_id = $categoryId; - if ($categoryId === "4") { - $a->question = $question; - $a->multiple_response = $multipleResponse; - $a->stop_poll = $stopPoll; - $a->answers()->delete(); - foreach ($answers as $answer) { - if (!empty($answer)) { - $a->answers()->create([ - 'answer' => $answer, - ]); - } - } - } else { - $a->question = null; - $a->multiple_response = null; - $a->stop_poll = null; - $a->answers()->delete(); - } $a->status = $status; - $a->notification = $notification; $a->save(); if ($a->category_id == 1 && $a->status === 1) { diff --git a/app/Http/Controllers/Bo/HomeSlidersController.php b/app/Http/Controllers/Bo/HomeSlidersController.php index c2bf8c0..0ebb252 100644 --- a/app/Http/Controllers/Bo/HomeSlidersController.php +++ b/app/Http/Controllers/Bo/HomeSlidersController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Bo; use App\Http\Controllers\Controller; use App\Models\HomeSliders; use Illuminate\Http\Request; +use Illuminate\Support\Str; class HomeSlidersController extends Controller { @@ -37,7 +38,39 @@ class HomeSlidersController extends Controller */ public function store(Request $request) { - // + $title = $request->title; + $picture = $request->picture; + $text = $request->text; + $linkLabel = $request->link_label; + $link = $request->link; + $newTab = $request->link_new_tab === null ? 0 : 1; + $status = 0; + + $request->validate([ + 'title' => 'required|max:255', + 'picture' => 'required|image|mimes:jpeg,png,jpg|max:2048|dimensions:max-width=300,max-height=300', + 'link_label' => 'required|max:100', + 'link' => 'required|max:255', + ]); + + $imageName = Str::slug($title) .'-jeusselin.'.$picture->extension(); + $picture->move(public_path('uploads/images/slider_accueil/' . date('Y') . '/' . date('m') . '/'), $imageName); + // $imageName_r = Str::slug($title) .'-jeusselin_r.'.$picture_r->extension(); + // $picture_r->move(public_path('uploads/images/slider_accueil/' . date('Y') . '/' . date('m') . '/'), $imageName_r); + + $hsp = new HomeSliders(); + $hsp->title = $title; + $hsp->picture = 'uploads/images/slider_accueil/' . date('Y') . '/' . date('m') . '/' . $imageName; + //$hsp->picture_r = 'uploads/images/slider_accueil/' . date('Y') . '/' . date('m') . '/' . $imageName_r; + $hsp->text = $text; + $hsp->link_label = $linkLabel; + $hsp->link = $link; + $hsp->link_new_tab = $newTab; + $hsp->status = $status; + $hsp->order = $this->getLastOrder(); + $hsp->save(); + + return redirect()->route('bo.home-sliders.index'); } /** @@ -59,7 +92,8 @@ class HomeSlidersController extends Controller */ public function edit($id) { - // + $h = HomeSliders::findOrFail($id); + return view('bo.home-sliders.edit', compact('h')); } /** @@ -71,7 +105,65 @@ class HomeSlidersController extends Controller */ public function update(Request $request, $id) { - // + $title = $request->title; + $picture = $request->picture; + $picture_r = null; //$request->picture_r; + $text = $request->text; + $linkLabel = $request->link_label; + $link = $request->link; + $newTab = $request->link_new_tab === null ? 0 : 1; + $status = $request->status === null ? 0 : 1; + + $request->validate([ + 'title' => 'required|max:255', + 'link_label' => 'required|max:100', + 'link' => 'required|max:255', + ]); + + if ($picture !== NULL && $picture_r !== NULL){ + $request->validate([ + 'picture' => 'image|mimes:jpeg,png,jpg|max:2048|dimensions:max-width=300,max-height=300', + 'picture_r' => 'image|mimes:jpeg,png,jpg|max:2048|dimensions:width=500,height=671', + ]); + }elseif ($picture !== NULL && $picture_r === NULL){ + $request->validate([ + 'picture' => 'required|image|mimes:jpeg,png,jpg|max:2048|dimensions:max-width=300,max-height=300' + ]); + }elseif ($picture === NULL && $picture_r !== NULL){ + $request->validate([ + 'picture_r' => 'required|image|mimes:jpeg,png,jpg|max:2048|dimensions:width=500,height=671' + ]); + } + + $hsp = HomeSliders::findOrFail($id); + + if ($picture !== NULL){ + if(file_exists(public_path() . '/' . $hsp->picture)) + unlink(public_path() . '/' . $hsp->picture); + $imageName = Str::slug($title) .'-jeusselin.'.$picture->extension(); + $picture->move(public_path('uploads/images/slider_accueil/' . date('Y') . '/' . date('m') . '/'), $imageName); + } + if ($picture_r !== NULL) { + if(file_exists(public_path() . '/' . $hsp->picture_r)) + unlink(public_path() . '/' . $hsp->picture_r); + $imageName_r = Str::slug($title) . '-jeusselin_r.' . $picture_r->extension(); + $picture_r->move(public_path('uploads/images/slider_accueil/' . date('Y') . '/' . date('m') . '/'), $imageName_r); + } + + $hsp->title = $title; + if ($picture !== null) + $hsp->picture = 'uploads/images/slider_accueil/' . date('Y') . '/' . date('m') . '/' . $imageName; + if ($picture_r !== null) + $hsp->picture_r = 'uploads/images/slider_accueil/' . date('Y') . '/' . date('m') . '/' . $imageName_r; + $hsp->text = $text; + $hsp->link_label = $linkLabel; + $hsp->link = $link; + $hsp->link_new_tab = $newTab; + + $hsp->status = $status; + $hsp->save(); + + return redirect()->route('bo.home-sliders.edit', $hsp->id)->with('success', 'Enregistré !'); } /** @@ -82,6 +174,46 @@ class HomeSlidersController extends Controller */ public function destroy($id) { - // + $h = HomeSliders::findOrFail($id); + + if(file_exists(public_path() . '/' . $h->picture)) + unlink(public_path() . '/' . $h->picture); + if(!is_null($h->picture_r)) { + if(file_exists(public_path() . '/' . $h->picture_r)) + unlink(public_path() . '/' . $h->picture_r); + } + + $h->delete(); + + return redirect()->route('bo.home-sliders.index'); + } + + public function changeOrder($id, $action) + { + $current = HomeSliders::findOrFail($id); + + if ($action === 'up'){ + $tmp = HomeSliders::where('order', '<', $current->order)->orderBy('order', 'DESC')->first(); + $newOrder = $tmp->order; + $tmp->order = $current->order; + $current->order = $newOrder; + }else{ + $tmp = HomeSliders::where('order', '>', $current->order)->orderBy('order', 'ASC')->first(); + $newOrder = $tmp->order; + $tmp->order = $current->order; + $current->order = $newOrder; + } + $tmp->save(); + $current->save(); + + return redirect()->route('bo.home-sliders.index'); + } + + private function getLastOrder() + { + $order = HomeSliders::select('order')->orderBy('order', 'DESC')->first(); + if ($order === NULL) + return 1; + return $order->order + 1; } } diff --git a/database/migrations/2021_02_19_103030_create_home_slider_pictures_table.php b/database/migrations/2021_02_19_103030_create_home_slider_pictures_table.php index c6bf17a..08afad0 100644 --- a/database/migrations/2021_02_19_103030_create_home_slider_pictures_table.php +++ b/database/migrations/2021_02_19_103030_create_home_slider_pictures_table.php @@ -21,7 +21,7 @@ class CreateHomeSliderPicturesTable extends Migration $table->string('title'); $table->text('text'); $table->string('picture'); - $table->string('picture_r'); + $table->string('picture_r')->nullable(); $table->string('link_label', 100); $table->string('link'); $table->boolean('link_new_tab')->default(false); diff --git a/database/migrations/2021_02_19_112146_create_articles_table.php b/database/migrations/2021_02_19_112146_create_articles_table.php index 6fb3dee..cb887a0 100644 --- a/database/migrations/2021_02_19_112146_create_articles_table.php +++ b/database/migrations/2021_02_19_112146_create_articles_table.php @@ -22,10 +22,6 @@ class CreateArticlesTable extends Migration $table->string('picture'); $table->string('picture_r'); $table->text('content'); - $table->string('question')->nullable(); - $table->integer('multiple_response')->nullable(); - $table->integer('stop_poll')->nullable(); - $table->integer('notification')->default(0); $table->boolean('status')->default(false); diff --git a/public/uploads/.gitkeep b/public/uploads/.gitkeep new file mode 100644 index 0000000..d8a1a27 --- /dev/null +++ b/public/uploads/.gitkeep @@ -0,0 +1 @@ +gitkeep \ No newline at end of file diff --git a/resources/views/bo/articles/create.blade.php b/resources/views/bo/articles/create.blade.php index 2770282..1be9d7e 100644 --- a/resources/views/bo/articles/create.blade.php +++ b/resources/views/bo/articles/create.blade.php @@ -26,11 +26,11 @@
-
+
-
+
@@ -45,44 +45,6 @@ @endforeach
-
-
- -
-
- -
-
- -
-
- Ajouter une réponse -
-
- - - - - - - - - -
RéponseAction
-
-
-
- -
@@ -95,76 +57,6 @@ @section('scripts') @endsection diff --git a/resources/views/bo/articles/edit.blade.php b/resources/views/bo/articles/edit.blade.php index 1fa31cb..04f7b64 100644 --- a/resources/views/bo/articles/edit.blade.php +++ b/resources/views/bo/articles/edit.blade.php @@ -66,62 +66,6 @@ @endforeach -
-
- -
-
- -
-
- -
-
- Ajouter une réponse -
-
- - - - - - - - - @for($i = 0; $i < count($a->answers); $i++) - - - - - @endfor - -
RéponseAction
Supprimer
-
-
-
- -
- +
diff --git a/resources/views/bo/home-sliders/edit.blade.php b/resources/views/bo/home-sliders/edit.blade.php index 85c66f0..a28fe81 100644 --- a/resources/views/bo/home-sliders/edit.blade.php +++ b/resources/views/bo/home-sliders/edit.blade.php @@ -1,169 +1,85 @@ @extends('layouts.bo') @section('content') -
-
- Modification d'une slide pour l'accueil - Retour -
- @method('DELETE') - @csrf - -
-
- -
-
- @method('PUT') - @csrf - @if (session('success')) -
- {{ session('success') }} -
- @endif - @if ($errors->any()) -
-
    - @foreach ($errors->all() as $error) -
  • {{ $error }}
  • - @endforeach -
-
- @endif -
    -
  • Champs généraux
  • -
    -
    -
    -
    -
    - -
    -
    - - -
    -
    -
    -
    - -
    -
    - - -
    -
    -
    -
    - -
    -
    - -
    -
    -
    - -
    -
    - -
    -
    -
    -
    -
  • Options de liens
  • -
    -
    -
    -
    - -
    -
    -
    - -
    -
    - - -
    -
    -
    - -
    -
    -
    -
    -
  • Paramètres de publications
  • -
    -
    -
    -
    - -
    -
    - -
    -
    - -
    -
    - -
    -
    - -
    -
    - -
    -
    - -
    -
    - -
    -
    - -
    -
    -
    -
    -
-
-
+
+
+ Slides de l'acceuil - edition + Retour +
+ @method('DELETE') + @csrf + +
+ + + @if (session('success')) +
+ {{ session('success') }} +
+ @endif + @if ($errors->any()) +
+
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+
+ @endif +
+ @method('PUT') + @csrf +
    +
  • Champs généraux
  • +
    +
    +
    +
    + +
    +
    + +
    +
    + + +
    +
    + +
    +
    +
    +
    +
  • Options de liens
  • +
    +
    +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    +
    +
    + + +
+ @endsection diff --git a/resources/views/bo/home-sliders/index.blade.php b/resources/views/bo/home-sliders/index.blade.php index 5750b2c..48c8cbe 100644 --- a/resources/views/bo/home-sliders/index.blade.php +++ b/resources/views/bo/home-sliders/index.blade.php @@ -24,10 +24,10 @@ {{$slide->title}} {{$slide->text}} - {{$slide->picture}} + {{$slide->link_label}} {{$slide->status}} - Éditer + Éditer @endforeach