Add project collaboration entity
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20251007112311 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Project Collaborations. Table and relationship setup.';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE TABLE project_collaboration (id INT AUTO_INCREMENT NOT NULL, project_id INT NOT NULL, title VARCHAR(255) NOT NULL, description LONGTEXT NOT NULL, is_fulfilled TINYINT(1) NOT NULL, locales JSON NOT NULL COMMENT '(DC2Type:json)', INDEX IDX_EAB7425166D1F9C (project_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
|
||||
SQL);
|
||||
$this->addSql(<<<'SQL'
|
||||
ALTER TABLE project_collaboration ADD CONSTRAINT FK_EAB7425166D1F9C FOREIGN KEY (project_id) REFERENCES project (id)
|
||||
SQL);
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql(<<<'SQL'
|
||||
ALTER TABLE project_collaboration DROP FOREIGN KEY FK_EAB7425166D1F9C
|
||||
SQL);
|
||||
$this->addSql(<<<'SQL'
|
||||
DROP TABLE project_collaboration
|
||||
SQL);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Project;
|
||||
|
||||
use App\ApiResource\TimestampedCreationApiResource;
|
||||
use App\ApiResource\TimestampedUpdationApiResource;
|
||||
use App\Entity\Trait\LocalizedEntityTrait;
|
||||
use App\Mapping\Provider\EntityMapProvider;
|
||||
use App\Repository\Project\CollaborationRepository;
|
||||
use AutoMapper\Attribute\MapProvider;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Gedmo\Mapping\Annotation as Gedmo;
|
||||
|
||||
#[MapProvider(EntityMapProvider::class)]
|
||||
#[ORM\Table(name: 'project_collaboration')]
|
||||
#[ORM\Entity(repositoryClass: CollaborationRepository::class)]
|
||||
class Collaboration
|
||||
{
|
||||
use LocalizedEntityTrait;
|
||||
use TimestampedCreationApiResource;
|
||||
use TimestampedUpdationApiResource;
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'collaborations')]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?Project $project = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
#[Gedmo\Translatable()]
|
||||
private ?string $title = null;
|
||||
|
||||
#[ORM\Column(type: Types::TEXT)]
|
||||
#[Gedmo\Translatable()]
|
||||
private ?string $description = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?bool $fulfilled = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getProject(): ?Project
|
||||
{
|
||||
return $this->project;
|
||||
}
|
||||
|
||||
public function setProject(?Project $project): static
|
||||
{
|
||||
$this->project = $project;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTitle(): ?string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function setTitle(string $title): static
|
||||
{
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setDescription(string $description): static
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isFulfilled(): ?bool
|
||||
{
|
||||
return $this->fulfilled;
|
||||
}
|
||||
|
||||
public function setFulfilled(bool $fulfilled): static
|
||||
{
|
||||
$this->fulfilled = $fulfilled;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -141,6 +141,12 @@ class Project implements UserOwnedInterface, AccountingOwnerInterface, Localized
|
||||
#[ORM\OneToMany(targetEntity: Support::class, mappedBy: 'project')]
|
||||
private Collection $supports;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Collaboration>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: Collaboration::class, mappedBy: 'project')]
|
||||
private Collection $collaborations;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->accounting = Accounting::of($this);
|
||||
@@ -150,6 +156,7 @@ class Project implements UserOwnedInterface, AccountingOwnerInterface, Localized
|
||||
$this->updates = new ArrayCollection();
|
||||
$this->supports = new ArrayCollection();
|
||||
$this->categories = new ArrayCollection();
|
||||
$this->collaborations = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
@@ -475,4 +482,34 @@ class Project implements UserOwnedInterface, AccountingOwnerInterface, Localized
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Collaboration>
|
||||
*/
|
||||
public function getCollaborations(): Collection
|
||||
{
|
||||
return $this->collaborations;
|
||||
}
|
||||
|
||||
public function addCollaboration(Collaboration $collaboration): static
|
||||
{
|
||||
if (!$this->collaborations->contains($collaboration)) {
|
||||
$this->collaborations->add($collaboration);
|
||||
$collaboration->setProject($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeCollaboration(Collaboration $collaboration): static
|
||||
{
|
||||
if ($this->collaborations->removeElement($collaboration)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($collaboration->getProject() === $this) {
|
||||
$collaboration->setProject(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository\Project;
|
||||
|
||||
use App\Entity\Project\Collaboration;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Collaboration>
|
||||
*/
|
||||
class CollaborationRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Collaboration::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return Collaboration[] Returns an array of Collaboration objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('c')
|
||||
// ->andWhere('c.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('c.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?Collaboration
|
||||
// {
|
||||
// return $this->createQueryBuilder('c')
|
||||
// ->andWhere('c.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user