create offerings and its migration
This commit is contained in:
parent
f3ad0e4638
commit
307954d46f
4 changed files with 223 additions and 0 deletions
93
src/Entity/Offering.php
Normal file
93
src/Entity/Offering.php
Normal file
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\OfferingRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity(repositoryClass=OfferingRepository::class)
|
||||
*/
|
||||
class Offering
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="offerings")
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
*/
|
||||
private $byUser;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime")
|
||||
*/
|
||||
private $createdAt;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255)
|
||||
*/
|
||||
private $title;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
*/
|
||||
private $photoFilename;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getByUser(): ?User
|
||||
{
|
||||
return $this->byUser;
|
||||
}
|
||||
|
||||
public function setByUser(?User $byUser): self
|
||||
{
|
||||
$this->byUser = $byUser;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCreatedAt(): ?\DateTimeInterface
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
public function setCreatedAt(\DateTimeInterface $createdAt): self
|
||||
{
|
||||
$this->createdAt = $createdAt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTitle(): ?string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function setTitle(string $title): self
|
||||
{
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPhotoFilename(): ?string
|
||||
{
|
||||
return $this->photoFilename;
|
||||
}
|
||||
|
||||
public function setPhotoFilename(?string $photoFilename): self
|
||||
{
|
||||
$this->photoFilename = $photoFilename;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -3,6 +3,8 @@
|
|||
namespace App\Entity;
|
||||
|
||||
use App\Repository\UserRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
@ -47,6 +49,16 @@ class User implements UserInterface
|
|||
*/
|
||||
private $username;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity=Offering::class, mappedBy="byUser", orphanRemoval=true)
|
||||
*/
|
||||
private $offerings;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->offerings = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
|
@ -146,4 +158,34 @@ class User implements UserInterface
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection|Offering[]
|
||||
*/
|
||||
public function getOfferings(): Collection
|
||||
{
|
||||
return $this->offerings;
|
||||
}
|
||||
|
||||
public function addOffering(Offering $offering): self
|
||||
{
|
||||
if (!$this->offerings->contains($offering)) {
|
||||
$this->offerings[] = $offering;
|
||||
$offering->setByUser($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeOffering(Offering $offering): self
|
||||
{
|
||||
if ($this->offerings->removeElement($offering)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($offering->getByUser() === $this) {
|
||||
$offering->setByUser(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue