diff --git a/app/Console/Commands/UpdateNewsStatus.php b/app/Console/Commands/UpdateNewsStatus.php new file mode 100644 index 0000000..a657df6 --- /dev/null +++ b/app/Console/Commands/UpdateNewsStatus.php @@ -0,0 +1,33 @@ +job(NewsStatusUpdate::class)->everyMinute(); + $schedule->job(SeasonalSectionStatusUpdate::class)->everyMinute(); } /** diff --git a/app/Enums/News/CategoryEnum.php b/app/Enums/News/CategoryEnum.php new file mode 100644 index 0000000..a5f8190 --- /dev/null +++ b/app/Enums/News/CategoryEnum.php @@ -0,0 +1,27 @@ +name => 'La vie d\'Entreprise', + self::convictions->name => 'Nos convictions', + self::recipes->name => 'Nos recettes', + self::jobs->name => 'Nos métiers', + self::communication->name => 'Communication', + ]; +} diff --git a/app/Enums/Products/CookingModeEnum.php b/app/Enums/Products/CookingModeEnum.php new file mode 100644 index 0000000..2b2824c --- /dev/null +++ b/app/Enums/Products/CookingModeEnum.php @@ -0,0 +1,27 @@ +name => 'Micro-ondes', + self::furnace->name => 'Four traditionnel', + self::waterbath->name => 'Bain-marie', + self::pan->name => 'Poêle', + self::fresh->name => 'Se consomme frais', + ]; +} diff --git a/app/Enums/SeasonalSections/BackgroundEnum.php b/app/Enums/SeasonalSections/BackgroundEnum.php new file mode 100644 index 0000000..daa6790 --- /dev/null +++ b/app/Enums/SeasonalSections/BackgroundEnum.php @@ -0,0 +1,23 @@ +name => 'Chandeleur', + self::chinesenewyear->name => 'Nouvel an chinois', + self::endofyear->name => 'Fin d\'année', + ]; +} diff --git a/app/Enums/StaticPageType.php b/app/Enums/StaticPageType.php new file mode 100644 index 0000000..6af3f76 --- /dev/null +++ b/app/Enums/StaticPageType.php @@ -0,0 +1,37 @@ +name => 'Contact', + self::legals->name => 'Mentions légales', + self::confidentiality->name => 'Confidentialité', + self::home->name => 'Accueil', + self::conviction->name => 'Nos Convictions', + self::explorer->name => 'Explorate & Gastronome', + self::joinus->name => 'Rejoignez-nous', + self::ranges->name => 'Nos Gammes de Produits', + self::aboutus->name => 'Nous Connaître', + self::news->name => 'Actualités', + ]; +} diff --git a/app/Jobs/NewsStatusUpdate.php b/app/Jobs/NewsStatusUpdate.php new file mode 100644 index 0000000..5e13fe4 --- /dev/null +++ b/app/Jobs/NewsStatusUpdate.php @@ -0,0 +1,46 @@ + */ + $newsListToPublish = News::query() + ->where('publish_at', '<=', Carbon::now()->toDateTime()) + ->whereNotNull('publish_at') + ->where('published', false)->get(); + Log::debug(__CLASS__ . " news to publish " . $newsListToPublish->count()); + foreach ($newsListToPublish as $news) { + $news->publish_at = null; + $news->published = true; + $news->saveOrFail(); + } + /** @var \Illuminate\Database\Eloquent\Collection */ + $newsListToUnPublish = News::query() + ->where('unpublish_at', '<=', Carbon::now()->toDateTime()) + ->whereNotNull('unpublish_at') + ->where('published', true)->get(); + Log::debug(__CLASS__ . " news to unpublish " . $newsListToPublish->count()); + foreach ($newsListToUnPublish as $news) { + $news->publish_at = null; + $news->unpublish_at = null; + $news->published = false; + $news->saveOrFail(); + } + } +} diff --git a/app/Jobs/SeasonalSectionStatusUpdate.php b/app/Jobs/SeasonalSectionStatusUpdate.php new file mode 100644 index 0000000..22ca262 --- /dev/null +++ b/app/Jobs/SeasonalSectionStatusUpdate.php @@ -0,0 +1,46 @@ + */ + $seasonalsectionsListToPublish = SeasonalSection::query() + ->where('publish_at', '<=', Carbon::now()->toDateTime()) + ->whereNotNull('publish_at') + ->where('published', false)->get(); + Log::debug(__CLASS__ . " seasonalsections to publish " . $seasonalsectionsListToPublish->count()); + foreach ($seasonalsectionsListToPublish as $seasonalsections) { + $seasonalsections->publish_at = null; + $seasonalsections->published = true; + $seasonalsections->saveOrFail(); + } + /** @var \Illuminate\Database\Eloquent\Collection */ + $seasonalsectionsListToUnPublish = SeasonalSection::query() + ->where('unpublish_at', '<=', Carbon::now()->toDateTime()) + ->whereNotNull('unpublish_at') + ->where('published', true)->get(); + Log::debug(__CLASS__ . " seasonalsections to unpublish " . $seasonalsectionsListToPublish->count()); + foreach ($seasonalsectionsListToUnPublish as $seasonalsections) { + $seasonalsections->publish_at = null; + $seasonalsections->unpublish_at = null; + $seasonalsections->published = false; + $seasonalsections->saveOrFail(); + } + } +} diff --git a/app/Lib/Helpers/FileStorageHelper.php b/app/Lib/Helpers/FileStorageHelper.php index 45ccec9..f5b864b 100644 --- a/app/Lib/Helpers/FileStorageHelper.php +++ b/app/Lib/Helpers/FileStorageHelper.php @@ -451,4 +451,22 @@ class FileStorageHelper $filename = trim($filename, '.-'); return $filename; } + + /** + * Remove all model files for the given Model. + * + * @param Model $model + * @return void + */ + public static function removeModelFiles(Model $model): void + { + $tableName = $model::query()->getModel()->getTable(); + + if (!empty(Storage::disk('public')->allFiles("modelfiles/{$tableName}"))) { + Storage::disk('public')->deleteDirectory("modelfiles/{$tableName}"); + } + if (!empty(Storage::disk('private')->allFiles("modelfiles/{$tableName}"))) { + Storage::disk('private')->deleteDirectory("modelfiles/{$tableName}"); + } + } } diff --git a/app/Models/Commitment.php b/app/Models/Commitment.php new file mode 100644 index 0000000..8c65194 --- /dev/null +++ b/app/Models/Commitment.php @@ -0,0 +1,108 @@ + + */ + protected $fillable = [ + 'title', + 'picture', + 'picture_alt', + 'picture_title', + 'published', + 'order', + ]; + + /** + * The attributes that should be cast. + * + * @var array + */ + protected $casts = [ + 'published' => 'bool', + ]; + + /** + * Perform any actions required after the model boots. + * + * @return void + */ + protected static function booted(): void + { + static::creating(function (self $model) { + self::setOrder($model); + $model->picture = FileStorageHelper::storeFile($model, $model->picture, true); + }); + static::updating(function (self $model) { + $model->picture = FileStorageHelper::storeFile($model, $model->picture, true); + }); + static::updated(function (self $model) { + FileStorageHelper::removeOldFile($model, 'picture'); + }); + + static::deleted(function (self $model) { + FileStorageHelper::removeFile($model, 'picture'); + }); + } + + // * METHODS + + /** + * Set order after the last element of the list. + * + * @param self $model + * @return void + */ + private static function setOrder(self $model): void + { + $model->order = \intval(self::query()->max('order')) + 1; + } + + // * RELATIONS + + /** + * The products that belong to the commitment. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function products(): \Illuminate\Database\Eloquent\Relations\BelongsToMany + { + return $this->belongsToMany(Product::class); + } + + /** + * The page that belong to the commitment. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function explorerpage(): \Illuminate\Database\Eloquent\Relations\BelongsToMany + { + return $this->belongsToMany(Explorerpage::class); + } +} diff --git a/app/Models/Convictionpage.php b/app/Models/Convictionpage.php new file mode 100644 index 0000000..e22e77c --- /dev/null +++ b/app/Models/Convictionpage.php @@ -0,0 +1,56 @@ + + */ + protected $fillable = [ + 'key_feed', + 'key_earth_1', + 'key_earth_2', + 'key_together_1', + 'key_together_2', + 'key_together_3', + 'key_together_4', + 'key_territory', + ]; + + /** + * Perform any actions required after the model boots. + * + * @return void + */ + protected static function booted(): void + { + static::creating(function () { + throw new \RuntimeException("Creating a new page is not authorized"); + }); + static::deleting(function () { + throw new \RuntimeException('Deleting a page is not authorized'); + }); + } +} diff --git a/app/Models/Explorerpage.php b/app/Models/Explorerpage.php new file mode 100644 index 0000000..a767d5b --- /dev/null +++ b/app/Models/Explorerpage.php @@ -0,0 +1,83 @@ + + */ + protected $fillable = [ + 'picture_1', + 'picture_1_alt', + 'picture_1_title', + 'picture_2', + 'picture_2_alt', + 'picture_2_title', + 'picture_3', + 'picture_3_alt', + 'picture_3_title', + ]; + + /** + * Perform any actions required after the model boots. + * + * @return void + */ + protected static function booted(): void + { + static::creating(function () { + throw new \RuntimeException("Creating a new page is not authorized"); + }); + static::updating(function (self $model) { + $model->picture_1 = FileStorageHelper::storeFile($model, $model->picture_1, true); + $model->picture_2 = FileStorageHelper::storeFile($model, $model->picture_2, true); + $model->picture_3 = FileStorageHelper::storeFile($model, $model->picture_3, true); + }); + static::updated(function (self $model) { + FileStorageHelper::removeOldFile($model, 'picture_1'); + FileStorageHelper::removeOldFile($model, 'picture_2'); + FileStorageHelper::removeOldFile($model, 'picture_3'); + }); + static::deleting(function () { + throw new \RuntimeException('Deleting a page is not authorized'); + }); + } + + // * RELATIONS + + /** + * The commitments that belong to the page. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function commitments(): \Illuminate\Database\Eloquent\Relations\BelongsToMany + { + return $this->belongsToMany(Commitment::class); + } +} diff --git a/app/Models/Homepage.php b/app/Models/Homepage.php new file mode 100644 index 0000000..b8f8178 --- /dev/null +++ b/app/Models/Homepage.php @@ -0,0 +1,63 @@ + + */ + protected $fillable = [ + 'title_part_1', + 'title_part_2', + 'title_part_3', + 'picture', + 'picture_alt', + 'picture_title', + 'presentation_title', + 'presentation_content', + ]; + + /** + * Perform any actions required after the model boots. + * + * @return void + */ + protected static function booted(): void + { + static::creating(function () { + throw new \RuntimeException("Creating a new page is not authorized"); + }); + static::updating(function (self $model) { + $model->picture = FileStorageHelper::storeFile($model, $model->picture, true); + }); + static::updated(function (self $model) { + FileStorageHelper::removeOldFile($model, 'picture'); + }); + static::deleting(function () { + throw new \RuntimeException('Deleting a page is not authorized'); + }); + } +} diff --git a/app/Models/Joinuspage.php b/app/Models/Joinuspage.php new file mode 100644 index 0000000..81ba675 --- /dev/null +++ b/app/Models/Joinuspage.php @@ -0,0 +1,42 @@ + + */ + protected $fillable = [ + 'video_url', + ]; + + /** + * Perform any actions required after the model boots. + * + * @return void + */ + protected static function booted(): void + { + static::creating(function () { + throw new \RuntimeException("Creating a new page is not authorized"); + }); + static::deleting(function () { + throw new \RuntimeException('Deleting a page is not authorized'); + }); + } +} diff --git a/app/Models/News.php b/app/Models/News.php new file mode 100644 index 0000000..4c30334 --- /dev/null +++ b/app/Models/News.php @@ -0,0 +1,201 @@ + + */ + protected $fillable = [ + 'seo_title', + 'seo_description', + 'title', + 'slug', + 'category', + 'picture_thumbnail', + 'picture_thumbnail_alt', + 'picture_thumbnail_title', + 'picture', + 'picture_alt', + 'picture_title', + 'subtitle', + 'content', + 'published', + 'publish_at', + 'unpublish_at', + 'order', + ]; + + /** + * The attributes that should be cast. + * + * @var array + */ + protected $casts = [ + 'category' => CategoryEnum::class, + 'published' => 'bool', + 'publish_at' => 'datetime', + 'unpublish_at' => 'datetime', + ]; + + /** + * Perform any actions required after the model boots. + * + * @return void + */ + protected static function booted(): void + { + static::creating(function (self $model) { + self::assertFieldIsUnique('title', $model->title); + self::setOrder($model); + self::manageFields($model); + }); + static::updating(function (self $model) { + self::manageFields($model); + }); + static::updated(function (self $model) { + FileStorageHelper::removeOldFile($model, 'picture'); + }); + + static::deleted(function (self $model) { + FileStorageHelper::removeFile($model, 'picture'); + }); + } + + // * METHODS + + /** + * Manage model fields. + * + * @param self $model + * @return void + */ + private static function manageFields(self $model): void + { + self::setSlug($model, $model->title); + self::makeStatusSense($model); + $model->picture = FileStorageHelper::storeFile($model, $model->picture, true); + $model->picture_thumbnail = FileStorageHelper::storeFile($model, $model->picture_thumbnail, true); + } + + /** + * Set the slug. + * + * @param self $model + * @param string $original + * + * @return void + */ + private static function setSlug(self $model, string $original): void + { + $model->slug = Str::slug($original); + } + + /** + * Set order after the last element of the list. + * + * @param self $model + * @return void + */ + private static function setOrder(self $model): void + { + $model->order = \intval(self::query()->max('order')) + 1; + } + + /** + * Asserts using validation that the field is unique. + * + * @param string $nameField + * @param string $valueField + * @param integer|null $id + * @return void + */ + private static function assertFieldIsUnique(string $nameField, string $valueField, ?int $id = null): void + { + $table = (new self())->getTable(); + ToolboxHelper::assertFieldIsUnique($table, $nameField, $valueField, $id); + } + + /** + * Adjusts model status using current status and publish dates + * + * @param self $model + * @return void + */ + private static function makeStatusSense(self $model): void + { + /** @var \Carbon\Carbon|null */ + $publish_at = $model->publish_at; + /** @var \Carbon\Carbon|null */ + $unpublish_at = $model->unpublish_at; + $wantedStatus = $model->published; + if ($publish_at or $unpublish_at) { + $model->published = $model->planificated_status; + } + if ($wantedStatus !== $model->published) { + $previousMessage = session()->get('bo.info', ''); + session()->flash('bo.info', \trans( + 'La publication est modifiée en concordance avec les dates enregistrées. + Pour modifier l\'état de publication, veuillez modifier ou enlever les dates correspondantes.' + ) . " \n{$previousMessage}"); + } + } + + /** + * Getter the current status following planification dates planificated_status + * + * @return boolean + */ + public function getPlanificatedStatusAttribute(): bool + { + /** @var \Carbon\Carbon|null */ + $publish_at = $this->publish_at; + /** @var \Carbon\Carbon|null */ + $unpublish_at = $this->unpublish_at; + if ($publish_at and $unpublish_at) { + return $unpublish_at->greaterThanOrEqualTo(now()) and $publish_at->lessThan(now()); + } + if ($publish_at) { + return $publish_at->lessThan(now()); + } + if ($unpublish_at) { + return $unpublish_at->greaterThanOrEqualTo(now()); + } + return false; + } +} diff --git a/app/Models/Product.php b/app/Models/Product.php new file mode 100644 index 0000000..18dc339 --- /dev/null +++ b/app/Models/Product.php @@ -0,0 +1,192 @@ + + */ + protected $fillable = [ + 'seo_title', + 'seo_description', + 'title', + 'slug', + 'subtitle', + 'picture_thumbnail', + 'picture_thumbnail_alt', + 'picture_thumbnail_title', + 'picture_ambiance', + 'picture_ambiance_alt', + 'picture_ambiance_title', + 'picture_packshot', + 'picture_packshot_alt', + 'picture_packshot_title', + 'description', + 'cooking_mode', + 'cooking_advice', + 'ingredients', + 'nutritionnal_values', + 'published', + 'order', + 'range_id' + ]; + + /** + * The attributes that should be cast. + * + * @var array + */ + protected $casts = [ + 'cooking_mode' => CookingModeEnum::class, + 'published' => 'bool', + ]; + + /** + * Perform any actions required after the model boots. + * + * @return void + */ + protected static function booted(): void + { + static::creating(function (self $model) { + self::assertFieldIsUnique('title', $model->title); + self::setOrder($model); + self::manageFields($model); + }); + static::updating(function (self $model) { + self::manageFields($model); + }); + static::updated(function (self $model) { + FileStorageHelper::removeOldFile($model, 'picture_thumbnail'); + FileStorageHelper::removeOldFile($model, 'picture_ambiance'); + FileStorageHelper::removeOldFile($model, 'picture_packshot'); + }); + + static::deleted(function (self $model) { + FileStorageHelper::removeFile($model, 'picture_thumbnail'); + FileStorageHelper::removeFile($model, 'picture_ambiance'); + FileStorageHelper::removeFile($model, 'picture_packshot'); + }); + } + + // * METHODS + + /** + * Manage model fields. + * + * @param self $model + * @return void + */ + private static function manageFields(self $model): void + { + self::setSlug($model, $model->title); + $model->picture_thumbnail = FileStorageHelper::storeFile($model, $model->picture_thumbnail, true); + $model->picture_ambiance = FileStorageHelper::storeFile($model, $model->picture_ambiance, true); + $model->picture_packshot = FileStorageHelper::storeFile($model, $model->picture_packshot, true); + } + + /** + * Set the slug. + * + * @param self $model + * @param string $original + * + * @return void + */ + private static function setSlug(self $model, string $original): void + { + $model->slug = Str::slug($original); + } + + /** + * Set order after the last element of the list. + * + * @param self $model + * @return void + */ + private static function setOrder(self $model): void + { + $model->order = \intval(self::query()->max('order')) + 1; + } + + /** + * Asserts using validation that the field is unique. + * + * @param string $nameField + * @param string $valueField + * @param integer|null $id + * @return void + */ + private static function assertFieldIsUnique(string $nameField, string $valueField, ?int $id = null): void + { + $table = (new self())->getTable(); + ToolboxHelper::assertFieldIsUnique($table, $nameField, $valueField, $id); + } + + // * RELATIONS + + /** + * Get the range that owns the product. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function range(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(Range::class); + } + + /** + * The commitments that belong to the product. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function commitments(): \Illuminate\Database\Eloquent\Relations\BelongsToMany + { + return $this->belongsToMany(Commitment::class); + } +} diff --git a/app/Models/Range.php b/app/Models/Range.php new file mode 100644 index 0000000..724f112 --- /dev/null +++ b/app/Models/Range.php @@ -0,0 +1,173 @@ + + */ + protected $fillable = [ + 'seo_title', + 'seo_description', + 'title', + 'slug', + 'subtitle', + 'tagline', + 'picture', + 'picture_alt', + 'picture_title', + 'picture_productsheet', + 'picture_productsheet_alt', + 'picture_productsheet_title', + 'picture_thumbnail', + 'picture_thumbnail_alt', + 'picture_thumbnail_title', + 'published', + 'order', + ]; + + /** + * The attributes that should be cast. + * + * @var array + */ + protected $casts = [ + 'cooking_mode' => CookingModeEnum::class, + 'published' => 'bool', + ]; + + /** + * Perform any actions required after the model boots. + * + * @return void + */ + protected static function booted(): void + { + static::creating(function (self $model) { + self::assertFieldIsUnique('title', $model->title); + self::setOrder($model); + self::manageFields($model); + }); + static::updating(function (self $model) { + self::manageFields($model); + }); + static::updated(function (self $model) { + FileStorageHelper::removeOldFile($model, 'picture'); + FileStorageHelper::removeOldFile($model, 'picture_productsheet'); + FileStorageHelper::removeOldFile($model, 'picture_thumbnail'); + }); + + static::deleted(function (self $model) { + FileStorageHelper::removeFile($model, 'picture'); + FileStorageHelper::removeFile($model, 'picture_productsheet'); + FileStorageHelper::removeFile($model, 'picture_thumbnail'); + }); + } + + // * METHODS + + /** + * Manage model fields. + * + * @param self $model + * @return void + */ + private static function manageFields(self $model): void + { + self::setSlug($model, $model->title); + $model->picture = FileStorageHelper::storeFile($model, $model->picture, true); + $model->picture_productsheet = FileStorageHelper::storeFile($model, $model->picture_productsheet, true); + $model->picture_thumbnail = FileStorageHelper::storeFile($model, $model->picture_thumbnail, true); + } + + /** + * Set the slug. + * + * @param self $model + * @param string $original + * + * @return void + */ + private static function setSlug(self $model, string $original): void + { + $model->slug = Str::slug($original); + } + + /** + * Set order after the last element of the list. + * + * @param self $model + * @return void + */ + private static function setOrder(self $model): void + { + $model->order = \intval(self::query()->max('order')) + 1; + } + + /** + * Asserts using validation that the field is unique. + * + * @param string $nameField + * @param string $valueField + * @param integer|null $id + * @return void + */ + private static function assertFieldIsUnique(string $nameField, string $valueField, ?int $id = null): void + { + $table = (new self())->getTable(); + ToolboxHelper::assertFieldIsUnique($table, $nameField, $valueField, $id); + } + + // * RELATIONS + + /** + * Get the products in the range. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function products(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(Product::class); + } +} diff --git a/app/Models/SeasonalSection.php b/app/Models/SeasonalSection.php new file mode 100644 index 0000000..0fb7f6b --- /dev/null +++ b/app/Models/SeasonalSection.php @@ -0,0 +1,146 @@ + + */ + protected $fillable = [ + 'title', + 'text', + 'picture', + 'picture_alt', + 'picture_title', + 'background', + 'published', + 'publish_at', + 'unpublish_at', + 'order', + ]; + + /** + * The attributes that should be cast. + * + * @var array + */ + protected $casts = [ + 'background' => BackgroundEnum::class, + 'published' => 'bool', + 'publish_at' => 'datetime', + 'unpublish_at' => 'datetime', + ]; + + /** + * Perform any actions required after the model boots. + * + * @return void + */ + protected static function booted(): void + { + static::creating(function (self $model) { + self::manageFields($model); + }); + static::updating(function (self $model) { + self::manageFields($model); + }); + static::updated(function (self $model) { + FileStorageHelper::removeOldFile($model, 'picture'); + }); + + static::deleted(function (self $model) { + FileStorageHelper::removeFile($model, 'picture'); + }); + } + + // * METHODS + + /** + * Manage model fields. + * + * @param self $model + * @return void + */ + private static function manageFields(self $model): void + { + self::makeStatusSense($model); + $model->picture = FileStorageHelper::storeFile($model, $model->picture, true); + } + + + /** + * Adjusts model status using current status and publish dates + * + * @param self $model + * @return void + */ + private static function makeStatusSense(self $model): void + { + /** @var \Carbon\Carbon|null */ + $publish_at = $model->publish_at; + /** @var \Carbon\Carbon|null */ + $unpublish_at = $model->unpublish_at; + $wantedStatus = $model->published; + if ($publish_at or $unpublish_at) { + $model->published = $model->planificated_status; + } + if ($wantedStatus !== $model->published) { + $previousMessage = session()->get('bo.info', ''); + session()->flash('bo.info', \trans( + 'La publication est modifiée en concordance avec les dates enregistrées. + Pour modifier l\'état de publication, veuillez modifier ou enlever les dates correspondantes.' + ) . " \n{$previousMessage}"); + } + } + + /** + * Getter the current status following planification dates planificated_status + * + * @return boolean + */ + public function getPlanificatedStatusAttribute(): bool + { + /** @var \Carbon\Carbon|null */ + $publish_at = $this->publish_at; + /** @var \Carbon\Carbon|null */ + $unpublish_at = $this->unpublish_at; + if ($publish_at and $unpublish_at) { + return $unpublish_at->greaterThanOrEqualTo(now()) and $publish_at->lessThan(now()); + } + if ($publish_at) { + return $publish_at->lessThan(now()); + } + if ($unpublish_at) { + return $unpublish_at->greaterThanOrEqualTo(now()); + } + return false; + } +} diff --git a/app/Models/Stamp.php b/app/Models/Stamp.php new file mode 100644 index 0000000..407e414 --- /dev/null +++ b/app/Models/Stamp.php @@ -0,0 +1,62 @@ + + */ + protected $fillable = [ + 'picture', + 'picture_alt', + 'picture_title', + 'published', + ]; + + /** + * The attributes that should be cast. + * + * @var array + */ + protected $casts = [ + 'published' => 'bool', + ]; + + /** + * Perform any actions required after the model boots. + * + * @return void + */ + protected static function booted(): void + { + static::creating(function (self $model) { + $model->picture = FileStorageHelper::storeFile($model, $model->picture, true); + }); + static::updating(function (self $model) { + $model->picture = FileStorageHelper::storeFile($model, $model->picture, true); + }); + static::updated(function (self $model) { + FileStorageHelper::removeOldFile($model, 'picture'); + }); + static::deleted(function (self $model) { + FileStorageHelper::removeFile($model, 'picture'); + }); + } +} diff --git a/app/Models/StaticPage.php b/app/Models/StaticPage.php new file mode 100644 index 0000000..4751c94 --- /dev/null +++ b/app/Models/StaticPage.php @@ -0,0 +1,86 @@ + + */ + protected $fillable = [ + 'seo_title', + 'seo_description', + 'title', + 'content', + ]; + + /** + * The attributes that should be cast. + * + * @var array + */ + protected $casts = [ + 'type' => StaticPageType::class, + ]; + + /** + * Perform any actions required after the model boots. + * + * @return void + */ + protected static function booted(): void + { + static::creating(function () { + throw new \RuntimeException("Creating a new page is not authorized"); + }); + static::updating(function (self $model) { + // * ASSERTIONS + static::assertTitleIsUnique($model->title, $model->id); + + // * CHANGES + $model->slug = Str::slug($model->title); + }); + static::deleting(function () { + throw new \RuntimeException('Deleting a page is not authorized'); + }); + } + + // * METHODS + + /** + * Asserts using validation that the title is unique + * + * @param string|null $title + * @param integer|null $id + * @return void + * @throws \Illuminate\Validation\ValidationException If an actu title already exists. + */ + private static function assertTitleIsUnique(string|null $title, ?int $id = null) + { + $table = (new self())->getTable(); + ToolboxHelper::assertFieldIsUnique($table, 'title', $title, $id); + ToolboxHelper::assertFieldIsUnique($table, 'slug', Str::slug($title), $id); + } +} diff --git a/app/Models/Testimonial.php b/app/Models/Testimonial.php new file mode 100644 index 0000000..a2bd756 --- /dev/null +++ b/app/Models/Testimonial.php @@ -0,0 +1,76 @@ + + */ + protected $fillable = [ + 'picture', + 'picture_alt', + 'picture_title', + 'description', + 'job', + 'statut', + 'order', + ]; + + /** + * Perform any actions required after the model boots. + * + * @return void + */ + protected static function booted(): void + { + static::creating(function (self $model) { + self::setOrder($model); + $model->picture = FileStorageHelper::storeFile($model, $model->picture, true); + }); + static::updating(function (self $model) { + $model->picture = FileStorageHelper::storeFile($model, $model->picture, true); + }); + static::updated(function (self $model) { + FileStorageHelper::removeOldFile($model, 'picture'); + }); + + static::deleted(function (self $model) { + FileStorageHelper::removeFile($model, 'picture'); + }); + } + + // * METHODS + + /** + * Set order after the last element of the list. + * + * @param self $model + * @return void + */ + private static function setOrder(self $model): void + { + $model->order = \intval(self::query()->max('order')) + 1; + } +} diff --git a/database/factories/CommitmentFactory.php b/database/factories/CommitmentFactory.php new file mode 100644 index 0000000..d9cdfc7 --- /dev/null +++ b/database/factories/CommitmentFactory.php @@ -0,0 +1,23 @@ + + */ + public function definition() + { + return [ + 'title' => fake()->sentence(), + 'picture_alt' => fake()->sentence(), + 'picture_title' => fake()->sentence(), + 'published' => fake()->boolean(75), + ]; + } +} diff --git a/database/factories/ConvictionpageFactory.php b/database/factories/ConvictionpageFactory.php new file mode 100644 index 0000000..b4a2ae7 --- /dev/null +++ b/database/factories/ConvictionpageFactory.php @@ -0,0 +1,27 @@ + + */ + public function definition() + { + return [ + 'key_feed' => fake()->randomFloat(2, 0, 999999), + 'key_earth_1' => fake()->randomFloat(2, 0, 999999), + 'key_earth_2' => fake()->randomFloat(2, 0, 999999), + 'key_together_1' => fake()->randomFloat(2, 0, 999999), + 'key_together_2' => fake()->randomFloat(2, 0, 999999), + 'key_together_3' => fake()->randomFloat(2, 0, 999999), + 'key_together_4' => fake()->randomFloat(2, 0, 999999), + 'key_territory' => fake()->randomFloat(2, 0, 999999), + ]; + } +} diff --git a/database/factories/ExplorerpageFactory.php b/database/factories/ExplorerpageFactory.php new file mode 100644 index 0000000..09ba213 --- /dev/null +++ b/database/factories/ExplorerpageFactory.php @@ -0,0 +1,25 @@ + + */ + public function definition() + { + return [ + 'picture_1_alt' => fake()->sentence(), + 'picture_1_title' => fake()->sentence(), + 'picture_2_alt' => fake()->sentence(), + 'picture_2_title' => fake()->sentence(), + 'picture_3_alt' => fake()->sentence(), + 'picture_3_title' => fake()->sentence(), + ]; + } +} diff --git a/database/factories/HomepageFactory.php b/database/factories/HomepageFactory.php new file mode 100644 index 0000000..e5fea30 --- /dev/null +++ b/database/factories/HomepageFactory.php @@ -0,0 +1,26 @@ + + */ + public function definition() + { + return [ + 'title_part1' => fake()->sentence(), + 'title_part2' => fake()->sentence(), + 'title_part3' => fake()->sentence(), + 'picture_alt' => fake()->sentence(), + 'picture_title' => fake()->sentence(), + 'presentation_title' => fake()->sentence(), + 'presentation_content' => \clean(\fake()->randomHtml(6, 7)), + ]; + } +} diff --git a/database/factories/JoinuspageFactory.php b/database/factories/JoinuspageFactory.php new file mode 100644 index 0000000..d0abb0d --- /dev/null +++ b/database/factories/JoinuspageFactory.php @@ -0,0 +1,20 @@ + + */ + public function definition() + { + return [ + 'video_url' => 'https://www.youtube.com/watch?v=6B4O-_1CQoI', + ]; + } +} diff --git a/database/factories/NewsFactory.php b/database/factories/NewsFactory.php new file mode 100644 index 0000000..90d14e1 --- /dev/null +++ b/database/factories/NewsFactory.php @@ -0,0 +1,40 @@ + + */ + public function definition() + { + $title = fake()->sentence(); + $publish_at = now()->subDays(rand(1, 30)); + $unpublish_at = $publish_at->copy()->addDays(rand(1, 30)); + $published = now() > $publish_at && now() < $unpublish_at ? true : false; + + return [ + 'seo_title' => fake()->word(), + 'seo_description' => fake()->text(160), + 'title' => $title, + 'slug' => Str::slug($title), + 'category' => \collect(CategoryEnum::cases())->random(), + 'picture_thumbnail_alt' => fake()->sentence(), + 'picture_thumbnail_title' => fake()->sentence(), + 'picture_alt' => fake()->sentence(), + 'picture_title' => fake()->sentence(), + 'subtitle' => fake()->sentence(), + 'content' => \clean(\fake()->randomHtml(6, 7)), + 'published' => $published, + 'publish_at' => $publish_at, + 'unpublish_at' => $unpublish_at, + ]; + } +} diff --git a/database/factories/ProductFactory.php b/database/factories/ProductFactory.php new file mode 100644 index 0000000..bdc1154 --- /dev/null +++ b/database/factories/ProductFactory.php @@ -0,0 +1,50 @@ + + */ + public function definition() + { + $title = fake()->sentence(); + + return [ + 'seo_title' => fake()->word(), + 'seo_description' => fake()->text(160), + 'title' => $title, + 'slug' => Str::slug($title), + 'subtitle' => fake()->sentence(), + 'picture_thumbnail_alt' => fake()->sentence(), + 'picture_thumbnail_title' => fake()->sentence(), + 'picture_ambiance_alt' => fake()->sentence(), + 'picture_ambiance_title' => fake()->sentence(), + 'picture_packshot_alt' => fake()->sentence(), + 'picture_packshot_title' => fake()->sentence(), + 'description' => \clean(\fake()->randomHtml(6, 7)), + 'cooking_mode' => \collect(CookingModeEnum::cases())->random(), + 'cooking_advice' => \clean(\fake()->randomHtml(6, 7)), + 'ingredients' => \clean(\fake()->randomHtml(6, 7)), + 'nutritionnal_values' => json_encode([ + 'Energie en Kj' => fake()->randomFloat(2), + 'Energie en kcal' => fake()->randomFloat(2), + 'Matières grasses' => fake()->randomFloat(2), + 'dont acides gras saturés' => fake()->randomFloat(2), + 'Glucides' => fake()->randomFloat(2), + 'Protéines' => fake()->randomFloat(2), + 'Sel' => fake()->randomFloat(2), + ]), + 'published' => fake()->boolean(75), + 'range_id' => Range::all()->random()->id, + ]; + } +} diff --git a/database/factories/RangeFactory.php b/database/factories/RangeFactory.php new file mode 100644 index 0000000..e5e4af8 --- /dev/null +++ b/database/factories/RangeFactory.php @@ -0,0 +1,36 @@ + + */ + public function definition() + { + $title = fake()->sentence(); + + return [ + 'seo_title' => fake()->word(), + 'seo_description' => fake()->text(160), + 'title' => $title, + 'slug' => Str::slug($title), + 'subtitle' => fake()->sentence(), + 'tagline' => fake()->sentence(), + 'description' => \clean(\fake()->randomHtml(6, 7)), + 'picture_alt' => fake()->sentence(), + 'picture_title' => fake()->sentence(), + 'picture_productsheet_alt' => fake()->sentence(), + 'picture_productsheet_title' => fake()->sentence(), + 'picture_thumbnail_alt' => fake()->sentence(), + 'picture_thumbnail_title' => fake()->sentence(), + 'published' => fake()->boolean(75), + ]; + } +} diff --git a/database/factories/SeasonalSectionFactory.php b/database/factories/SeasonalSectionFactory.php new file mode 100644 index 0000000..d41df9a --- /dev/null +++ b/database/factories/SeasonalSectionFactory.php @@ -0,0 +1,24 @@ + + */ + public function definition() + { + return [ + 'title' => fake()->sentence(), + 'text' => fake()->text(), + 'picture_alt' => fake()->sentence(), + 'picture_title' => fake()->sentence(), + 'published' => false, + ]; + } +} diff --git a/database/factories/StampFactory.php b/database/factories/StampFactory.php new file mode 100644 index 0000000..c8f1f54 --- /dev/null +++ b/database/factories/StampFactory.php @@ -0,0 +1,22 @@ + + */ + public function definition() + { + return [ + 'picture_alt' => fake()->sentence(), + 'picture_title' => fake()->sentence(), + 'published' => fake()->boolean(75), + ]; + } +} diff --git a/database/factories/TestimonialFactory.php b/database/factories/TestimonialFactory.php new file mode 100644 index 0000000..65eaac9 --- /dev/null +++ b/database/factories/TestimonialFactory.php @@ -0,0 +1,24 @@ + + */ + public function definition() + { + return [ + 'picture_alt' => fake()->sentence(), + 'picture_title' => fake()->sentence(), + 'description' => fake()->sentence(), + 'job' => fake()->jobTitle(), + 'statut' => fake()->word(), + ]; + } +} diff --git a/database/factories/assets/commitments/default-picture-185x185.png b/database/factories/assets/commitments/default-picture-185x185.png new file mode 100644 index 0000000..2a271fe Binary files /dev/null and b/database/factories/assets/commitments/default-picture-185x185.png differ diff --git a/database/factories/assets/explorerpages/default-picture-265x364.png b/database/factories/assets/explorerpages/default-picture-265x364.png new file mode 100644 index 0000000..c4ec675 Binary files /dev/null and b/database/factories/assets/explorerpages/default-picture-265x364.png differ diff --git a/database/factories/assets/homepages/default-picture-640x390.png b/database/factories/assets/homepages/default-picture-640x390.png new file mode 100644 index 0000000..020a5e3 Binary files /dev/null and b/database/factories/assets/homepages/default-picture-640x390.png differ diff --git a/database/factories/assets/news/default-picture-1002x565.png b/database/factories/assets/news/default-picture-1002x565.png new file mode 100644 index 0000000..f544424 Binary files /dev/null and b/database/factories/assets/news/default-picture-1002x565.png differ diff --git a/database/factories/assets/news/default-picture-265x354.png b/database/factories/assets/news/default-picture-265x354.png new file mode 100644 index 0000000..8b5a92b Binary files /dev/null and b/database/factories/assets/news/default-picture-265x354.png differ diff --git a/database/factories/assets/products/default-picture-327x252.png b/database/factories/assets/products/default-picture-327x252.png new file mode 100644 index 0000000..8665558 Binary files /dev/null and b/database/factories/assets/products/default-picture-327x252.png differ diff --git a/database/factories/assets/products/default-picture-332x252.png b/database/factories/assets/products/default-picture-332x252.png new file mode 100644 index 0000000..4c9bbcc Binary files /dev/null and b/database/factories/assets/products/default-picture-332x252.png differ diff --git a/database/factories/assets/products/default-picture-774x515.png b/database/factories/assets/products/default-picture-774x515.png new file mode 100644 index 0000000..e8ea997 Binary files /dev/null and b/database/factories/assets/products/default-picture-774x515.png differ diff --git a/database/factories/assets/ranges/default-picture-246x337.png b/database/factories/assets/ranges/default-picture-246x337.png new file mode 100644 index 0000000..f911fbc Binary files /dev/null and b/database/factories/assets/ranges/default-picture-246x337.png differ diff --git a/database/factories/assets/ranges/default-picture-332x442.png b/database/factories/assets/ranges/default-picture-332x442.png new file mode 100644 index 0000000..f5936c1 Binary files /dev/null and b/database/factories/assets/ranges/default-picture-332x442.png differ diff --git a/database/factories/assets/ranges/default-picture-466x440.png b/database/factories/assets/ranges/default-picture-466x440.png new file mode 100644 index 0000000..49826f5 Binary files /dev/null and b/database/factories/assets/ranges/default-picture-466x440.png differ diff --git a/database/factories/assets/seasonalsections/default-picture-362x542.png b/database/factories/assets/seasonalsections/default-picture-362x542.png new file mode 100644 index 0000000..fc669bc Binary files /dev/null and b/database/factories/assets/seasonalsections/default-picture-362x542.png differ diff --git a/database/factories/assets/stamps/default-picture-120x120.png b/database/factories/assets/stamps/default-picture-120x120.png new file mode 100644 index 0000000..b6334aa Binary files /dev/null and b/database/factories/assets/stamps/default-picture-120x120.png differ diff --git a/database/factories/assets/testimonials/default-picture-292x417.png b/database/factories/assets/testimonials/default-picture-292x417.png new file mode 100644 index 0000000..15769fe Binary files /dev/null and b/database/factories/assets/testimonials/default-picture-292x417.png differ diff --git a/database/migrations/2023_10_18_180112_create_explorerpage_commitment_table.php b/database/migrations/2023_10_18_180112_create_commitment_explorerpage_table.php similarity index 81% rename from database/migrations/2023_10_18_180112_create_explorerpage_commitment_table.php rename to database/migrations/2023_10_18_180112_create_commitment_explorerpage_table.php index cf7aa6f..28a5b79 100644 --- a/database/migrations/2023_10_18_180112_create_explorerpage_commitment_table.php +++ b/database/migrations/2023_10_18_180112_create_commitment_explorerpage_table.php @@ -13,7 +13,7 @@ return new class extends Migration */ public function up() { - Schema::create('explorerpage_commitment', function (Blueprint $table) { + Schema::create('commitment_explorerpage', function (Blueprint $table) { $table->unsignedBigInteger('explorerpage_id'); $table->unsignedBigInteger('commitment_id'); }); @@ -26,6 +26,6 @@ return new class extends Migration */ public function down() { - Schema::dropIfExists('explorerpage_commitment'); + Schema::dropIfExists('commitment_explorerpage'); } }; diff --git a/database/migrations/2023_10_18_180112_create_product_commitment_table.php b/database/migrations/2023_10_18_180112_create_commitment_product_table.php similarity index 82% rename from database/migrations/2023_10_18_180112_create_product_commitment_table.php rename to database/migrations/2023_10_18_180112_create_commitment_product_table.php index 34a649d..570fa85 100644 --- a/database/migrations/2023_10_18_180112_create_product_commitment_table.php +++ b/database/migrations/2023_10_18_180112_create_commitment_product_table.php @@ -13,7 +13,7 @@ return new class extends Migration */ public function up() { - Schema::create('product_commitment', function (Blueprint $table) { + Schema::create('commitment_product', function (Blueprint $table) { $table->unsignedBigInteger('product_id'); $table->unsignedBigInteger('commitment_id'); }); @@ -26,6 +26,6 @@ return new class extends Migration */ public function down() { - Schema::dropIfExists('product_commitment'); + Schema::dropIfExists('commitment_product'); } }; diff --git a/database/migrations/2023_10_18_180112_create_explorerpages_table.php b/database/migrations/2023_10_18_180112_create_explorerpages_table.php index 485407e..b6de403 100644 --- a/database/migrations/2023_10_18_180112_create_explorerpages_table.php +++ b/database/migrations/2023_10_18_180112_create_explorerpages_table.php @@ -15,13 +15,13 @@ return new class extends Migration { Schema::create('explorerpages', function (Blueprint $table) { $table->id(); - $table->string('picture_1')->comment('Path de la première illustration'); + $table->string('picture_1')->comment('Path de la première illustration (265px * 364px'); $table->string('picture_1_alt')->comment('Attribut alt de l\'image 1'); $table->string('picture_1_title')->comment('Attribut title de l\'image 1'); - $table->string('picture_2')->comment('Path de la deuxième illustration'); + $table->string('picture_2')->comment('Path de la deuxième illustration (265px * 364px'); $table->string('picture_2_alt')->comment('Attribut alt de l\'image 2'); $table->string('picture_2_title')->comment('Attribut title de l\'image 2'); - $table->string('picture_3')->comment('Path de la troisième illustration'); + $table->string('picture_3')->comment('Path de la troisième illustration (265px * 364px'); $table->string('picture_3_alt')->comment('Attribut alt de l\'image 3'); $table->string('picture_3_title')->comment('Attribut title de l\'image 3'); $table->timestamps(); diff --git a/database/migrations/2023_10_18_180112_create_products_table.php b/database/migrations/2023_10_18_180112_create_products_table.php index 7619f2c..36c674a 100644 --- a/database/migrations/2023_10_18_180112_create_products_table.php +++ b/database/migrations/2023_10_18_180112_create_products_table.php @@ -34,7 +34,7 @@ return new class extends Migration ->comment('Mode de cuisson (enum \\App\\Enums\\Products\\CookingModeEnum)'); $table->text('cooking_advice')->comment('WYSIWYG - Conseil de réchauffage'); $table->text('ingredients')->comment('WYSIWYG - Ingrédients qui composent le produit'); - $table->json('nutrionnal_values')->comment('JSON des valeurs nutritionnelles pour 100g'); + $table->json('nutritionnal_values')->comment('JSON des valeurs nutritionnelles pour 100g'); $table->boolean('published')->comment('Le produit est-il visible ?'); $table->unsignedInteger('order')->comment('Numéro permettant d\'ordonner les produits'); $table->unsignedBigInteger('range_id'); diff --git a/database/migrations/2023_10_18_180112_create_seasonal_section_table.php b/database/migrations/2023_10_18_180112_create_seasonal_sections_table.php similarity index 95% rename from database/migrations/2023_10_18_180112_create_seasonal_section_table.php rename to database/migrations/2023_10_18_180112_create_seasonal_sections_table.php index d19954b..d3cf606 100644 --- a/database/migrations/2023_10_18_180112_create_seasonal_section_table.php +++ b/database/migrations/2023_10_18_180112_create_seasonal_sections_table.php @@ -13,7 +13,7 @@ return new class extends Migration */ public function up() { - Schema::create('seasonal_section', function (Blueprint $table) { + Schema::create('seasonal_sections', function (Blueprint $table) { $table->id(); $table->string('title')->comment('Titre de la section saisonnière'); $table->text('text')->comment('WYSIWYG - Texte de la section saisonnière'); diff --git a/database/migrations/2023_10_18_180112_create_static_pages_table.php b/database/migrations/2023_10_18_180112_create_static_pages_table.php index 5683ab4..a28d0c0 100644 --- a/database/migrations/2023_10_18_180112_create_static_pages_table.php +++ b/database/migrations/2023_10_18_180112_create_static_pages_table.php @@ -2,6 +2,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Schema; return new class extends Migration @@ -11,18 +12,26 @@ return new class extends Migration * * @return void */ - public function up() + public function up(): void { Schema::create('static_pages', function (Blueprint $table) { $table->id(); - $table->unsignedTinyInteger('type')->unique() - ->comment('Type de la page (enum \\App\\Enums\\StaticPage\\PageTypeEnum)'); - $table->string('seo_title')->comment('Utilisé pour la balise title de la page'); - $table->string('seo_description')->comment('Utilisé pour la balise meta description de la page'); - $table->string('title')->comment('Utilisé pour la balise h1 de la page'); - $table->text('content')->comment('WYSIWYG - Contenu de la page. Peut être une chaîne vide selon le type'); + + $table->unsignedTinyInteger('type')->unique()->comment('Page type (StaticPageEnum)'); + + $table->string('seo_title')->comment('Seo title about 70 chars as recommended'); + $table->string('seo_description')->comment('Seo description about 160 chars as recommended'); + + $table->string('title')->comment('Title for the page'); + $table->string('slug')->unique()->comment('Unique title slug'); + + $table->text('content')->comment('WYSIWYG text content using ckeditor'); + $table->timestamps(); }); + Artisan::call('db:seed', [ + 'class' => 'StaticPageSeeder' + ]); } /** @@ -30,7 +39,7 @@ return new class extends Migration * * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('static_pages'); } diff --git a/database/migrations/2023_10_18_180115_add_foreign_keys_to_explorerpage_commitment_table.php b/database/migrations/2023_10_18_180115_add_foreign_keys_to_commitment_explorerpage_table.php similarity index 72% rename from database/migrations/2023_10_18_180115_add_foreign_keys_to_explorerpage_commitment_table.php rename to database/migrations/2023_10_18_180115_add_foreign_keys_to_commitment_explorerpage_table.php index 04ab240..6a974c9 100644 --- a/database/migrations/2023_10_18_180115_add_foreign_keys_to_explorerpage_commitment_table.php +++ b/database/migrations/2023_10_18_180115_add_foreign_keys_to_commitment_explorerpage_table.php @@ -13,7 +13,7 @@ return new class extends Migration */ public function up() { - Schema::table('explorerpage_commitment', function (Blueprint $table) { + Schema::table('commitment_explorerpage', function (Blueprint $table) { $table->foreign(['explorerpage_id'])->references(['id'])->on('explorerpages'); $table->foreign(['commitment_id'])->references(['id'])->on('commitments'); }); @@ -26,9 +26,9 @@ return new class extends Migration */ public function down() { - Schema::table('explorerpage_commitment', function (Blueprint $table) { - $table->dropForeign('explorerpage_commitment_explorerpage_id_foreign'); - $table->dropForeign('explorerpage_commitment_commitment_id_foreign'); + Schema::table('commitment_explorerpage', function (Blueprint $table) { + $table->dropForeign('commitment_explorerpage_explorerpage_id_foreign'); + $table->dropForeign('commitment_explorerpage_commitment_id_foreign'); }); } }; diff --git a/database/migrations/2023_10_18_180115_add_foreign_keys_to_product_commitment_table.php b/database/migrations/2023_10_18_180115_add_foreign_keys_to_commitment_product_table.php similarity index 71% rename from database/migrations/2023_10_18_180115_add_foreign_keys_to_product_commitment_table.php rename to database/migrations/2023_10_18_180115_add_foreign_keys_to_commitment_product_table.php index 0295c21..f7c3033 100644 --- a/database/migrations/2023_10_18_180115_add_foreign_keys_to_product_commitment_table.php +++ b/database/migrations/2023_10_18_180115_add_foreign_keys_to_commitment_product_table.php @@ -13,7 +13,7 @@ return new class extends Migration */ public function up() { - Schema::table('product_commitment', function (Blueprint $table) { + Schema::table('commitment_product', function (Blueprint $table) { $table->foreign(['product_id'])->references(['id'])->on('products'); $table->foreign(['commitment_id'])->references(['id'])->on('commitments'); }); @@ -26,9 +26,9 @@ return new class extends Migration */ public function down() { - Schema::table('product_commitment', function (Blueprint $table) { - $table->dropForeign('product_commitment_product_id_foreign'); - $table->dropForeign('product_commitment_commitment_id_foreign'); + Schema::table('commitment_product', function (Blueprint $table) { + $table->dropForeign('commitment_product_product_id_foreign'); + $table->dropForeign('commitment_product_commitment_id_foreign'); }); } }; diff --git a/database/seeders/CommitmentSeeder.php b/database/seeders/CommitmentSeeder.php new file mode 100644 index 0000000..5bff0e7 --- /dev/null +++ b/database/seeders/CommitmentSeeder.php @@ -0,0 +1,25 @@ +create([ + 'picture' => FileStorageHelper::storeFile(new Commitment(), new \SplFileInfo(\resource_path( + '../database/factories/assets/commitments/default-picture-185x185.png' + ))) + ]); + } +} diff --git a/database/seeders/ConvictionpageSeeder.php b/database/seeders/ConvictionpageSeeder.php new file mode 100644 index 0000000..88c3862 --- /dev/null +++ b/database/seeders/ConvictionpageSeeder.php @@ -0,0 +1,25 @@ +create(); + } finally { + Convictionpage::setEventDispatcher(new \Illuminate\Events\Dispatcher()); + } + } +} diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index bf08078..7e25de1 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -15,6 +15,17 @@ class DatabaseSeeder extends Seeder { $this->call([ UserSeeder::class, + CommitmentSeeder::class, + RangeSeeder::class, + ProductSeeder::class, + NewsSeeder::class, + SeasonalSectionSeeder::class, + StampSeeder::class, + TestimonialSeeder::class, + ConvictionpageSeeder::class, + ExplorerpageSeeder::class, + HomepageSeeder::class, + JoinuspageSeeder::class, ]); } } diff --git a/database/seeders/ExplorerpageSeeder.php b/database/seeders/ExplorerpageSeeder.php new file mode 100644 index 0000000..9616728 --- /dev/null +++ b/database/seeders/ExplorerpageSeeder.php @@ -0,0 +1,43 @@ +create([ + 'picture_1' => FileStorageHelper::storeFile(new Explorerpage(), new \SplFileInfo( + \resource_path('../database/factories/assets/explorerpages/default-picture-265x364.png') + )), + 'picture_2' => FileStorageHelper::storeFile(new Explorerpage(), new \SplFileInfo( + \resource_path('../database/factories/assets/explorerpages/default-picture-265x364.png') + )), + 'picture_3' => FileStorageHelper::storeFile(new Explorerpage(), new \SplFileInfo( + \resource_path('../database/factories/assets/explorerpages/default-picture-265x364.png') + )), + ]); + + $commitments = Commitment::query()->get(); + Explorerpage::query()->each(function (Explorerpage $explorerpage) use ($commitments) { + $explorerpage->commitments()->saveMany($commitments->random(\rand(3, 12))); + }); + } finally { + Explorerpage::setEventDispatcher(new \Illuminate\Events\Dispatcher()); + } //end try + } +} diff --git a/database/seeders/HomepageSeeder.php b/database/seeders/HomepageSeeder.php new file mode 100644 index 0000000..e67aaa7 --- /dev/null +++ b/database/seeders/HomepageSeeder.php @@ -0,0 +1,31 @@ +create([ + 'picture' => FileStorageHelper::storeFile(new Homepage(), new \SplFileInfo(\resource_path( + '../database/factories/assets/homepages/default-picture-640x390.png' + ))), + ]); + } finally { + Homepage::setEventDispatcher(new \Illuminate\Events\Dispatcher()); + } + } +} diff --git a/database/seeders/JoinuspageSeeder.php b/database/seeders/JoinuspageSeeder.php new file mode 100644 index 0000000..d9f0640 --- /dev/null +++ b/database/seeders/JoinuspageSeeder.php @@ -0,0 +1,25 @@ +create(); + } finally { + Joinuspage::setEventDispatcher(new \Illuminate\Events\Dispatcher()); + } + } +} diff --git a/database/seeders/NewsSeeder.php b/database/seeders/NewsSeeder.php new file mode 100644 index 0000000..45f9239 --- /dev/null +++ b/database/seeders/NewsSeeder.php @@ -0,0 +1,28 @@ +create([ + 'picture_thumbnail' => FileStorageHelper::storeFile(new News(), new \SplFileInfo(\resource_path( + '../database/factories/assets/news/default-picture-265x354.png' + ))), + 'picture' => FileStorageHelper::storeFile(new News(), new \SplFileInfo(\resource_path( + '../database/factories/assets/news/default-picture-1002x565.png' + ))), + ]); + } +} diff --git a/database/seeders/ProductSeeder.php b/database/seeders/ProductSeeder.php new file mode 100644 index 0000000..0ee156b --- /dev/null +++ b/database/seeders/ProductSeeder.php @@ -0,0 +1,37 @@ +create([ + 'picture_thumbnail' => FileStorageHelper::storeFile(new Product(), new \SplFileInfo(\resource_path( + '../database/factories/assets/products/default-picture-332x252.png' + ))), + 'picture_ambiance' => FileStorageHelper::storeFile(new Product(), new \SplFileInfo(\resource_path( + '../database/factories/assets/products/default-picture-774x515.png' + ))), + 'picture_packshot' => FileStorageHelper::storeFile(new Product(), new \SplFileInfo(\resource_path( + '../database/factories/assets/products/default-picture-327x252.png' + ))) + ]); + + $commitments = Commitment::query()->get(); + Product::query()->each(function (Product $product) use ($commitments) { + $product->commitments()->saveMany($commitments->random(\rand(0, 4))); + }); + } +} diff --git a/database/seeders/RangeSeeder.php b/database/seeders/RangeSeeder.php new file mode 100644 index 0000000..4f94f01 --- /dev/null +++ b/database/seeders/RangeSeeder.php @@ -0,0 +1,31 @@ +create([ + 'picture' => FileStorageHelper::storeFile(new Range(), new \SplFileInfo(\resource_path( + '../database/factories/assets/ranges/default-picture-466x440.png' + ))), + 'picture_productsheet' => FileStorageHelper::storeFile(new Range(), new \SplFileInfo(\resource_path( + '../database/factories/assets/ranges/default-picture-332x442.png' + ))), + 'picture_thumbnail' => FileStorageHelper::storeFile(new Range(), new \SplFileInfo(\resource_path( + '../database/factories/assets/ranges/default-picture-246x337.png' + ))), + ]); + } +} diff --git a/database/seeders/SeasonalSectionSeeder.php b/database/seeders/SeasonalSectionSeeder.php new file mode 100644 index 0000000..09f0f73 --- /dev/null +++ b/database/seeders/SeasonalSectionSeeder.php @@ -0,0 +1,34 @@ +subDays(rand(1, 10)); + $unpublish_at = $publish_at->copy()->addDays(rand(10, 20)); + foreach (BackgroundEnum::cases() as $i => $background) { + SeasonalSection::factory(1)->create([ + 'background' => $background, + 'published' => $i === array_key_first(BackgroundEnum::cases()) ? true : false, + 'publish_at' => $publish_at->subMonths(), + 'unpublish_at' => $unpublish_at->subMonths(), + 'picture' => FileStorageHelper::storeFile(new SeasonalSection(), new \SplFileInfo( + \resource_path('../database/factories/assets/seasonalsections/default-picture-362x542.png') + )), + ]); + } + } +} diff --git a/database/seeders/StampSeeder.php b/database/seeders/StampSeeder.php new file mode 100644 index 0000000..5c81e80 --- /dev/null +++ b/database/seeders/StampSeeder.php @@ -0,0 +1,25 @@ +create([ + 'picture' => FileStorageHelper::storeFile(new Stamp(), new \SplFileInfo( + \resource_path('../database/factories/assets/stamps/default-picture-120x120.png') + )), + ]); + } +} diff --git a/database/seeders/StaticPageSeeder.php b/database/seeders/StaticPageSeeder.php new file mode 100644 index 0000000..ce563f8 --- /dev/null +++ b/database/seeders/StaticPageSeeder.php @@ -0,0 +1,155 @@ +updateOrCreate( + [ + 'type' => StaticPageType::contact, + ], + [ + 'seo_title' => 'Seo title pour la page contactez nous', + 'seo_description' => 'Seo description pour la page contactez nous', + 'title' => 'Contactez-nous', + 'slug' => Str::slug('Contactez-nous'), + 'type' => StaticPageType::contact, + 'content' => '', + ] + ); + StaticPage::query()->updateOrCreate( + [ + 'type' => StaticPageType::legals, + ], + [ + 'seo_title' => 'Seo title pour la page mentions légales', + 'seo_description' => 'Seo description pour la page mentions légales', + 'title' => 'Mentions légales', + 'slug' => Str::slug('Mentions légales'), + 'type' => StaticPageType::legals, + 'content' => \clean(\fake()->randomHtml(6, 7)), + ] + ); + StaticPage::query()->updateOrCreate( + [ + 'type' => StaticPageType::confidentiality, + ], + [ + 'seo_title' => 'Seo title pour la page charte de confidentialitée', + 'seo_description' => 'Seo description pour la page charte de confidentialitée', + 'title' => 'Charte de confidentialitée', + 'slug' => Str::slug('Charte de confidentialitée'), + 'type' => StaticPageType::confidentiality, + 'content' => \clean(\fake()->randomHtml(6, 7)), + ] + ); + StaticPage::query()->updateOrCreate( + [ + 'type' => StaticPageType::home, + ], + [ + 'seo_title' => 'Seo title pour la page d\'accueil', + 'seo_description' => 'Seo description pour la page d\'accueil', + 'title' => 'Accueil', + 'slug' => Str::slug('Accueil'), + 'type' => StaticPageType::home, + 'content' => '', + ] + ); + StaticPage::query()->updateOrCreate( + [ + 'type' => StaticPageType::conviction, + ], + [ + 'seo_title' => 'Seo title pour la page Nos Convictions', + 'seo_description' => 'Seo description pour la page Nos Convictions', + 'title' => 'Nos Convictions', + 'slug' => Str::slug('Nos Convictions'), + 'type' => StaticPageType::conviction, + 'content' => '', + ] + ); + StaticPage::query()->updateOrCreate( + [ + 'type' => StaticPageType::explorer, + ], + [ + 'seo_title' => 'Seo title pour la page Explorateur & Gastronome', + 'seo_description' => 'Seo description pour la page Explorateur & Gastronome', + 'title' => 'Explorateur & Gastronome', + 'slug' => Str::slug('Explorateur & Gastronome'), + 'type' => StaticPageType::explorer, + 'content' => '', + ] + ); + StaticPage::query()->updateOrCreate( + [ + 'type' => StaticPageType::joinus, + ], + [ + 'seo_title' => 'Seo title pour la page Rejoignez-nous', + 'seo_description' => 'Seo description pour la page Rejoignez-nous', + 'title' => 'Rejoignez-nous', + 'slug' => Str::slug('Rejoignez-nous'), + 'type' => StaticPageType::joinus, + 'content' => '', + ] + ); + StaticPage::query()->updateOrCreate( + [ + 'type' => StaticPageType::ranges, + ], + [ + 'seo_title' => 'Seo title pour la page Nos Gammes de Produits', + 'seo_description' => 'Seo description pour la page Nos Gammes de Produits', + 'title' => 'Nos Gammes de Produits', + 'slug' => Str::slug('Nos Gammes de Produits'), + 'type' => StaticPageType::ranges, + 'content' => '', + ] + ); + StaticPage::query()->updateOrCreate( + [ + 'type' => StaticPageType::aboutus, + ], + [ + 'seo_title' => 'Seo title pour la page Nous Connaître', + 'seo_description' => 'Seo description pour la page Nous Connaître', + 'title' => 'Nous Connaître', + 'slug' => Str::slug('Nous Connaître'), + 'type' => StaticPageType::aboutus, + 'content' => '', + ] + ); + StaticPage::query()->updateOrCreate( + [ + 'type' => StaticPageType::news, + ], + [ + 'seo_title' => 'Seo title pour la page Actualités', + 'seo_description' => 'Seo description pour la page Actualités', + 'title' => 'Actualités', + 'slug' => Str::slug('Actualités'), + 'type' => StaticPageType::news, + 'content' => '', + ] + ); + } finally { + StaticPage::setEventDispatcher(new \Illuminate\Events\Dispatcher()); + } //end try + } +} diff --git a/database/seeders/TestimonialSeeder.php b/database/seeders/TestimonialSeeder.php new file mode 100644 index 0000000..599b2fa --- /dev/null +++ b/database/seeders/TestimonialSeeder.php @@ -0,0 +1,25 @@ +create([ + 'picture' => FileStorageHelper::storeFile(new Testimonial(), new \SplFileInfo( + \resource_path('../database/factories/assets/testimonials/default-picture-292x417.png') + )), + ]); + } +}