src/Entity/PurchaseNote.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. /**
  5.  * @ORM\Entity(repositoryClass="App\Repository\PurchaseNoteRepository")
  6.  */
  7. class PurchaseNote
  8. {
  9.     /**
  10.      * @ORM\Id()
  11.      * @ORM\GeneratedValue()
  12.      * @ORM\Column(type="integer")
  13.      */
  14.     private $id;
  15.     /**
  16.      * @ORM\ManyToOne(targetEntity="App\Entity\Purchase", inversedBy="purchaseNotes")
  17.      * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
  18.      */
  19.     private $purchase;
  20.     /**
  21.      * @ORM\Column(type="text")
  22.      */
  23.     private $description;
  24.     /**
  25.      * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="purchaseNotes")
  26.      * @ORM\JoinColumn(nullable=true)
  27.      */
  28.     private $author;
  29.     /**
  30.      * @ORM\Column(type="datetime")
  31.      */
  32.     private $modified_at;
  33.     /**
  34.      * @ORM\Column(type="datetime")
  35.      */
  36.     private $created_at;
  37.     /**
  38.      * @ORM\Column(type="string", length=255)
  39.      */
  40.     private $author_name;
  41.     /**
  42.      * @ORM\Column(type="string", length=255)
  43.      */
  44.     private $author_email;
  45.     /**
  46.      * @ORM\Column(type="text")
  47.      */
  48.     private $hidden_description;
  49.     
  50.     public function __construct ()
  51.     {
  52.         $this->description "";
  53.         $this->hidden_description "";
  54.         $this->modified_at = new \DateTime("now");
  55.         $this->created_at = new \DateTime("now");
  56.         $this->author_name "";
  57.         $this->author_email "";
  58.     }
  59.     public function getId()
  60.     {
  61.         return $this->id;
  62.     }
  63.     public function getPurchase(): ?purchase
  64.     {
  65.         return $this->purchase;
  66.     }
  67.     public function setPurchase(?purchase $purchase): self
  68.     {
  69.         $this->purchase $purchase;
  70.         return $this;
  71.     }
  72.     public function getDescription(): ?string
  73.     {
  74.         return $this->description;
  75.     }
  76.     public function setDescription(string $description null): self
  77.     {
  78.         $this->description $description $description "";
  79.         return $this;
  80.     }
  81.     public function getAuthor(): ?User
  82.     {
  83.         return $this->author;
  84.     }
  85.     public function setAuthor(?User $author): self
  86.     {
  87.         $this->author $author;
  88.         return $this;
  89.     }
  90.     public function getModifiedAt(): ?\DateTimeInterface
  91.     {
  92.         return $this->modified_at;
  93.     }
  94.     public function setModifiedAt(\DateTimeInterface $modified_at): self
  95.     {
  96.         $this->modified_at $modified_at;
  97.         return $this;
  98.     }
  99.     public function getCreatedAt(): ?\DateTimeInterface
  100.     {
  101.         return $this->created_at;
  102.     }
  103.     public function setCreatedAt(\DateTimeInterface $created_at): self
  104.     {
  105.         $this->created_at $created_at;
  106.         return $this;
  107.     }
  108.     public function getAuthorName(): ?string
  109.     {
  110.         if($this->author_name) {
  111.             return $this->author_name;
  112.         }
  113.         elseif($this->author) {
  114.             return $this->author->getDisplayname();
  115.         }
  116.         return "";
  117.     }
  118.     public function setAuthorName(string $author_name null): self
  119.     {
  120.         $this->author_name $author_name $author_name "";
  121.         return $this;
  122.     }
  123.     public function getAuthorEmail(): ?string
  124.     {
  125.         return $this->author_email;
  126.     }
  127.     public function setAuthorEmail(string $author_email null): self
  128.     {
  129.         $this->author_email $author_email $author_email "";
  130.         return $this;
  131.     }
  132.     public function getHiddenDescription(): ?string
  133.     {
  134.         return $this->hidden_description;
  135.     }
  136.     public function setHiddenDescription(string $hidden_description null): self
  137.     {
  138.         $this->hidden_description $hidden_description $hidden_description "";
  139.         return $this;
  140.     }
  141.     
  142.     public function getLine(): ?string
  143.     {
  144.         $text '';
  145.         if ($date $this->getCreatedAt()) {
  146.             $date $date->format('F j, Y \a\t g:i a ');
  147.             $text .= "added on {$date}";
  148.         }
  149.         if ($author $this->getAuthorName()) {
  150.             $text .= "by {$author}";
  151.         }
  152.         
  153.         return $text;
  154.     }
  155.     
  156.     public function __toString ()
  157.     {
  158.         return $this->id "" $this->id '';
  159.     }
  160.     
  161. }