Add Origin Entity in Accompanying Period package

This commit is contained in:
Mathieu Jaumotte 2021-03-29 11:24:57 +02:00
parent ba31927dc3
commit acff64c16f
4 changed files with 214 additions and 1 deletions

View File

@ -22,6 +22,7 @@
namespace Chill\PersonBundle\Entity;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Origin;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
@ -93,6 +94,15 @@ class AccompanyingPeriod
*/
private $user;
/**
* @var Origin
*
* @ORM\ManyToOne(
* targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\Origin")
* @ORM\JoinColumn(nullable=true)
*/
private $origin;
/**
* AccompanyingPeriod constructor.
@ -355,5 +365,15 @@ class AccompanyingPeriod
return $this;
}
public function getOrigin(): Origin
{
return $this->origin;
}
public function setOrigin($origin): AccompanyingPeriod
{
$this->origin = $origin;
return $this;
}
}

View File

@ -0,0 +1,79 @@
<?php
/*
* Chill is a software for social workers
*
* Copyright (C) 2021, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriod\OriginRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=OriginRepository::class)
* @ORM\Table(name="chill_person_accompanying_period_origin")
*/
class Origin
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $label;
/**
* @ORM\Column(type="date_immutable", nullable=true)
*/
private $noActiveAfter;
public function getId(): ?int
{
return $this->id;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(string $label): self
{
$this->label = $label;
return $this;
}
public function getNoActiveAfter(): ?\DateTimeImmutable
{
return $this->noActiveAfter;
}
public function setNoActiveAfter(?\DateTimeImmutable $noActiveAfter): self
{
$this->noActiveAfter = $noActiveAfter;
return $this;
}
}

View File

@ -0,0 +1,69 @@
<?php
/*
* Chill is a software for social workers
*
* Copyright (C) 2021, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\PersonBundle\Repository\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Origin;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @method Origin|null find($id, $lockMode = null, $lockVersion = null)
* @method Origin|null findOneBy(array $criteria, array $orderBy = null)
* @method Origin[] findAll()
* @method Origin[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class OriginRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Origin::class);
}
// /**
// * @return Origin[] Returns an array of Origin objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('o')
->andWhere('o.exampleField = :val')
->setParameter('val', $value)
->orderBy('o.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
/*
public function findOneBySomeField($value): ?Origin
{
return $this->createQueryBuilder('o')
->andWhere('o.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}

View File

@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace Chill\Migrations\Person;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Add AccompanyingPeriod Origin table
*
* @author Mathieu Jaumotte mathieu.jaumotte@champs-libres.coop
*/
final class Version20210329090904 extends AbstractMigration
{
public function getDescription() : string
{
return 'Add AccompanyingPeriod Origin table';
}
public function up(Schema $schema) : void
{
$this->addSql('CREATE SEQUENCE chill_person_accompanying_period_origin_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE TABLE chill_person_accompanying_period_origin (id INT NOT NULL, label VARCHAR(255) NOT NULL, noActiveAfter DATE DEFAULT NULL, PRIMARY KEY(id))');
$this->addSql('COMMENT ON COLUMN chill_person_accompanying_period_origin.noActiveAfter IS \'(DC2Type:date_immutable)\'');
$this->addSql('ALTER TABLE chill_person_accompanying_period ADD origin_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE chill_person_accompanying_period ADD CONSTRAINT FK_E260A86856A273CC FOREIGN KEY (origin_id) REFERENCES chill_person_accompanying_period_origin (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_E260A86856A273CC ON chill_person_accompanying_period (origin_id)');
}
public function down(Schema $schema) : void
{
$this->addSql('ALTER TABLE chill_person_accompanying_period DROP CONSTRAINT FK_E260A86856A273CC');
$this->addSql('DROP SEQUENCE chill_person_accompanying_period_origin_id_seq CASCADE');
$this->addSql('DROP TABLE chill_person_accompanying_period_origin');
$this->addSql('DROP INDEX IDX_E260A86856A273CC');
$this->addSql('ALTER TABLE chill_person_accompanying_period DROP origin_id');
}
}