|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- <?php
-
- namespace Lc\SovBundle\Model\Ticket;
-
- use Doctrine\Common\Collections\ArrayCollection;
- use Doctrine\Common\Collections\Collection;
- use Doctrine\ORM\Mapping as ORM;
- use Gedmo\Mapping\Annotation as Gedmo;
- use Lc\SovBundle\Doctrine\EntityInterface;
- use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity;
- use Lc\SovBundle\Model\User\UserInterface;
-
- /**
- * @ORM\MappedSuperclass()
- */
- abstract class TicketModel extends AbstractLightEntity implements TicketInterface, EntityInterface
- {
- const TYPE_TECHNICAL_PROBLEM = 'technical-problem';
- const TYPE_GENERAL_QUESTION = 'general-question';
-
- const TICKET_STATUS_OPEN = 'open';
- const TICKET_STATUS_BEING_PROCESSED = 'being-processed';
- const TICKET_STATUS_CLOSED = 'closed';
-
- /**
- * @Gedmo\Blameable(on="create")
- * @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface")
- * @ORM\JoinColumn(nullable=true)
- */
- protected $createdBy;
-
- /**
- * @Gedmo\Blameable(on="update")
- * @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface")
- * @ORM\JoinColumn(nullable=true)
- */
- protected $updatedBy;
-
- /**
- * @ORM\Column(type="string", length=32)
- */
- protected $type;
-
- /**
- * @ORM\Column(type="string", length=32)
- */
- protected $status;
-
- /**
- * @ORM\Column(type="string", length=255)
- */
- protected $subject;
-
- /**
- * @ORM\Column(type="array", nullable=true)
- */
- protected $tags = [];
-
- /**
- * @ORM\Column(type="string", length=64, nullable=true)
- */
- protected $visitorFirstname;
-
- /**
- * @ORM\Column(type="string", length=64, nullable=true)
- */
- protected $visitorLastname;
-
- /**
- * @ORM\Column(type="string", length=128, nullable=true)
- */
- protected $visitorEmail;
-
- /**
- * @ORM\Column(type="string", length=255, nullable=true)
- */
- protected $visitorToken;
-
- /**
- * @ORM\OneToMany(targetEntity="Lc\SovBundle\Model\Ticket\TicketMessageInterface", mappedBy="ticket", orphanRemoval=true, cascade={"persist", "remove"})
- * @ORM\OrderBy({"id" = "ASC"})
- */
- protected $ticketMessages;
-
- /**
- * @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface", inversedBy="tickets")
- */
- protected $user;
-
- public function __construct()
- {
- $this->ticketMessages = new ArrayCollection();
- }
-
- public function getUsername()
- {
- if ($this->getUser()) {
- return $this->getUser()->getName();
- } else {
- return strtoupper($this->getVisitorLastname()) . ' ' . $this->getVisitorFirstname();
- }
- }
-
- public function getUserInfosTicket()
- {
- $user = $this->getUser();
- if ($user) {
- return '#' . $user->getId() . ' ' . $user->getName() . ' ' . $user->getEmail();
- } else {
- return strtoupper($this->getVisitorLastname()) . ' ' . $this->getVisitorFirstname(
- ) . ' ' . $this->getVisitorEmail();
- }
- }
-
- public function getEmail()
- {
- if ($this->getUser()) {
- return $this->getUser()->getEmail();
- } else {
- return $this->getVisitorEmail();
- }
- }
-
- public function getVisitorInfos()
- {
- return strtoupper($this->getVisitorLastname()) . ' ' . $this->getVisitorFirstname(
- ) . ' (' . $this->getVisitorEmail() . ')';
- }
-
- public function getLastMessage()
- {
- return $this->getTicketMessages()->last();
- }
-
- public function getType(): ?string
- {
- return $this->type;
- }
-
- public function setType(string $type): self
- {
- $this->type = $type;
-
- return $this;
- }
-
- public function getTypeLabel(): string
- {
- return 'entity.Ticket.fields.typeOptions.' . $this->getType();
- }
-
- public function getChoicesType(): array
- {
- return [
- 'entity.Ticket.fields.typeOptions.' . TicketModel::TYPE_GENERAL_QUESTION => TicketModel::TYPE_GENERAL_QUESTION,
- 'entity.Ticket.fields.typeOptions.' . TicketModel::TYPE_TECHNICAL_PROBLEM => TicketModel::TYPE_TECHNICAL_PROBLEM,
- ];
- }
-
- public function getStatus(): ?string
- {
- return $this->status;
- }
-
- public function setStatus(string $status): self
- {
- $this->status = $status;
-
- return $this;
- }
-
- public function getStatusLabel(): string
- {
- return 'entity.Ticket.statusOptions.' . $this->getStatus();
- }
-
- public function getChoicesStatus(): array
- {
- return [
- 'entity.Ticket.fields.statusOptions.' . TicketModel::TICKET_STATUS_OPEN => TicketModel::TICKET_STATUS_OPEN,
- 'entity.Ticket.fields.statusOptions.' . TicketModel::TICKET_STATUS_BEING_PROCESSED => TicketModel::TICKET_STATUS_BEING_PROCESSED,
- 'entity.Ticket.fields.statusOptions.' . TicketModel::TICKET_STATUS_CLOSED => TicketModel::TICKET_STATUS_CLOSED,
- ];
- }
-
- public function getSubject(): ?string
- {
- return $this->subject;
- }
-
- public function setSubject(string $subject): self
- {
- $this->subject = $subject;
-
- return $this;
- }
-
- public function getTags(): ?array
- {
- return $this->tags;
- }
-
- public function setTags(?array $tags): self
- {
- $this->tags = $tags;
-
- return $this;
- }
-
- public function getVisitorFirstname(): ?string
- {
- return $this->visitorFirstname;
- }
-
- public function setVisitorFirstname(?string $visitorFirstname): self
- {
- $this->visitorFirstname = $visitorFirstname;
-
- return $this;
- }
-
- public function getVisitorLastname(): ?string
- {
- return $this->visitorLastname;
- }
-
- public function setVisitorLastname(?string $visitorLastname): self
- {
- $this->visitorLastname = $visitorLastname;
-
- return $this;
- }
-
- public function getVisitorEmail(): ?string
- {
- return $this->visitorEmail;
- }
-
- public function setVisitorEmail(?string $visitorEmail): self
- {
- $this->visitorEmail = $visitorEmail;
-
- return $this;
- }
-
- public function getVisitorToken(): ?string
- {
- return $this->visitorToken;
- }
-
- public function setVisitorToken(?string $visitorToken): self
- {
- $this->visitorToken = $visitorToken;
-
- return $this;
- }
-
- /**
- * @return Collection|TicketMessageInterface[]
- */
- public function getTicketMessages(): Collection
- {
- return $this->ticketMessages;
- }
-
- public function addTicketMessage(TicketMessageInterface $ticketMessage): self
- {
- if (!$this->ticketMessages->contains($ticketMessage)) {
- $this->ticketMessages[] = $ticketMessage;
- $ticketMessage->setTicket($this);
- }
-
- return $this;
- }
-
- public function removeTicketMessage(TicketMessageInterface $ticketMessage): self
- {
- if ($this->ticketMessages->contains($ticketMessage)) {
- $this->ticketMessages->removeElement($ticketMessage);
- // set the owning side to null (unless already changed)
- if ($ticketMessage->getTicket() === $this) {
- $ticketMessage->setTicket(null);
- }
- }
-
- return $this;
- }
-
- public function getUser(): ?UserInterface
- {
- return $this->user;
- }
-
- public function setUser(?UserInterface $user): self
- {
- $this->user = $user;
-
- return $this;
- }
- }
|