diff --git a/app/Models/Actu.php b/app/Models/Actu.php new file mode 100644 index 00000000..2b7810c0 --- /dev/null +++ b/app/Models/Actu.php @@ -0,0 +1,71 @@ +header = clean($actu->header); + $actu->content = clean($actu->content); + }); + static::updating(function (Actu $actu) { + $actu->header = clean($actu->header); + $actu->content = clean($actu->content); + }); + // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass + static::created(function (Actu $actu) { + Cache::delete('ActusGlobal'); + }); + // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass + static::updated(function (Actu $actu) { + Cache::delete('ActusGlobal'); + }); + // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass + static::deleted(function (Actu $actu) { + Cache::delete('ActusGlobal'); + }); + } + + public function getRouteKeyName() + { + return 'slug'; + } + + public function tags() + { + return $this->morphToMany(Tag::class, 'taggable'); + } + + public function notifiable() + { + return $this->morphOne(Notifications::class, 'notifiable'); + } + + public static function getCachedActus() + { + if (!Cache::has('ActusGlobal')) { + self::setCachedActus(); + } + return Cache::get('ActusGlobal'); + } + + protected static function setCachedActus() + { + $actus = Actu::with('tags')->whereStatus(true)->whereFront(true) + ->orderBy('updated_at', 'DESC')->limit(3)->get(); + Cache::put('ActusGlobal', $actus); + } +} diff --git a/app/Models/Tag.php b/app/Models/Tag.php new file mode 100644 index 00000000..449fcbaa --- /dev/null +++ b/app/Models/Tag.php @@ -0,0 +1,37 @@ +slug = Str::slug($tag->name); + }); + static::updating(function (Tag $tag) { + $tag->slug = Str::slug($tag->name); + }); + } + + public function getRouteKeyName() + { + return 'slug'; + } + + public function actus() + { + return $this->morphedByMany(Actu::class, 'taggable'); + } +} diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index cdf5d55e..7b6d62ad 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,6 +2,7 @@ namespace App\Providers; +use App\Models\Actu; use App\Models\Articles; use App\Models\Moments; use Carbon\Carbon; @@ -58,6 +59,12 @@ class AppServiceProvider extends ServiceProvider Log::critical($e->getMessage()); View::share('momentFiche', false); } + try { + View::share('ActusGlobal', Actu::getCachedActus() ?? []); + } catch (\Exception $e) { + Log::critical($e->getMessage()); + View::share('ActusGlobal', []); + } try { View::share('ArticlesGlobal', Articles::getCachedArticles() ?? []); } catch (\Exception $e) { diff --git a/config/image-resizer.php b/config/image-resizer.php index 1995ae20..e89616d8 100644 --- a/config/image-resizer.php +++ b/config/image-resizer.php @@ -83,6 +83,22 @@ return [ 'inCanvas' => true, 'format' => 'png', 'trim' => true + ], + 'actuFront' => [ + 'height' => 244, + 'width' => 366, + 'format' => 'png', + 'resize' => true, + 'inCanvas' => true, + 'keepRatio' => true + ], + 'actuFrontWebp' => [ + 'height' => 244, + 'width' => 366, + 'format' => 'webp', + 'resize' => true, + 'inCanvas' => true, + 'keepRatio' => true ] ] ]; diff --git a/database/factories/ActusFactory.php b/database/factories/ActusFactory.php new file mode 100644 index 00000000..32f10d2b --- /dev/null +++ b/database/factories/ActusFactory.php @@ -0,0 +1,33 @@ +define(Actu::class, function (Faker $faker) use (&$i) { + $title = implode(' ', $faker->unique()->words(rand(6, 12))); + $front = ($i++ <= 3 ? true : false); + return [ + 'title' => $title, + 'slug' => \Illuminate\Support\Str::slug($title), + 'header' => $faker->text(300), + 'content' => $faker->text(1500), + 'picture' => '/assets/images/actu_fake_image.jpg', + 'picture_alt' => 'Image de champs', + 'front' => $front, + 'status' => $front ?: (bool)rand(0, 1) + ]; +}); diff --git a/database/factories/TagFactory.php b/database/factories/TagFactory.php new file mode 100644 index 00000000..03cf498d --- /dev/null +++ b/database/factories/TagFactory.php @@ -0,0 +1,23 @@ +define(Tag::class, function (Faker $faker) { + return [ + 'name' => implode(' ', $faker->words(rand(1, 2))) + ]; +}); diff --git a/database/migrations/2021_09_16_100041_create_taggables_table.php b/database/migrations/2021_09_16_100041_create_taggables_table.php new file mode 100644 index 00000000..77c5508f --- /dev/null +++ b/database/migrations/2021_09_16_100041_create_taggables_table.php @@ -0,0 +1,32 @@ +bigInteger('tag_id'); + $table->bigInteger('taggable_id'); + $table->string('taggable_type', 60); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('taggables'); + } +} diff --git a/database/migrations/2021_09_16_100042_create_tags_table.php b/database/migrations/2021_09_16_100042_create_tags_table.php new file mode 100644 index 00000000..cbb0a55a --- /dev/null +++ b/database/migrations/2021_09_16_100042_create_tags_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('slug')->unique(); + $table->string('name'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('tags'); + } +} diff --git a/database/migrations/2021_09_16_101055_create_actus_table.php b/database/migrations/2021_09_16_101055_create_actus_table.php new file mode 100644 index 00000000..bdf844a3 --- /dev/null +++ b/database/migrations/2021_09_16_101055_create_actus_table.php @@ -0,0 +1,44 @@ +id(); + + $table->string('title'); + $table->string('slug'); + $table->text('header'); + $table->string('picture'); + $table->string('picture_alt'); + $table->mediumText('content'); + + // affiché en front page ? + $table->boolean('front'); + + $table->boolean('status'); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('actus'); + } +} diff --git a/database/seeds/ActuSeeder.php b/database/seeds/ActuSeeder.php new file mode 100644 index 00000000..9d452dbc --- /dev/null +++ b/database/seeds/ActuSeeder.php @@ -0,0 +1,33 @@ +truncate(); + $this->call([ + TagSeeder::class + ]); + Actu::truncate(); + $tags = Tag::query()->get(); + factory(Actu::class, 28)->create() + ->each(function ($actu) use ($tags) { + $offset = rand(0, 5); + $length = rand(1, 4); + $actu->tags() + ->saveMany($tags->slice($offset, $length)); + $actu->save(); + }); + } +} diff --git a/database/seeds/TagSeeder.php b/database/seeds/TagSeeder.php new file mode 100644 index 00000000..be54b378 --- /dev/null +++ b/database/seeds/TagSeeder.php @@ -0,0 +1,19 @@ +create(); + } +} diff --git a/resources/assets/images/actu_fake_image.jpg b/resources/assets/images/actu_fake_image.jpg new file mode 100644 index 00000000..5390d64b Binary files /dev/null and b/resources/assets/images/actu_fake_image.jpg differ diff --git a/resources/assets/images/onsengage/cest-bon-detre-engage.svg b/resources/assets/images/onsengage/cest-bon-detre-engage.svg new file mode 100644 index 00000000..7ce8bce3 --- /dev/null +++ b/resources/assets/images/onsengage/cest-bon-detre-engage.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/resources/sass/_variables.scss b/resources/sass/_variables.scss index 0e97d92c..49d2edb6 100644 --- a/resources/sass/_variables.scss +++ b/resources/sass/_variables.scss @@ -69,6 +69,9 @@ $engagementDarkGreen: #006633; $engagementLightGreen: #8AC51D; $engagementMajorBreakPoint: $big_screen + 30px; +// Actus +$actuTime: #A29094; + // Body $body-bg: $color1; diff --git a/resources/sass/front/pages/_home.scss b/resources/sass/front/pages/_home.scss index 326f564e..8a480960 100644 --- a/resources/sass/front/pages/_home.scss +++ b/resources/sass/front/pages/_home.scss @@ -717,6 +717,219 @@ } } + & .actus { + + $containerMaxWidth: 77.466rem; // 1162px + $articleMaxWith: 24.4rem; // 366px + $articleMaxHeigth: 41.6rem; // 609px + $articleGutter: 2.13rem; // 32px + display: flex; + justify-content: center; + + & .container { + display: flex; + flex-direction: column; + align-items: center; + + max-width: $containerMaxWidth; + width: 100%; + + & .header { + margin-top: 6.53rem; + & h3 { + font-size: 3rem; + font-family: 'Veneer'; + } + } + + & .card { + display: flex; + flex-direction: row; + margin-top: 3.2rem; + + & article { + max-height: $articleMaxHeigth; + max-width: $articleMaxWith; + background-color: #FFF; + + display: flex; + flex-direction: column; + justify-content: space-between; + + &:first-child { + margin-right: $articleGutter; + } + &:last-child { + margin-left: $articleGutter; + } + + & > a { + position: relative; + display: block; + & i.engagement { + z-index: 1; + height: 7.999rem; + width: 8.675rem; + position: absolute; + bottom: 1.599rem; + left: 1.579rem; + content: " "; + background-image: url("~@/images/onsengage/cest-bon-detre-engage.svg"); + background-size: contain; + } + & picture { + overflow: hidden; + position: relative; + width: $articleMaxWith; + & img { + object-fit: contain; + } + } + .hoverFigure { + background-color: $engagementDarkGreen; + z-index: 2; + position: absolute; + top: 0; + left: 0; + height: 100%; + width: 100%; + opacity: 0; + display: flex; + justify-content: center; + align-items: center; + transition: opacity 500ms ease 0s; + cursor: pointer; + + &:hover { + opacity: 0.88; + } + + h5 { + user-select: none; + color: #ffffff; + font-size: 2.534rem; + position: relative; + font-family: 'CreamyScriptRegular'; + + &:before { + background-image: url('~@/images/recette/hoverRecette.png'); + display: inline-block; + content: ""; + width: 2.5em; + height: 1em; + position: absolute; + top: -0.8em; + left: 50%; + transform: translateX(-50%); + } + &:after { + background-image: url('~@/images/recette/hoverRecette.png'); + display: inline-block; + content: ""; + width: 2.5em; + height: 1em; + transform: rotate(180deg) translateX(54%); + position: absolute; + top: 1em; + left: 50%; + } + } + } + + } + + & header { + margin: 0 1.6rem; + margin-top: 1.6rem; + + & div.tags { + & span { + font-family: "Veneer"; + font-size: 1.867rem; + color: $engagementDarkGreen; + text-transform: uppercase; + } + } + & h4 { + margin-top: 1.066rem; + margin-bottom: 1.066rem; + font-family: "Catamaran-Black"; + text-transform: uppercase; + color: $color5; + font-size: 1.2rem; + line-height: 1.733rem; + } + } + + & section { + margin: 0 1.6rem; + font-family: "Catamaran-Regular"; + color: $color5; + font-size: 1.2rem; + line-height: 1.8666rem; + } + & footer { + display: flex; + flex-direction: row; + justify-content: space-between; + margin: 0 1.6rem; + margin-top: 1.6rem; + margin-bottom: 1.066rem; + + & time { + font-family: "CreamyScriptRegular"; + font-size: 1.066rem; + color: $actuTime; + } + & a.link { + font-family: "Catamaran-Bold"; + font-size: 0.933rem; + color: $engagementDarkGreen; + text-decoration: underline; + } + } + } + + @include max-width($containerMaxWidth) { + flex-direction: column; + & article { + &:first-child { + margin-right: inherit !important; + margin-bottom: $articleGutter; + } + &:last-child { + margin-left: inherit !important; + margin-top: $articleGutter; + } + } + } + } + + & .footer { + padding-top: 1.799rem; + & > a { + background-color: $engagementDarkGreen; + color: #FFF; + display: inline-block; + min-height: 2.867rem; + font-family: 'Catamaran-Bold'; + font-size: 1.066rem; + font-weight: bold; + padding: 0.6rem 1rem; + border-radius: 2rem; + text-transform: uppercase; + line-height: 1.733rem; + + &:hover { + background-color: #082014 !important; + text-decoration: underline !important; + cursor: pointer; + } + } + } + } + } + & #btnEnd { max-width: 1200px; margin: 50px auto 0 auto; diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index aeb45fc7..7a119b45 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -124,6 +124,50 @@ +
+
+
+

{{ __('Actualités') }}

+
+
+ @foreach($ActusGlobal as $actu) + + @endforeach +
+ +
+

{{ __('Profitez d\'offres exclusives !') }}

diff --git a/resources/views/layouts/app-footer.blade.php b/resources/views/layouts/app-footer.blade.php index 096cdda2..7c41f701 100644 --- a/resources/views/layouts/app-footer.blade.php +++ b/resources/views/layouts/app-footer.blade.php @@ -14,6 +14,7 @@