src/Entity/Obligation.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Building;
  4. use DateTime;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. use App\Entity\User;
  8. /**
  9.  * @ORM\Entity(repositoryClass="App\Repository\ObligationRepository")
  10.  */
  11. class Obligation
  12. {
  13.     /**
  14.      * @ORM\Column(name="id", type="integer")
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue(strategy="AUTO")
  17.      */
  18.     private int $id;
  19.     /**
  20.      * @ORM\Column(name="title", type="string", length=255, nullable=true)
  21.      *
  22.      */
  23.     private string|null $title;
  24.     /**
  25.      * @Assert\Length(
  26.      *    max = 255,
  27.      *    maxMessage = "Tekst treba da ima maksimalno {{ limit }} karaktera."
  28.      * )
  29.      *
  30.      * @ORM\Column(name="text", type="string", length=255, nullable=true)
  31.      *
  32.      */
  33.     private string|null $text;
  34.     /**
  35.      * @ORM\Column(name="date", type="datetime")
  36.      */
  37.     private DateTime $date;
  38.     /**
  39.      * @ORM\Column(name="end", type="datetime", nullable=true)
  40.      */
  41.     private DateTime|null $end;
  42.     /**
  43.      * @ORM\Column(name="done", type="boolean", nullable=true, options={"default" : false})
  44.      */
  45.     private bool|null $done;
  46.     /**
  47.      * @ORM\ManyToOne(targetEntity="App\Entity\Building", cascade={"persist"})
  48.      * @ORM\JoinColumns({
  49.      *   @ORM\JoinColumn(name="building_id", referencedColumnName="id", nullable=true, onDelete="CASCADE")
  50.      * })
  51.      */
  52.     private Building|null $building;
  53.     /**
  54.      * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="obligations")
  55.      * @ORM\JoinColumns({
  56.      *   @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
  57.      * })
  58.      */
  59.     private User $user;
  60.     /**
  61.      * @ORM\Column(name="createdAt", type="datetime")
  62.      */
  63.     private DateTime|null $createdAt;
  64.     /**
  65.      * @ORM\Column(name="createdBy", type="string", nullable=true)
  66.      */
  67.     private string|null $createdBy;
  68.     /**
  69.      * @return string|null
  70.      */
  71.     public function getCreatedBy(): ?string
  72.     {
  73.         return $this->createdBy;
  74.     }
  75.     public function __construct()
  76.     {
  77.         $this->setCreatedAt(new DateTime());
  78.     }
  79.     /**
  80.      * Get id
  81.      *
  82.      * @return int
  83.      */
  84.     public function getId(): int
  85.     {
  86.         return $this->id;
  87.     }
  88.     /**
  89.      * @return string|null
  90.      */
  91.     public function getTitle(): ?string
  92.     {
  93.         return $this->title;
  94.     }
  95.     /**
  96.      * @param string|null $title
  97.      */
  98.     public function setTitle(?string $title): void
  99.     {
  100.         $this->title $title;
  101.     }
  102.     /**
  103.      * @return string|null
  104.      */
  105.     public function getText(): ?string
  106.     {
  107.         return $this->text;
  108.     }
  109.     /**
  110.      * @param string|null $text
  111.      */
  112.     public function setText(?string $text): void
  113.     {
  114.         $this->text $text;
  115.     }
  116.     /**
  117.      * @return DateTime
  118.      */
  119.     public function getDate(): DateTime
  120.     {
  121.         return $this->date;
  122.     }
  123.     /**
  124.      * @param DateTime $date
  125.      */
  126.     public function setDate(DateTime $date): void
  127.     {
  128.         $this->date $date;
  129.     }
  130.     /**
  131.      * @return DateTime|null
  132.      */
  133.     public function getEnd(): ?DateTime
  134.     {
  135.         return $this->end;
  136.     }
  137.     /**
  138.      * @param DateTime|null $end
  139.      */
  140.     public function setEnd(?DateTime $end): void
  141.     {
  142.         $this->end $end;
  143.     }
  144.     /**
  145.      * @return bool|null
  146.      */
  147.     public function isDone(): ?bool
  148.     {
  149.         return $this->done;
  150.     }
  151.     /**
  152.      * @param bool|null $done
  153.      */
  154.     public function setDone(?bool $done): void
  155.     {
  156.         $this->done $done;
  157.     }
  158.     /**
  159.      * @return DateTime|null
  160.      */
  161.     public function getCreatedAt(): ?DateTime
  162.     {
  163.         return $this->createdAt;
  164.     }
  165.     /**
  166.      * @param DateTime $createdAt
  167.      */
  168.     public function setCreatedAt(DateTime $createdAt): void
  169.     {
  170.         $this->createdAt $createdAt;
  171.     }
  172.     /**
  173.      * @return User
  174.      */
  175.     public function getUser(): User
  176.     {
  177.         return $this->user;
  178.     }
  179.     /**
  180.      * @param User|null $user
  181.      */
  182.     public function setUser(?User $user): void
  183.     {
  184.         $this->user $user;
  185.         if (empty($this->createdBy)) {
  186.             if ($user) {
  187.                 $this->createdBy $user->getCreatedByValue();
  188.             }
  189.         }
  190.     }
  191.     public function __toString()
  192.     {
  193.         return (string) $this->getTitle();
  194.     }
  195.     /**
  196.      * @return Building|null
  197.      */
  198.     public function getBuilding(): ?Building
  199.     {
  200.         return $this->building;
  201.     }
  202.     /**
  203.      * @param Building|null $building
  204.      */
  205.     public function setBuilding(?Building $building): void
  206.     {
  207.         $this->building $building;
  208.     }
  209. }