diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php index 391a9ce89..d65c1a7c9 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php @@ -87,6 +87,11 @@ class SocialAction */ private $title = []; + /** + * @ORM\Column(type="float", name="ordering", options={"default": 0.0}) + */ + private float $ordering = 0.0; + public function __construct() { $this->children = new ArrayCollection(); @@ -95,6 +100,17 @@ class SocialAction $this->evaluations = new ArrayCollection(); } + public function getOrdering(): float + { + return $this->ordering; + } + + public function setOrdering(float $ordering): SocialAction + { + $this->ordering = $ordering; + return $this; + } + public function addChild(self $child): self { if (!$this->children->contains($child)) { diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php index b0be1ae00..99f7586c4 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php @@ -60,12 +60,28 @@ class SocialIssue */ private $title = []; + /** + * @ORM\Column(type="float", name="ordering", options={"default": 0.0}) + */ + private float $ordering = 0.0; + public function __construct() { $this->children = new ArrayCollection(); $this->socialActions = new ArrayCollection(); } + public function getOrdering(): float + { + return $this->ordering; + } + + public function setOrdering(float $ordering): SocialIssue + { + $this->ordering = $ordering; + return $this; + } + public function addChild(self $child): self { if (!$this->children->contains($child)) { diff --git a/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php b/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php index 53d24c788..621b97b7e 100644 --- a/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php +++ b/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php @@ -253,6 +253,8 @@ final class SocialWorkMetadata implements SocialWorkMetadataInterface ?string $socialActionTitle, ?string $socialActionChildTitle, SocialIssue $socialIssue, + float $orderingParent, + float $orderingChild, ?SocialAction $previousSocialAction, ?SocialAction $previousSocialActionChild ): array { @@ -271,7 +273,8 @@ final class SocialWorkMetadata implements SocialWorkMetadataInterface ]; $parentIsSame = true; } else { - $return['socialAction'] = $parent = (new SocialAction())->setTitle(['fr' => $socialActionTitle]); + $return['socialAction'] = $parent = (new SocialAction())->setTitle(['fr' => $socialActionTitle]) + ->setOrdering($orderingParent); $parent->setIssue($socialIssue); $this->entityManager->persist($parent); $parentIsSame = false; @@ -284,7 +287,7 @@ final class SocialWorkMetadata implements SocialWorkMetadataInterface } else { $return['socialActionChild'] = $child = (new SocialAction())->setTitle(['fr' => $socialActionChildTitle]); $parent->addChild($child); - $child->setIssue($socialIssue); + $child->setIssue($socialIssue)->setOrdering($orderingChild); $this->entityManager->persist($child); } @@ -299,6 +302,8 @@ final class SocialWorkMetadata implements SocialWorkMetadataInterface private function handleSocialIssue( ?string $socialIssueTitle, ?string $socialIssueChildTitle, + float $orderingParent, + float $orderingChild, ?SocialIssue $previousSocialIssue, ?SocialIssue $previousSocialIssueChild ): array { @@ -310,7 +315,8 @@ final class SocialWorkMetadata implements SocialWorkMetadataInterface ]; $parentIsSame = true; } elseif (null !== $socialIssueTitle) { - $return['socialIssue'] = $parent = (new SocialIssue())->setTitle(['fr' => $socialIssueTitle]); + $return['socialIssue'] = $parent = (new SocialIssue())->setTitle(['fr' => $socialIssueTitle]) + ->setOrdering($orderingParent); $this->entityManager->persist($parent); $parentIsSame = false; } else { @@ -323,7 +329,8 @@ final class SocialWorkMetadata implements SocialWorkMetadataInterface if ($parentIsSame && null !== $previousSocialIssueChild && ($previousSocialIssueChild->getTitle()['fr'] === $socialIssueChildTitle)) { $return['socialIssueChild'] = $previousSocialIssueChild; } elseif (null !== $socialIssueChildTitle) { - $return['socialIssueChild'] = $child = (new SocialIssue())->setTitle(['fr' => $socialIssueChildTitle]); + $return['socialIssueChild'] = $child = (new SocialIssue())->setTitle(['fr' => $socialIssueChildTitle]) + ->setOrdering($orderingChild); $parent->addChild($child); $this->entityManager->persist($child); } else { @@ -353,10 +360,14 @@ final class SocialWorkMetadata implements SocialWorkMetadataInterface */ private function import1(int $key, array $row, array $previousRow): array { + $baseOrdering = $key * 10.0; + $socialIssues = $this ->handleSocialIssue( $row[0], $row[1], + $key + 1.0, + $key + 3.0, $previousRow['socialIssues']['socialIssue'] ?? null, $previousRow['socialIssues']['socialIssueChild'] ?? null ); @@ -372,6 +383,8 @@ final class SocialWorkMetadata implements SocialWorkMetadataInterface $row[2], $row[3], $socialIssue, + $key + 5.0, + $key + 7.0, $previousRow['socialActions']['socialAction'] ?? null, $previousRow['socialActions']['socialActionChild'] ?? null ); diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20211213213755.php b/src/Bundle/ChillPersonBundle/migrations/Version20211213213755.php new file mode 100644 index 000000000..b3bb07b89 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20211213213755.php @@ -0,0 +1,28 @@ +addSql('ALTER TABLE chill_person_social_action ADD ordering DOUBLE PRECISION DEFAULT \'0\' NOT NULL'); + $this->addSql('ALTER TABLE chill_person_social_issue ADD ordering DOUBLE PRECISION DEFAULT \'0\' NOT NULL'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_person_social_action DROP ordering'); + $this->addSql('ALTER TABLE chill_person_social_issue DROP ordering'); + } +}