- Ajout page infrastructure/bovine avec CRUD - Refacto BuildingCase (suppression Statut, simplification) - Commande EnrichBovinesCommand pour enrichir les données bovins - 4 migrations Doctrine - Mise à jour composables shipment/weighing - Mise à jour README et CHANGELOG Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
252 lines
8.0 KiB
PHP
252 lines
8.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\DataFixtures;
|
|
|
|
use App\Entity\Building;
|
|
use App\Entity\BuildingCase;
|
|
use App\Entity\BuildingCasePosition;
|
|
use App\Entity\BuildingLayout;
|
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
|
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
|
use Doctrine\Persistence\ObjectManager;
|
|
use RuntimeException;
|
|
|
|
class BuildingInfrastructureFixtures extends Fixture implements DependentFixtureInterface
|
|
{
|
|
public function load(ObjectManager $manager): void
|
|
{
|
|
$buildings = $this->getBuildingsByCode($manager, ['B1', 'B2', 'B3']);
|
|
$layouts = $this->loadLayouts($manager, $buildings);
|
|
$cases = $this->loadBuildingCases($manager, $buildings);
|
|
$this->loadCasePositions($manager, $layouts, $cases);
|
|
|
|
$manager->flush();
|
|
}
|
|
|
|
public function getDependencies(): array
|
|
{
|
|
return [
|
|
ReferenceFixtures::class,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param list<string> $codes
|
|
*
|
|
* @return array<string, Building>
|
|
*/
|
|
private function getBuildingsByCode(ObjectManager $manager, array $codes): array
|
|
{
|
|
$repo = $manager->getRepository(Building::class);
|
|
$result = [];
|
|
|
|
foreach ($codes as $code) {
|
|
/** @var null|Building $building */
|
|
$building = $repo->findOneBy(['code' => $code]);
|
|
if (!$building instanceof Building) {
|
|
throw new RuntimeException(sprintf('Building "%s" not found. Load ReferenceFixtures first.', $code));
|
|
}
|
|
|
|
$result[$code] = $building;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* @param array<string, Building> $buildings
|
|
*
|
|
* @return array<string, BuildingLayout>
|
|
*/
|
|
private function loadLayouts(ObjectManager $manager, array $buildings): array
|
|
{
|
|
$repo = $manager->getRepository(BuildingLayout::class);
|
|
|
|
$data = [
|
|
['name' => 'plan1', 'columns' => 23, 'rows' => 2, 'buildingCode' => 'B1'],
|
|
['name' => 'plan2', 'columns' => 23, 'rows' => 2, 'buildingCode' => 'B2'],
|
|
['name' => 'plan3', 'columns' => 23, 'rows' => 2, 'buildingCode' => 'B3'],
|
|
];
|
|
|
|
$result = [];
|
|
foreach ($data as $row) {
|
|
/** @var null|BuildingLayout $layout */
|
|
$layout = $repo->findOneBy(['name' => $row['name']]);
|
|
if (!$layout instanceof BuildingLayout) {
|
|
$layout = new BuildingLayout()
|
|
->setName($row['name'])
|
|
->setColumns($row['columns'])
|
|
->setRows($row['rows'])
|
|
->setIdBuilding($buildings[$row['buildingCode']])
|
|
;
|
|
$manager->persist($layout);
|
|
}
|
|
|
|
$result[$row['buildingCode']] = $layout;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* @param array<string, Building> $buildings
|
|
*
|
|
* @return array<string, BuildingCase>
|
|
*/
|
|
private function loadBuildingCases(ObjectManager $manager, array $buildings): array
|
|
{
|
|
$repo = $manager->getRepository(BuildingCase::class);
|
|
|
|
$caseRanges = [
|
|
['buildingCode' => 'B1', 'from' => 1, 'to' => 44],
|
|
['buildingCode' => 'B2', 'from' => 1, 'to' => 44],
|
|
['buildingCode' => 'B3', 'from' => 1, 'to' => 44],
|
|
];
|
|
|
|
$result = [];
|
|
foreach ($caseRanges as $range) {
|
|
for ($caseNumber = $range['from']; $caseNumber <= $range['to']; ++$caseNumber) {
|
|
$code = sprintf('%s-C%d', $range['buildingCode'], $caseNumber);
|
|
|
|
if (isset($result[$code])) {
|
|
continue;
|
|
}
|
|
|
|
/** @var null|BuildingCase $buildingCase */
|
|
$buildingCase = $repo->findOneBy(['code' => $code]);
|
|
if (!$buildingCase instanceof BuildingCase) {
|
|
$buildingCase = new BuildingCase()
|
|
->setCaseNumber($caseNumber)
|
|
->setCode($code)
|
|
->setCapacity(15)
|
|
->setIdBuilding($buildings[$range['buildingCode']])
|
|
;
|
|
$manager->persist($buildingCase);
|
|
}
|
|
|
|
$result[$code] = $buildingCase;
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* @param array<string, BuildingLayout> $layouts
|
|
* @param array<string, BuildingCase> $casesByCode
|
|
*/
|
|
private function loadCasePositions(ObjectManager $manager, array $layouts, array $casesByCode): void
|
|
{
|
|
$repo = $manager->getRepository(BuildingCasePosition::class);
|
|
|
|
$layoutMap = [
|
|
'B1' => 'plan1',
|
|
'B2' => 'plan2',
|
|
'B3' => 'plan3',
|
|
];
|
|
|
|
$slots = $this->buildSlotMap();
|
|
|
|
foreach ($layoutMap as $buildingCode => $layoutName) {
|
|
$layout = $layouts[$buildingCode] ?? null;
|
|
if (!$layout instanceof BuildingLayout || $layout->getName() !== $layoutName) {
|
|
throw new RuntimeException(sprintf('Layout "%s" for building "%s" not found.', $layoutName, $buildingCode));
|
|
}
|
|
|
|
foreach ($slots as $slot) {
|
|
$caseCode = sprintf('%s-C%d', $buildingCode, $slot['caseNumber']);
|
|
$buildingCase = $casesByCode[$caseCode] ?? null;
|
|
|
|
if (!$buildingCase instanceof BuildingCase) {
|
|
throw new RuntimeException(sprintf('Building case "%s" not found.', $caseCode));
|
|
}
|
|
|
|
/** @var null|BuildingCasePosition $position */
|
|
$position = $repo->findOneBy([
|
|
'buildingLayout' => $layout,
|
|
'buildingCase' => $buildingCase,
|
|
'x' => $slot['x'],
|
|
'y' => $slot['y'],
|
|
]);
|
|
|
|
if ($position instanceof BuildingCasePosition) {
|
|
continue;
|
|
}
|
|
|
|
$position = new BuildingCasePosition()
|
|
->setX($slot['x'])
|
|
->setY($slot['y'])
|
|
->setW($slot['w'])
|
|
->setH($slot['h'])
|
|
->setRenderOrder((string) $slot['renderOrder'])
|
|
->setBuildingLayout($layout)
|
|
->setBuildingCase($buildingCase)
|
|
;
|
|
$manager->persist($position);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Reproduit le slot_map SQL (44 emplacements sur 2 lignes avec un gap en colonne 13).
|
|
*
|
|
* @return list<array{x:int,y:int,w:int,h:int,renderOrder:int,caseNumber:int}>
|
|
*/
|
|
private function buildSlotMap(): array
|
|
{
|
|
$slots = [];
|
|
|
|
// Ligne 1, colonnes 1..12 => cases 13..24
|
|
for ($c = 1; $c <= 12; ++$c) {
|
|
$slots[] = [
|
|
'x' => $c,
|
|
'y' => 1,
|
|
'w' => 1,
|
|
'h' => 1,
|
|
'renderOrder' => $c,
|
|
'caseNumber' => $c + 12,
|
|
];
|
|
}
|
|
|
|
// Ligne 1, colonnes 14..23 => cases 25..34
|
|
for ($c = 14; $c <= 23; ++$c) {
|
|
$slots[] = [
|
|
'x' => $c,
|
|
'y' => 1,
|
|
'w' => 1,
|
|
'h' => 1,
|
|
'renderOrder' => $c - 1,
|
|
'caseNumber' => $c + 11,
|
|
];
|
|
}
|
|
|
|
// Ligne 2, colonnes 1..12 => cases 12..1
|
|
for ($c = 1; $c <= 12; ++$c) {
|
|
$slots[] = [
|
|
'x' => $c,
|
|
'y' => 2,
|
|
'w' => 1,
|
|
'h' => 1,
|
|
'renderOrder' => 22 + $c,
|
|
'caseNumber' => 13 - $c,
|
|
];
|
|
}
|
|
|
|
// Ligne 2, colonnes 14..23 => cases 44..35
|
|
for ($c = 14; $c <= 23; ++$c) {
|
|
$slots[] = [
|
|
'x' => $c,
|
|
'y' => 2,
|
|
'w' => 1,
|
|
'h' => 1,
|
|
'renderOrder' => 21 + $c,
|
|
'caseNumber' => 58 - $c,
|
|
];
|
|
}
|
|
|
|
return $slots;
|
|
}
|
|
}
|