<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\PurchaseNoteRepository")
*/
class PurchaseNote
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Purchase", inversedBy="purchaseNotes")
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
*/
private $purchase;
/**
* @ORM\Column(type="text")
*/
private $description;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="purchaseNotes")
* @ORM\JoinColumn(nullable=true)
*/
private $author;
/**
* @ORM\Column(type="datetime")
*/
private $modified_at;
/**
* @ORM\Column(type="datetime")
*/
private $created_at;
/**
* @ORM\Column(type="string", length=255)
*/
private $author_name;
/**
* @ORM\Column(type="string", length=255)
*/
private $author_email;
/**
* @ORM\Column(type="text")
*/
private $hidden_description;
public function __construct ()
{
$this->description = "";
$this->hidden_description = "";
$this->modified_at = new \DateTime("now");
$this->created_at = new \DateTime("now");
$this->author_name = "";
$this->author_email = "";
}
public function getId()
{
return $this->id;
}
public function getPurchase(): ?purchase
{
return $this->purchase;
}
public function setPurchase(?purchase $purchase): self
{
$this->purchase = $purchase;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description = null): self
{
$this->description = $description ? $description : "";
return $this;
}
public function getAuthor(): ?User
{
return $this->author;
}
public function setAuthor(?User $author): self
{
$this->author = $author;
return $this;
}
public function getModifiedAt(): ?\DateTimeInterface
{
return $this->modified_at;
}
public function setModifiedAt(\DateTimeInterface $modified_at): self
{
$this->modified_at = $modified_at;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeInterface $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getAuthorName(): ?string
{
if($this->author_name) {
return $this->author_name;
}
elseif($this->author) {
return $this->author->getDisplayname();
}
return "";
}
public function setAuthorName(string $author_name = null): self
{
$this->author_name = $author_name ? $author_name : "";
return $this;
}
public function getAuthorEmail(): ?string
{
return $this->author_email;
}
public function setAuthorEmail(string $author_email = null): self
{
$this->author_email = $author_email ? $author_email : "";
return $this;
}
public function getHiddenDescription(): ?string
{
return $this->hidden_description;
}
public function setHiddenDescription(string $hidden_description = null): self
{
$this->hidden_description = $hidden_description ? $hidden_description : "";
return $this;
}
public function getLine(): ?string
{
$text = '';
if ($date = $this->getCreatedAt()) {
$date = $date->format('F j, Y \a\t g:i a ');
$text .= "added on {$date}";
}
if ($author = $this->getAuthorName()) {
$text .= "by {$author}";
}
return $text;
}
public function __toString ()
{
return $this->id ? "" . $this->id : '';
}
}