This commit is contained in:
Julie Lenaerts 2022-02-25 09:29:28 +01:00
parent c4e0b68ebe
commit 051ed19f97
11 changed files with 82 additions and 81 deletions

View File

@ -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)
{

View File

@ -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",

View File

@ -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;
}

View File

@ -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'];
}
}
}

View File

@ -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);
// }
}

View File

@ -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');
}
}

View File

@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\Migrations\Budget;
@ -12,6 +19,14 @@ use Doctrine\Migrations\AbstractMigration;
*/
final class Version20220223123742 extends AbstractMigration
{
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');
}
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');
}
}

View File

@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\Migrations\Budget;
@ -12,6 +19,14 @@ use Doctrine\Migrations\AbstractMigration;
*/
final class Version20220224090319 extends AbstractMigration
{
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');
}
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');
}
}

View File

@ -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');

View File

@ -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();
}
}

View File

@ -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);
}
}