mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add ordering to social issue and social action
This commit is contained in:
parent
3d3cc9aeb4
commit
f2fd30b690
@ -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)) {
|
||||
|
@ -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)) {
|
||||
|
@ -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
|
||||
);
|
||||
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Person;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20211213213755 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Add ordering to social issue and social actions';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->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');
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user