<?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;
use MedBrief\MSR\Traits\FilterableClassConstantsTrait;
/**
* MatterCommunication
*
* @ORM\Table(name="MatterCommunication")
*
* @ORM\Entity
*
* @ORM\HasLifecycleCallbacks
*
* @Audit\Auditable
*
* @Audit\Security(view={"ROLE_ALLOWED_TO_AUDIT"})
*/
class MatterCommunication
{
use FilterableClassConstantsTrait;
// Label constants
public const LABEL_IMPORTANT = 'important';
public const LABEL_IMPORTANT__LABEL = 'Important';
public const LABEL_INSTRUCTION = 'instruction';
public const LABEL_INSTRUCTION__LABEL = 'Instruction';
public const LABEL_INITIAL_INSTRUCTION = 'initial_instruction';
public const LABEL_INITIAL_INSTRUCTION__LABEL = 'Initial Instruction';
public const LABEL_ISSUE = 'issue';
public const LABEL_ISSUE__LABEL = 'Issue';
public const LABEL_FEEDBACK = 'feedback';
public const LABEL_FEEDBACK__LABEL = 'Feedback';
public const LABEL_COMPLAINT = 'complaint';
public const LABEL_COMPLAINT__LABEL = 'Complaint';
public const LABEL_ACTION_REQUIRED = 'action_required';
public const LABEL_ACTION_REQUIRED__LABEL = 'Action Required';
public const LABEL_COMPLETE = 'complete';
public const LABEL_COMPLETE__LABEL = 'Complete';
public const LABEL_RELEASE = 'release';
public const LABEL_RELEASE__LABEL = 'Release';
public const LABEL_NOTIFICATION = 'notification';
public const LABEL_NOTIFICATION__LABEL = 'Notification';
public const LABEL_EXPERT = 'expert';
public const LABEL_EXPERT__LABEL = 'Expert';
public const LABEL_INTERNAL = 'internal';
public const LABEL_INTERNAL__LABEL = 'Internal';
public const LABEL_REDACTION = 'redaction';
public const LABEL_REDACTION__LABEL = 'Redaction';
public const LABEL_AMENDMENT = 'amendment';
public const LABEL_AMENDMENT__LABEL = 'Amendment';
// Send receive Constants
public const TYPE_SENT = true;
public const TYPE_SENT__LABEL = 'Sent';
public const TYPE_RECEIVED = false;
public const TYPE_RECEIVED__LABEL = 'Received';
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
*
* @ORM\Id
*
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var array|null
*
* @ORM\Column(name="labels", type="array", nullable=true)
*/
private $labels;
/**
* @var string|null
*
* @ORM\Column(name="content", type="text", nullable=true)
*/
private $content;
/**
* @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;
/**
* The search index used for filtering.
*
* @var string|null
*
* @ORM\Column(name="search_index", type="text", nullable=true)
*/
private $search_index;
/**
* @var bool|null
*
* @ORM\Column(name="isSentEmail", type="boolean", nullable=true)
*/
private $isSentEmail;
/**
* @var Email
*
* @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\Email", cascade={"persist","remove"}, orphanRemoval=true)
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="email_id", referencedColumnName="id", unique=true, nullable=true)
* })
*/
private $email;
/**
* @var Project
*
* @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\Project", inversedBy="matterCommunications")
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="project_id", referencedColumnName="id", nullable=true)
* })
*/
private $project;
/**
* Constructor
*/
public function __construct()
{
$this->labels = [];
$this->isSentEmail = self::TYPE_RECEIVED;
}
/**
* __toString
*
* @return string
*/
public function __toString()
{
return (string) $this->getId() ?: 'Unknown';
}
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set labels.
*
* @param array|null $labels
*
* @return MatterCommunication
*/
public function setLabels($labels = null)
{
$this->labels = $labels;
return $this;
}
/**
* Add Label to labels array
*
* @param MatterCommunication $label
*
* @return MatterCommunication
*/
public function addLabels(MatterCommunication $label)
{
$this->labels = $label;
return $this;
}
/**
* Remove Label to labels array
*
* @param MatterCommunication $label
*
* @return void
*/
public function removeLabels(MatterCommunication $label): void
{
$this->labels = $label;
}
/**
* Get labels.
*
* @return array|null
*/
public function getLabels()
{
return $this->labels;
}
/**
* Returns an array of permitted values for the Labels field.
*
* @return array
*/
public static function getLabelOptions()
{
$typeOptions = self::getConstantsWithLabelsAsChoices('LABEL');
return $typeOptions;
}
/**
* Returns an array of Labels to be readable by humans.
*
* @return array
*/
public function getLabelLabels()
{
$labelOptions = array_flip(self::getLabelOptions());
return array_map(function ($label) use ($labelOptions) {
return $labelOptions[$label] ?: 'Unknown';
}, $this->labels);
}
/**
* Set content.
*
* @param string|null $content
*
* @return MatterCommunication
*/
public function setContent($content = null)
{
$this->content = $content;
return $this;
}
/**
* Get content.
*
* @return string|null
*/
public function getContent()
{
return $this->content;
}
/**
* Set created.
*
* @param \DateTime $created
*
* @return MatterCommunication
*/
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 MatterCommunication
*/
public function setUpdated($updated)
{
$this->updated = $updated;
return $this;
}
/**
* Get updated.
*
* @return \DateTime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* Set searchIndex
*
* @param string $searchIndex
*
* @return MatterCommunication
*/
public function setSearchIndex($searchIndex)
{
$this->search_index = $searchIndex;
return $this;
}
/**
* Get searchIndex
*
* @return string
*/
public function getSearchIndex()
{
return $this->search_index;
}
/**
* Updates the Search Index field with internal data. The Search Index Field
* provides an easy way to perform a 'like' query for a generalised search.
*
* @ORM\PrePersist
*
* @ORM\PreUpdate
*/
public function updateSearchIndex()
{
$date = $this->getEmail()->getDateSent()->format('d.m.Y');
$searchIndex
= $this->getEmail()->getSender()
. ' '
. $this->getEmail()->getRecipients()
. ' '
. $this->getEmail()->getSubject()
. ' '
. $date;
$this->setSearchIndex($searchIndex);
}
/**
* Set email.
*
* @param Email|null $email
*
* @return MatterCommunication
*/
public function setEmail(?Email $email = null)
{
$this->email = $email;
return $this;
}
/**
* Get email.
*
* @return Email|null
*/
public function getEmail()
{
return $this->email;
}
/**
* Set project.
*
* @param Project|null $project
*
* @return MatterCommunication
*/
public function setProject(?Project $project = null)
{
$this->project = $project;
return $this;
}
/**
* Get project.
*
* @return Project|null
*/
public function getProject()
{
return $this->project;
}
/**
* Set isSentEmail.
*
* @param bool|null $isSentEmail
*
* @return MatterCommunication
*/
public function setIsSentEmail($isSentEmail = null)
{
$this->isSentEmail = $isSentEmail;
return $this;
}
/**
* Get isSentEmail.
*
* @return bool|null
*/
public function getIsSentEmail()
{
return $this->isSentEmail;
}
/**
* Returns an array of permitted values for the isSentEmail field and their
* associated labels.
*
* @return array
*/
public static function getIsSentEmailOptions()
{
$typeOptions = self::getConstantsWithLabelsAsChoices('TYPE');
return $typeOptions;
}
/**
* Returns a human readable version of the type isSentEmailLabel
*
* @return string
*/
public function getIsSentEmailLabel()
{
$options = array_flip(self::getIsSentEmailOptions());
return $options[$this->getIsSentEmail()] ?? '';
}
}