ldc-volena/database/seeders/Development/SectionSeeder.php
Jérémy Munsch f3d79cf7a9
Bump with laravel base controller phpstan and phpcs
Still TODO picture sizes for seeders
2024-02-12 15:51:31 +01:00

319 lines
9.3 KiB
PHP

<?php
namespace Database\Seeders\Development;
use App\Enums\Sections\PageSectionEnum;
use App\Enums\StaticPageType;
use App\Lib\Helpers\FileStorageHelper;
use App\Models\Section;
use App\Models\StaticPage;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;
/**
* FIXME: Definir les tailes d'images pour les sections
*
* @package Database\Seeders\Development
*/
class SectionSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
FileStorageHelper::removeModelFiles(new Section());
foreach (PageSectionEnum::cases() as $sectionEnum) {
// @phpstan-ignore-next-line
Section::factory(1)->make()->each(function (Section $section) use ($sectionEnum) {
$section->section = $sectionEnum;
$section->page_id = $this->getPageId($sectionEnum);
if ($sectionEnum === PageSectionEnum::hire_grow) {
$section->text = '';
};
// Call function according to the enum name.
$section->data = \method_exists(self::class, sprintf('get%sData', Str::studly($sectionEnum->name))) ?
self::{sprintf('get%sData', Str::studly($sectionEnum->name))}($section) :
[];
$section->saveQuietly();
});
} //end foreach
}
/**
* Get PageId related to the section.
*
* @param \App\Enums\Sections\PageSectionEnum $sectionEnum
* @return integer
*/
private function getPageId(\App\Enums\Sections\PageSectionEnum $sectionEnum): int
{
return match ($sectionEnum) {
PageSectionEnum::home_ambition,
PageSectionEnum::home_life,
PageSectionEnum::home_missions,
PageSectionEnum::home_team => StaticPage::where('type', StaticPageType::home)->first()->id,
PageSectionEnum::unveil_pole,
PageSectionEnum::unveil_local,
PageSectionEnum::unveil_sites,
PageSectionEnum::unveil_history,
PageSectionEnum::unveil_commitments => StaticPage::where('type', StaticPageType::unveil)->first()->id,
PageSectionEnum::hire_life,
PageSectionEnum::hire_formation,
PageSectionEnum::hire_grow,
PageSectionEnum::hire_parity,
PageSectionEnum::hire_find => StaticPage::where('type', StaticPageType::we_hire)->first()->id,
PageSectionEnum::commit_ambition,
PageSectionEnum::commit_breeding,
PageSectionEnum::commit_living,
PageSectionEnum::commit_respect_earth,
PageSectionEnum::commit_feed,
PageSectionEnum::commit_commitments => StaticPage::where('type', StaticPageType::we_commit)->first()->id,
PageSectionEnum::move_life,
PageSectionEnum::move_commitments => StaticPage::where('type', StaticPageType::we_move)->first()->id,
PageSectionEnum::produce_local,
PageSectionEnum::produce_gms,
PageSectionEnum::produce_rhd,
PageSectionEnum::produce_export,
PageSectionEnum::produce_quality,
PageSectionEnum::produce_linking => StaticPage::where('type', StaticPageType::we_produce)->first()->id,
PageSectionEnum::listening_study => StaticPage::where('type', StaticPageType::we_listen)->first()->id,
}; //end match
}
/**
* Get MiniCrud datas for Home - Ambition section.
*
* @param \App\Models\Section $section
* @return array
*/
private function getHomeAmbitionData(\App\Models\Section $section)
{
return $section->getHomeAmbitionBloc([]);
}
/**
* Get MiniCrud datas for Home - Life section.
*
* @param \App\Models\Section $section
* @return array
*/
private function getHomeLifeData(\App\Models\Section $section)
{
return $section->getHomeLifeBloc([]);
}
/**
* Get MiniCrud datas for Home - Missions section.
*
* @param \App\Models\Section $section
* @return array
*/
private function getHomeMissionsData(\App\Models\Section $section)
{
return $section->getHomeMissionsBloc(
[],
FileStorageHelper::storeFile(
new Section(),
new \SplFileInfo(\resource_path(
'../database/factories/assets/sections/home-missions-430x430.jpg'
))
),
fake()->sentence(),
fake()->sentence(),
430,
430,
fake()->url(),
fake()->randomNumber(),
fake()->randomNumber()
);
}
/**
* Get MiniCrud datas for Home - Team section.
*
* @param \App\Models\Section $section
* @return array
*/
private function getHomeTeamData(\App\Models\Section $section)
{
return $section->getHomeTeamBloc(
[],
FileStorageHelper::storeFile(
new Section(),
new \SplFileInfo(\resource_path(
'../database/factories/assets/sections/home-team-465x525.jpg'
))
),
fake()->sentence(),
fake()->sentence(),
465,
525,
fake()->url(),
);
}
/**
* Get MiniCrud datas for Unveil - Pole section.
*
* @param \App\Models\Section $section
* @return array
*/
private function getUnveilPoleData(\App\Models\Section $section)
{
return $section->getUnveilPoleBloc(
[],
fake()->randomNumber(),
fake()->randomNumber(),
fake()->randomNumber(),
fake()->randomNumber()
);
}
/**
* Get MiniCrud datas for Hire - Grow section.
*
* @param \App\Models\Section $section
* @return array
*/
private function getHireGrowData(\App\Models\Section $section)
{
return $section->getHireGrowBloc(
[],
fake()->text(35)
);
}
/**
* Get MiniCrud datas for Hire - Parity section.
*
* @param \App\Models\Section $section
* @return array
*/
private function getHireParityData(\App\Models\Section $section)
{
return $section->getHireParityBloc(
[],
FileStorageHelper::storeFile(
new Section(),
new \SplFileInfo(\resource_path(
'../database/factories/assets/sections/default-picture-100x100.png'
))
),
fake()->sentence(),
fake()->sentence(),
100,
100,
);
}
/**
* Get MiniCrud datas for Commit - Breeding section.
*
* @param \App\Models\Section $section
* @return array
*/
private function getCommitBreedingData(\App\Models\Section $section)
{
return $section->getCommitBreedingBloc(
[],
FileStorageHelper::storeFile(
new Section(),
new \SplFileInfo(\resource_path(
'../database/factories/assets/sections/default-picture-100x100.png'
))
),
fake()->sentence(),
fake()->sentence(),
100,
100,
);
}
/**
* Get MiniCrud datas for Commit - Living section.
*
* @param \App\Models\Section $section
* @return array
*/
private function getCommitLivingData(\App\Models\Section $section)
{
return $section->getCommitLivingBloc(
[],
\clean(\fake()->randomHtml())
);
}
/**
* Get MiniCrud datas for Commit - Respect Earth section.
*
* @param \App\Models\Section $section
* @return array
*/
private function getCommitRespectEarthData(\App\Models\Section $section)
{
return $section->getCommitRespectEarthBloc(
[],
\clean(\fake()->randomHtml())
);
}
/**
* Get MiniCrud datas for Commit - Feed section.
*
* @param \App\Models\Section $section
* @return array
*/
private function getCommitFeedData(\App\Models\Section $section)
{
return $section->getCommitFeedBloc(
[],
\clean(\fake()->randomHtml()),
\clean(\fake()->randomHtml())
);
}
/**
* Get MiniCrud datas for Commit - Commitments section.
*
* @param \App\Models\Section $section
* @return array
*/
private function getCommitCommitmentsData(\App\Models\Section $section)
{
return $section->getCommitCommitmentsBloc(
[],
fake()->sentence(),
fake()->sentence()
);
}
/**
* Get MiniCrud datas for Move - Commitments section.
*
* @param \App\Models\Section $section
* @return array
*/
private function getMoveCommitmentsData(\App\Models\Section $section)
{
return $section->getMoveCommitmentsBloc([]);
}
/**
* Get MiniCrud datas for Produce - Linking section.
*
* @param \App\Models\Section $section
* @return array
*/
private function getProduceLinkingData(\App\Models\Section $section)
{
return $section->getProduceLinkingBloc(
[],
\clean(\fake()->randomHtml()),
\clean(\fake()->randomHtml())
);
}
}