<?php
namespace MedBrief\MSR\Entity;
use DH\Auditor\Provider\Doctrine\Auditing\Annotation as Audit;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* SortingInstruction
*
* @ORM\Table(name="SortingInstruction")
*
* @ORM\Entity
*
* @Audit\Auditable
*
* @Audit\Security(view={"ROLE_ALLOWED_TO_AUDIT"})
*/
class SortingInstruction
{
// Type constants
public const TYPE_SILVER = 1;
public const TYPE_GOLD = 2;
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
*
* @ORM\Id
*
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var \DateTime
*
* @ORM\Column(name="created", type="datetime")
*
* @Gedmo\Timestampable(on="create")
*/
private $created;
/**
* @var \DateTime
*
* @ORM\Column(name="updated", type="datetime")
*
* @Gedmo\Timestampable(on="update")
*/
private $updated;
/**
* @var int|null
*
* @ORM\Column(name="type", type="integer", nullable=true)
*/
private $type;
/**
* @var string|null
*
* @ORM\Column(name="description", type="text", nullable=true)
*/
private $description;
/**
* @var Account
*
* @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\Account", mappedBy="defaultSortingInstruction")
*/
private $account;
/**
* __toString
*
* @return string
*/
public function __toString()
{
return sprintf('%1$s Sorting Instruction', $this->getAccount() ? $this->getAccount()->getName() : '');
}
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set created.
*
* @param \DateTime $created
*
* @return SortingInstruction
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
/**
* Get created.
*
* @return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set updated.
*
* @param \DateTime $updated
*
* @return SortingInstruction
*/
public function setUpdated($updated)
{
$this->updated = $updated;
return $this;
}
/**
* Get updated.
*
* @return \DateTime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* Set type.
*
* @param int|null $type
*
* @return SortingInstruction
*/
public function setType($type = null)
{
$this->type = $type;
return $this;
}
/**
* Get type.
*
* @return int|null
*/
public function getType()
{
return $this->type;
}
/**
* Get typeOptions
*
* @return array
*/
public static function getTypeOptions()
{
return [
self::TYPE_SILVER => 'Silver Sort',
self::TYPE_GOLD => 'Gold Sort',
];
}
/**
* Get typeLabel
*
* @return string
*/
public function getTypeLabel()
{
$options = self::getTypeOptions();
return $options[$this->getType()] ?? '';
}
/**
* Set description.
*
* @param string|null $description
*
* @return SortingInstruction
*/
public function setDescription($description = null)
{
$this->description = $description;
return $this;
}
/**
* Get description.
*
* @return string|null
*/
public function getDescription()
{
return $this->description;
}
/**
* Set account.
*
* @param Account|null $account
*
* @return SortingInstruction
*/
public function setAccount(?Account $account = null)
{
if ($this->account && !$account) {
$this->account->setDefaultSortingInstruction(null);
} elseif ($account) {
$account->setDefaultSortingInstruction($this);
}
$this->account = $account;
return $this;
}
/**
* Get account.
*
* @return Account|null
*/
public function getAccount()
{
return $this->account;
}
}