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->setStatus(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']) ; if(isset($params['answerByAdmin']) && $params['answerByAdmin']) { $ticketMessage->setAnswerByAdmin($params['answerByAdmin']) ; } $this->em->persist($ticketMessage); if(isset($params['closeTicket']) && $params['closeTicket']) { $ticket->setTicketStatus(Ticket::TICKET_STATUS_CLOSED) ; } $ticket->setUpdatedAt(new \DateTime()) ; $this->em->persist($ticket); $this->em->flush() ; return $ticketMessage ; } }