diff --git a/src/Bundle/ChillBudgetBundle/Controller/AbstractElementController.php b/src/Bundle/ChillBudgetBundle/Controller/AbstractElementController.php index f468bd18a..d7bfc80c5 100644 --- a/src/Bundle/ChillBudgetBundle/Controller/AbstractElementController.php +++ b/src/Bundle/ChillBudgetBundle/Controller/AbstractElementController.php @@ -60,7 +60,7 @@ abstract class AbstractElementController extends Controller $form = $this->createDeleteForm(); - if (null != $element->getPerson()) { + if (null !== $element->getPerson()) { $entity = $element->getPerson(); $indexPage = 'chill_budget_elements_index'; } else { @@ -107,7 +107,7 @@ abstract class AbstractElementController extends Controller { $this->denyAccessUnlessGranted(BudgetElementVoter::UPDATE, $element); - if (null != $element->getPerson()) { + if (null !== $element->getPerson()) { $entity = $element->getPerson(); $entityStr = 'person'; $indexPage = 'chill_budget_elements_index'; @@ -117,7 +117,7 @@ abstract class AbstractElementController extends Controller $indexPage = 'chill_budget_elements_household_index'; } - $entity = null != $element->getPerson() ? : $element->getHousehold(); + $entity = null !== $element->getPerson() ?: $element->getHousehold(); $form = $this->createForm($this->getType(), $element); $form->add('submit', SubmitType::class); @@ -145,6 +145,7 @@ abstract class AbstractElementController extends Controller /** * @param mixed $template * @param mixed $flashMessageOnSuccess + * @param mixed $entity */ protected function _new($entity, Request $request, $template, $flashMessageOnSuccess) { diff --git a/src/Bundle/ChillBudgetBundle/Controller/ResourceController.php b/src/Bundle/ChillBudgetBundle/Controller/ResourceController.php index 69e53c415..738ebb8a5 100644 --- a/src/Bundle/ChillBudgetBundle/Controller/ResourceController.php +++ b/src/Bundle/ChillBudgetBundle/Controller/ResourceController.php @@ -54,7 +54,7 @@ class ResourceController extends AbstractElementController } /** - * Create a new budget element for a person + * Create a new budget element for a person. * * @Route( * "{_locale}/budget/resource/by-person/{id}/new", @@ -72,7 +72,7 @@ class ResourceController extends AbstractElementController } /** - * Create new budget element for a household + * Create new budget element for a household. * * @Route( * "{_locale}/budget/resource/by-household/{id}/new", diff --git a/src/Bundle/ChillBudgetBundle/Entity/AbstractElement.php b/src/Bundle/ChillBudgetBundle/Entity/AbstractElement.php index 52e895bec..747e6f4b4 100644 --- a/src/Bundle/ChillBudgetBundle/Entity/AbstractElement.php +++ b/src/Bundle/ChillBudgetBundle/Entity/AbstractElement.php @@ -44,7 +44,6 @@ abstract class AbstractElement private ?string $comment; /** - * * @ORM\Column(name="endDate", type="datetime_immutable", nullable=true) * @Assert\GreaterThan( * propertyPath="startDate", @@ -53,13 +52,6 @@ abstract class AbstractElement */ private ?DateTimeImmutable $endDate; - /** - * @ORM\ManyToOne( - * targetEntity="\Chill\PersonBundle\Entity\Person" - * ) - */ - private ?Person $person = null; - /** * @ORM\ManyToOne( * targetEntity="\Chill\PersonBundle\Entity\Household\Household" @@ -68,19 +60,24 @@ abstract class AbstractElement private ?Household $household = null; /** - * + * @ORM\ManyToOne( + * targetEntity="\Chill\PersonBundle\Entity\Person" + * ) + */ + private ?Person $person = null; + + /** * @ORM\Column(name="startDate", type="datetime_immutable") * @Assert\Date */ private DateTimeImmutable $startDate; /** - * * @ORM\Column(name="type", type="string", length=255) */ private string $type; - /**Getters and Setters */ + /*Getters and Setters */ public function getAmount(): float { @@ -97,16 +94,16 @@ abstract class AbstractElement return $this->endDate; } - public function getPerson(): ?Person - { - return $this->person; - } - public function getHousehold(): ?Household { return $this->household; } + public function getPerson(): ?Person + { + return $this->person; + } + public function getStartDate(): DateTimeImmutable { return $this->startDate; @@ -153,16 +150,16 @@ abstract class AbstractElement return $this; } - public function setPerson(Person $person): self + public function setHousehold(Household $household): self { - $this->person = $person; + $this->household = $household; return $this; } - public function setHousehold(Household $household): self + public function setPerson(Person $person): self { - $this->household = $household; + $this->person = $person; return $this; } diff --git a/src/Bundle/ChillBudgetBundle/Menu/HouseholdMenuBuilder.php b/src/Bundle/ChillBudgetBundle/Menu/HouseholdMenuBuilder.php index 273144bb9..e983ddebb 100644 --- a/src/Bundle/ChillBudgetBundle/Menu/HouseholdMenuBuilder.php +++ b/src/Bundle/ChillBudgetBundle/Menu/HouseholdMenuBuilder.php @@ -37,12 +37,12 @@ class HouseholdMenuBuilder implements LocalMenuBuilderInterface $household = $parameters['household']; // if ($this->authorizationChecker->isGranted(BudgetElementVoter::SHOW, $household)) { - $menu->addChild($this->translator->trans('household.Budget'), [ - 'route' => 'chill_budget_elements_household_index', - 'routeParameters' => [ - 'id' => $household->getId(), - ], ]) - ->setExtras(['order' => 50]); + $menu->addChild($this->translator->trans('household.Budget'), [ + 'route' => 'chill_budget_elements_household_index', + 'routeParameters' => [ + 'id' => $household->getId(), + ], ]) + ->setExtras(['order' => 50]); // } } @@ -50,4 +50,4 @@ class HouseholdMenuBuilder implements LocalMenuBuilderInterface { return ['household']; } -} \ No newline at end of file +} diff --git a/src/Bundle/ChillBudgetBundle/Menu/PersonMenuBuilder.php b/src/Bundle/ChillBudgetBundle/Menu/PersonMenuBuilder.php index 30f9be486..bd8434a9f 100644 --- a/src/Bundle/ChillBudgetBundle/Menu/PersonMenuBuilder.php +++ b/src/Bundle/ChillBudgetBundle/Menu/PersonMenuBuilder.php @@ -15,7 +15,6 @@ use Chill\BudgetBundle\Security\Authorization\BudgetElementVoter; use Chill\MainBundle\Routing\LocalMenuBuilderInterface; use Knp\Menu\MenuItem; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; -use Symfony\Component\Security\Core\Security; use Symfony\Contracts\Translation\TranslatorInterface; class PersonMenuBuilder implements LocalMenuBuilderInterface @@ -38,14 +37,14 @@ class PersonMenuBuilder implements LocalMenuBuilderInterface $person = $parameters['person']; // if ($this->authorizationChecker->isGranted(BudgetElementVoter::SHOW, $person)) { - $menu->addChild( - $this->translator->trans('Budget'), - [ - 'route' => 'chill_budget_elements_index', - 'routeParameters' => ['id' => $person->getId()], - ] - ) - ->setExtra('order', 4000); + $menu->addChild( + $this->translator->trans('Budget'), + [ + 'route' => 'chill_budget_elements_index', + 'routeParameters' => ['id' => $person->getId()], + ] + ) + ->setExtra('order', 4000); // } } diff --git a/src/Bundle/ChillBudgetBundle/Migrations/Version20180522080432.php b/src/Bundle/ChillBudgetBundle/Migrations/Version20180522080432.php index c76d4d010..3a8d350b7 100644 --- a/src/Bundle/ChillBudgetBundle/Migrations/Version20180522080432.php +++ b/src/Bundle/ChillBudgetBundle/Migrations/Version20180522080432.php @@ -11,7 +11,6 @@ declare(strict_types=1); namespace Application\Migrations; - use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; @@ -20,6 +19,13 @@ use Doctrine\Migrations\AbstractMigration; */ final class Version20180522080432 extends AbstractMigration { + public function down(Schema $schema): void + { + $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); + + $this->addSql('CREATE SCHEMA chill_budget CASCADE'); + } + public function getDescription(): string { return 'Creation of necessary tables for budget bundle'; @@ -44,12 +50,4 @@ final class Version20180522080432 extends AbstractMigration $this->addSql('ALTER TABLE chill_budget.resource ADD CONSTRAINT FK_5E0A5E97217BBB47 FOREIGN KEY (person_id) REFERENCES chill_person_person (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE chill_budget.charge ADD CONSTRAINT FK_5C99D2C3217BBB47 FOREIGN KEY (person_id) REFERENCES chill_person_person (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); } - - public function down(Schema $schema): void - { - $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); - - $this->addSql('CREATE SCHEMA chill_budget CASCADE'); - } - } diff --git a/src/Bundle/ChillBudgetBundle/Migrations/Version20220223123742.php b/src/Bundle/ChillBudgetBundle/Migrations/Version20220223123742.php index 9e2899bc4..9aea60034 100644 --- a/src/Bundle/ChillBudgetBundle/Migrations/Version20220223123742.php +++ b/src/Bundle/ChillBudgetBundle/Migrations/Version20220223123742.php @@ -1,5 +1,12 @@ addSql('DROP SEQUENCE chill_budget.charge_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE chill_budget.resource_id_seq CASCADE'); + $this->addSql('DROP TABLE chill_budget.charge'); + $this->addSql('DROP TABLE chill_budget.resource'); + } + public function getDescription(): string { return 'Creation of necessary tables for budget bundle'; @@ -33,12 +48,4 @@ final class Version20220223123742 extends AbstractMigration $this->addSql('ALTER TABLE chill_budget.charge ADD CONSTRAINT FK_5C99D2C3217BBB47 FOREIGN KEY (person_id) REFERENCES chill_person_person (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE chill_budget.resource ADD CONSTRAINT FK_5E0A5E97217BBB47 FOREIGN KEY (person_id) REFERENCES chill_person_person (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); } - - public function down(Schema $schema): void - { - $this->addSql('DROP SEQUENCE chill_budget.charge_id_seq CASCADE'); - $this->addSql('DROP SEQUENCE chill_budget.resource_id_seq CASCADE'); - $this->addSql('DROP TABLE chill_budget.charge'); - $this->addSql('DROP TABLE chill_budget.resource'); - } } diff --git a/src/Bundle/ChillBudgetBundle/Migrations/Version20220224090319.php b/src/Bundle/ChillBudgetBundle/Migrations/Version20220224090319.php index 8d8ab0349..9711cbc6d 100644 --- a/src/Bundle/ChillBudgetBundle/Migrations/Version20220224090319.php +++ b/src/Bundle/ChillBudgetBundle/Migrations/Version20220224090319.php @@ -1,5 +1,12 @@ addSql('ALTER TABLE chill_budget.charge DROP CONSTRAINT FK_5C99D2C3E79FF843'); + $this->addSql('ALTER TABLE chill_budget.charge DROP household_id'); + $this->addSql('ALTER TABLE chill_budget.resource DROP CONSTRAINT FK_5E0A5E97E79FF843'); + $this->addSql('ALTER TABLE chill_budget.resource DROP household_id'); + } + public function getDescription(): string { return 'Add household to budget AbstractElement'; @@ -26,12 +41,4 @@ final class Version20220224090319 extends AbstractMigration $this->addSql('ALTER TABLE chill_budget.resource ADD CONSTRAINT FK_5E0A5E97E79FF843 FOREIGN KEY (household_id) REFERENCES chill_person_household (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('CREATE INDEX IDX_5E0A5E97E79FF843 ON chill_budget.resource (household_id)'); } - - public function down(Schema $schema): void - { - $this->addSql('ALTER TABLE chill_budget.charge DROP CONSTRAINT FK_5C99D2C3E79FF843'); - $this->addSql('ALTER TABLE chill_budget.charge DROP household_id'); - $this->addSql('ALTER TABLE chill_budget.resource DROP CONSTRAINT FK_5E0A5E97E79FF843'); - $this->addSql('ALTER TABLE chill_budget.resource DROP household_id'); - } } diff --git a/src/Bundle/ChillBudgetBundle/Repository/ChargeRepository.php b/src/Bundle/ChillBudgetBundle/Repository/ChargeRepository.php index 01b0c7ad8..19592f2f9 100644 --- a/src/Bundle/ChillBudgetBundle/Repository/ChargeRepository.php +++ b/src/Bundle/ChillBudgetBundle/Repository/ChargeRepository.php @@ -50,7 +50,7 @@ class ChargeRepository extends EntityRepository $entityStr = $entity instanceof Person ? 'person' : 'household'; - $qb->where("c.$entityStr = :$entityStr") + $qb->where("c.{$entityStr} = :{$entityStr}") ->andWhere('c.startDate < :date') ->andWhere('c.startDate < :date OR c.startDate IS NULL'); diff --git a/src/Bundle/ChillBudgetBundle/Repository/ResourceRepository.php b/src/Bundle/ChillBudgetBundle/Repository/ResourceRepository.php index 0248536df..22f96ad65 100644 --- a/src/Bundle/ChillBudgetBundle/Repository/ResourceRepository.php +++ b/src/Bundle/ChillBudgetBundle/Repository/ResourceRepository.php @@ -11,7 +11,6 @@ declare(strict_types=1); namespace Chill\BudgetBundle\Repository; -use Chill\PersonBundle\Entity\Household\Household; use Chill\PersonBundle\Entity\Person; use DateTime; use Doctrine\ORM\EntityRepository; @@ -24,7 +23,6 @@ use Doctrine\ORM\EntityRepository; */ class ResourceRepository extends EntityRepository { - // public function findByEntity($entity) // { @@ -36,7 +34,7 @@ class ResourceRepository extends EntityRepository $entityStr = $entity instanceof Person ? 'person' : 'household'; - $qb->where("c.$entityStr = :$entityStr") + $qb->where("c.{$entityStr} = :{$entityStr}") ->andWhere('c.startDate < :date') ->andWhere('c.startDate < :date OR c.startDate IS NULL'); @@ -51,5 +49,4 @@ class ResourceRepository extends EntityRepository return $qb->getQuery()->getResult(); } - } diff --git a/src/Bundle/ChillBudgetBundle/Security/Authorization/BudgetElementVoter.php b/src/Bundle/ChillBudgetBundle/Security/Authorization/BudgetElementVoter.php index a396f78ba..f698e43ba 100644 --- a/src/Bundle/ChillBudgetBundle/Security/Authorization/BudgetElementVoter.php +++ b/src/Bundle/ChillBudgetBundle/Security/Authorization/BudgetElementVoter.php @@ -12,9 +12,7 @@ declare(strict_types=1); namespace Chill\BudgetBundle\Security\Authorization; use Chill\BudgetBundle\Entity\AbstractElement; -use Chill\MainBundle\Entity\User; use Chill\MainBundle\Security\Authorization\AbstractChillVoter; -use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Chill\MainBundle\Security\Authorization\VoterHelperFactoryInterface; use Chill\MainBundle\Security\Authorization\VoterHelperInterface; use Chill\MainBundle\Security\ProvideRoleHierarchyInterface; @@ -46,12 +44,11 @@ class BudgetElementVoter extends AbstractChillVoter implements ProvideRoleHierar public function __construct(VoterHelperFactoryInterface $voterFactory) { $this->voter = $voterFactory - ->generate(self::class) - ->addCheckFor(AbstractElement::class, self::ROLES) - ->addCheckFor(Person::class, [self::CREATE, self::SEE]) - ->addCheckFor(Household::class, [self::CREATE, self::SEE]) - ->build(); - + ->generate(self::class) + ->addCheckFor(AbstractElement::class, self::ROLES) + ->addCheckFor(Person::class, [self::CREATE, self::SEE]) + ->addCheckFor(Household::class, [self::CREATE, self::SEE]) + ->build(); } public function getRoles(): array @@ -77,8 +74,6 @@ class BudgetElementVoter extends AbstractChillVoter implements ProvideRoleHierar protected function voteOnAttribute($attribute, $subject, TokenInterface $token) { - return $this->voter->voteOnAttribute($attribute, $subject, $token); - } }