Ви не можете вибрати більше 25 тем
Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
|
- <?php
-
- namespace Lc\ShopBundle\Services ;
-
- use App\Entity\TicketMessage;
- use Doctrine\ORM\EntityManagerInterface;
- use Lc\ShopBundle\Context\MerchantUtilsInterface;
- use Lc\ShopBundle\Context\OrderShopInterface;
- use Lc\ShopBundle\Context\TicketInterface;
- use Lc\ShopBundle\Context\TicketMessageInterface;
- use Lc\ShopBundle\Model\Ticket;
-
- class TicketUtils
- {
- protected $em ;
- protected $merchantUtils ;
-
- public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils)
- {
- $this->em = $em ;
- $this->merchantUtils = $merchantUtils ;
- }
-
- public function createTicket($params): TicketInterface
- {
- $classTicket = $this->em->getClassMetadata(TicketInterface::class)->getName() ;
- $ticket = new $classTicket ;
- $ticket->setMerchant($this->merchantUtils->getMerchantCurrent()) ;
- $ticket->setStatus(1) ;
-
- if(isset($params['user'])) {
- $ticket->setUser($params['user']) ;
- }
- else {
- $ticket->setVisitorFirstname($params['visitorFirstname']) ;
- $ticket->setVisitorLastname($params['visitorLastname']) ;
- $ticket->setVisitorEmail($params['visitorEmail']) ;
- $ticket->setVisitorToken(uniqid()) ;
- }
-
- $ticket->setTicketStatus(Ticket::TICKET_STATUS_OPEN) ;
- $ticket->setType($params['type']) ;
- if(isset($params['orderShop']) && $params['orderShop'] && $params['orderShop'] instanceof OrderShopInterface) {
- $ticket->setOrderShop($params['orderShop']) ;
- }
- $ticket->setSubject($params['subject']) ;
- $this->em->persist($ticket);
-
- $classTicketMessage = $this->em->getClassMetadata(TicketMessageInterface::class)->getName() ;
- $ticketMessage = new $classTicketMessage ;
- $ticketMessage->setStatus(1) ;
- $ticketMessage->setTicket($ticket) ;
- $ticketMessage->setMessage($params['message']) ;
- $this->em->persist($ticketMessage);
-
- $this->em->flush() ;
-
- return $ticket ;
- }
-
- public function createTicketMessage($params)
- {
- $classTicketMessage = $this->em->getClassMetadata(TicketMessageInterface::class)->getName() ;
- $ticketMessage = new $classTicketMessage ;
-
- $ticket = $params['ticket'] ;
-
- $ticketMessage->setStatus(1) ;
- $ticketMessage->setTicket($ticket) ;
- $ticketMessage->setMessage($params['message']) ;
- $this->em->persist($ticketMessage);
-
- if(isset($params['closeTicket']) && $params['closeTicket']) {
- $ticket->setTicketStatus(Ticket::TICKET_STATUS_CLOSED) ;
- $this->em->persist($ticket);
- }
-
- $this->em->flush() ;
-
- return $ticketMessage ;
- }
- }
|