mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-28 17:44:58 +00:00
Refactor LoadMotives fixture to support hierarchical motive relationships
- Implemented parent/child relationships in motive construction logic. - Refactored data parsing to handle nested motives with labels and associated attributes. - Updated fixtures to align with the new hierarchical motive structure.
This commit is contained in:
@@ -13,7 +13,6 @@ namespace Chill\TicketBundle\DataFixtures\ORM;
|
|||||||
|
|
||||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||||
use Chill\DocStoreBundle\Service\StoredObjectManagerInterface;
|
use Chill\DocStoreBundle\Service\StoredObjectManagerInterface;
|
||||||
use Chill\TicketBundle\Entity\EmergencyStatusEnum;
|
|
||||||
use Chill\TicketBundle\Entity\Motive;
|
use Chill\TicketBundle\Entity\Motive;
|
||||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||||
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
|
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
|
||||||
@@ -35,6 +34,7 @@ final class LoadMotives extends Fixture implements FixtureGroupInterface
|
|||||||
['label' => '☀️ De 07h à 21h', 'path' => __DIR__.'/docs/peloton_2.pdf'],
|
['label' => '☀️ De 07h à 21h', 'path' => __DIR__.'/docs/peloton_2.pdf'],
|
||||||
['label' => 'Dimanche et jours fériés', 'path' => __DIR__.'/docs/schema_1.png'],
|
['label' => 'Dimanche et jours fériés', 'path' => __DIR__.'/docs/schema_1.png'],
|
||||||
];
|
];
|
||||||
|
$motivesByLabel = [];
|
||||||
|
|
||||||
foreach (explode("\n", self::MOTIVES) as $row) {
|
foreach (explode("\n", self::MOTIVES) as $row) {
|
||||||
if ('' === trim($row)) {
|
if ('' === trim($row)) {
|
||||||
@@ -46,14 +46,29 @@ final class LoadMotives extends Fixture implements FixtureGroupInterface
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$motive = new Motive();
|
$labels = explode(' > ', $data[0]);
|
||||||
$motive->setLabel(['fr' => trim((string) $data[0])]);
|
$parent = null;
|
||||||
$motive->setMakeTicketEmergency(match ($data[1]) {
|
|
||||||
'true' => EmergencyStatusEnum::YES,
|
|
||||||
'false' => EmergencyStatusEnum::NO,
|
|
||||||
default => throw new \UnexpectedValueException('Unexpected value'),
|
|
||||||
});
|
|
||||||
|
|
||||||
|
while (count($labels) > 0) {
|
||||||
|
$label = array_shift($labels);
|
||||||
|
dump($labels);
|
||||||
|
if (isset($motivesByLabel[$label])) {
|
||||||
|
$motive = $motivesByLabel[$label];
|
||||||
|
} else {
|
||||||
|
$motive = new Motive();
|
||||||
|
$motive->setLabel(['fr' => $label]);
|
||||||
|
$motivesByLabel[$label] = $motive;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $parent) {
|
||||||
|
$motive->setParent($parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
$manager->persist($motive);
|
||||||
|
$parent = $motive;
|
||||||
|
|
||||||
|
if (0 === count($labels)) {
|
||||||
|
// this is the last one, we add data
|
||||||
$numberOfDocs = (int) $data[2];
|
$numberOfDocs = (int) $data[2];
|
||||||
for ($i = 1; $i <= $numberOfDocs; ++$i) {
|
for ($i = 1; $i <= $numberOfDocs; ++$i) {
|
||||||
$doc = $docs[$i - 1];
|
$doc = $docs[$i - 1];
|
||||||
@@ -78,18 +93,18 @@ final class LoadMotives extends Fixture implements FixtureGroupInterface
|
|||||||
$motive->addSupplementaryComment(['label' => trim((string) $supplementaryComment)]);
|
$motive->addSupplementaryComment(['label' => trim((string) $supplementaryComment)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$manager->persist($motive);
|
}
|
||||||
}
|
}
|
||||||
$manager->flush();
|
$manager->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
private const MOTIVES = <<<'CSV'
|
private const MOTIVES = <<<'CSV'
|
||||||
"Coordonnées",false,"3","Nouvelles coordonnées",
|
"Motif administratif > Coordonnées",false,"3","Nouvelles coordonnées",
|
||||||
"Horaire de passage",false,"0",
|
"Organisation > Horaire de passage",false,"0",
|
||||||
"Retard de livraison",false,"0",
|
"Organisation > Livraison > Retard de livraison",false,"0",
|
||||||
"Erreur de livraison",false,"0",
|
"Organisation > Livraison > Erreur de livraison",false,"0",
|
||||||
"Colis incomplet",false,"0",
|
"Organisation > Livraison > Colis incomplet",false,"0",
|
||||||
"MATLOC",false,"0",
|
"MATLOC",false,"0",
|
||||||
"Retard DASRI",false,"1",
|
"Retard DASRI",false,"1",
|
||||||
"Planning d'astreintes",false,"0",
|
"Planning d'astreintes",false,"0",
|
||||||
@@ -116,7 +131,7 @@ final class LoadMotives extends Fixture implements FixtureGroupInterface
|
|||||||
"Mauvaise adresse",false,"0",
|
"Mauvaise adresse",false,"0",
|
||||||
"Patient absent",false,"0",
|
"Patient absent",false,"0",
|
||||||
"Annulation",false,"0",
|
"Annulation",false,"0",
|
||||||
"Colis perdu",false,"0",
|
"Organisation > Livraison > Colis perdu",false,"0",
|
||||||
"Changement de rendez-vous",false,"0",
|
"Changement de rendez-vous",false,"0",
|
||||||
"Coordination interservices",false,"0",
|
"Coordination interservices",false,"0",
|
||||||
"Problème de substitution produits",true,"0",
|
"Problème de substitution produits",true,"0",
|
||||||
|
Reference in New Issue
Block a user