/**
  * Get email which was specified in TO field, when ticket was created via EmailProcessing
  *
  * @param Ticket $ticket
  * @return array|null
  */
 public function getEndpointByTicket(Ticket $ticket)
 {
     $qb = $this->_em->createQueryBuilder();
     $qb->select("r.endpoint")->from($this->_entityName, 'r')->where($qb->expr()->eq('r.ticket', $ticket->getId()))->setMaxResults(1);
     try {
         $result = $qb->getQuery()->getResult(Query::HYDRATE_SINGLE_SCALAR);
     } catch (\Exception $e) {
         $result = null;
     }
     return $result;
 }
 /**
  * @param Ticket $ticket
  * @param AbstractTicketEvent $event
  * @return array
  */
 private function getMemberList(Ticket $ticket, AbstractTicketEvent $event)
 {
     $members = [];
     if ($ticket->getAssignee()) {
         $members[] = new User($ticket->getAssignee()->getId(), User::TYPE_ORO);
     }
     if ($event->getEventName() == 'ticketAssigneeWasChanged') {
         return $members;
     }
     $members[] = $ticket->getReporter();
     return $members;
 }
 /**
  * @ORM\PrePersist
  * @ORM\PreUpdate
  * @param Ticket $ticket
  * @param LifecycleEventArgs $event
  */
 public function prePersistHandler(Ticket $ticket, LifecycleEventArgs $event)
 {
     if ($ticket->getSequenceNumber()->getValue()) {
         return;
     }
     $em = $event->getEntityManager();
     $query = $em->createQuery("SELECT MAX(t.sequenceNumber) FROM DiamanteDeskBundle:Ticket t WHERE t.branch = :branchId")->setParameter('branchId', $ticket->getBranch()->getId());
     $ticketSequenceNumberValue = $query->getSingleScalarResult();
     $ticketSequenceNumberValue++;
     $ticketSequenceNumber = $ticket->getSequenceNumber();
     $ref = new \ReflectionClass($ticketSequenceNumber);
     $property = $ref->getProperty(self::TICKET_SEQUENCE_NUMBER_FIELD_TO_UPDATE);
     $property->setAccessible(true);
     $property->setValue($ticketSequenceNumber, $ticketSequenceNumberValue);
     $property->setAccessible(false);
 }
Ejemplo n.º 4
0
 public function testCreateWhenAssigneeIsNull()
 {
     $branch = $this->createBranch();
     $reporter = $this->createReporter();
     $ticket = new Ticket(new UniqueId('unique_id'), new TicketSequenceNumber(null), self::TICKET_SUBJECT, self::TICKET_DESCRIPTION, $branch, $reporter, null, new Source(Source::PHONE), new Priority(Priority::PRIORITY_LOW), new Status(Status::NEW_ONE));
     $this->assertEquals('Subject', $ticket->getSubject());
     $this->assertEquals('Description', $ticket->getDescription());
     $this->assertEquals($branch, $ticket->getBranch());
     $this->assertEquals('new', $ticket->getStatus()->getValue());
     $this->assertEquals($reporter, $ticket->getReporter());
     $this->assertNull($ticket->getAssignee());
     $this->assertEquals(Source::PHONE, $ticket->getSource()->getValue());
 }
 /**
  * @test
  */
 public function thatTicketCreatesWithAttachments()
 {
     $branchId = 1;
     $assigneeId = 3;
     $reporter = $this->createReporter();
     $this->ticketBuilder->expects($this->once())->method('setSubject')->with(self::SUBJECT)->will($this->returnValue($this->ticketBuilder));
     $this->ticketBuilder->expects($this->once())->method('setDescription')->with(self::DESCRIPTION)->will($this->returnValue($this->ticketBuilder));
     $this->ticketBuilder->expects($this->once())->method('setBranchId')->with($branchId)->will($this->returnValue($this->ticketBuilder));
     $this->ticketBuilder->expects($this->once())->method('setReporter')->with((string) $reporter)->will($this->returnValue($this->ticketBuilder));
     $this->ticketBuilder->expects($this->once())->method('setAssigneeId')->with($assigneeId)->will($this->returnValue($this->ticketBuilder));
     $this->ticketBuilder->expects($this->once())->method('setSource')->with(Source::EMAIL)->will($this->returnValue($this->ticketBuilder));
     $this->ticketBuilder->expects($this->once())->method('build')->will($this->returnValue($this->ticket));
     $this->attachmentManager->expects($this->once())->method('createNewAttachment')->with($this->equalTo(self::DUMMY_FILENAME), $this->equalTo(self::DUMMY_FILE_CONTENT), $this->equalTo($this->ticket));
     $this->ticketRepository->expects($this->once())->method('store')->with($this->equalTo($this->ticket));
     $messageReference = new MessageReference(self::DUMMY_MESSAGE_ID, $this->ticket);
     $this->messageReferenceRepository->expects($this->once())->method('store')->with($this->equalTo($messageReference));
     $this->ticket->expects($this->atLeastOnce())->method('getRecordedEvents')->will($this->returnValue(array()));
     $this->messageReferenceService->createTicket(self::DUMMY_MESSAGE_ID, $branchId, self::SUBJECT, self::DESCRIPTION, $reporter, $assigneeId, $this->attachments());
 }
 /**
  * @param Ticket $ticket
  * @return array
  */
 private function getSuccessSaveResponse(Ticket $ticket)
 {
     return $this->get('oro_ui.router')->redirectAfterSave(['route' => 'diamante_ticket_update', 'parameters' => ['key' => (string) $ticket->getKey()]], ['route' => 'diamante_ticket_view', 'parameters' => ['key' => (string) $ticket->getKey()]]);
 }
 /**
  * @param Ticket $ticket
  * @param $command
  */
 protected function updateTicketStatus(Ticket $ticket, $command)
 {
     $status = new Status($command->ticketStatus);
     if (false === $ticket->getStatus()->equals($status)) {
         $ticket->updateStatus($status);
         $this->registry->getManager()->persist($ticket);
     }
 }
 /**
  * @param Ticket $ticket
  * @param User $user
  * @return null|object
  */
 public function findOne(Ticket $ticket, User $user)
 {
     return $this->findOneBy(['userType' => $user, 'ticket' => $ticket->getId()]);
 }
 /**
  * @param Ticket $ticket
  */
 private function removePrivateComments(Ticket $ticket)
 {
     $user = $this->authorizationService->getLoggedUser();
     if (!$user instanceof ApiUser) {
         return;
     }
     $comments = $ticket->getComments();
     foreach ($comments as $comment) {
         if ($comment->isPrivate()) {
             $comments->removeElement($comment);
         }
     }
 }
Ejemplo n.º 10
0
 public function delete()
 {
     $this->raise(new CommentWasDeleted($this->ticket->getUniqueId(), $this->ticket->getSubject(), $this->content, $this->private));
 }
 public static function create(Branch $branch, Ticket $ticket)
 {
     return new TicketKey($branch->getKey(), $ticket->getSequenceNumber()->getValue());
 }
 /**
  * Return watchers list
  *
  * @param Ticket $ticket
  *
  * @return array
  */
 public function getWatchers(Ticket $ticket)
 {
     return $ticket->getWatcherList()->getValues();
 }
 /**
  * @param Comment $comment
  * @param Ticket $ticket
  */
 private function dispatchEvents(Comment $comment, Ticket $ticket = null)
 {
     foreach ($comment->getRecordedEvents() as $event) {
         $this->dispatcher->dispatch($event->getEventName(), $event);
     }
     if ($ticket) {
         foreach ($ticket->getRecordedEvents() as $event) {
             $this->dispatcher->dispatch($event->getEventName(), $event);
         }
     }
     $this->notificationDeliveryManager->deliver($this->notifier);
 }
 /**
  * @param Ticket $ticket
  * @return UpdateStatusCommand
  */
 public function createUpdateStatusCommandForView(Ticket $ticket)
 {
     $command = new UpdateStatusCommand();
     $command->ticketId = $ticket->getId();
     $command->status = $ticket->getStatus();
     return $command;
 }
 /**
  * @test
  * @expectedException \RuntimeException
  * @expectedExceptionMessage Attachment loading failed. Ticket has no such attachment.
  */
 public function thatAttachmentRemovingThrowsExceptionWhenTicketHasNoAttachment()
 {
     $ticket = new Ticket(new UniqueId('unique_id'), new TicketSequenceNumber(12), self::SUBJECT, self::DESCRIPTION, $this->createBranch(), $this->createReporter(), $this->createAssignee(), new Source(Source::PHONE), new Priority(Priority::PRIORITY_LOW), new Status(Status::CLOSED));
     $ticket->addAttachment($this->attachment());
     $this->ticketRepository->expects($this->once())->method('get')->with($this->equalTo(self::DUMMY_TICKET_ID))->will($this->returnValue($ticket));
     $this->authorizationService->expects($this->once())->method('isActionPermitted')->with($this->equalTo('EDIT'), $this->equalTo($ticket))->will($this->returnValue(true));
     $removeTicketAttachmentCommand = new RemoveTicketAttachmentCommand();
     $removeTicketAttachmentCommand->ticketId = self::DUMMY_TICKET_ID;
     $removeTicketAttachmentCommand->attachmentId = self::DUMMY_ATTACHMENT_ID;
     $this->ticketService->removeAttachmentFromTicket($removeTicketAttachmentCommand);
 }
 /**
  * @param Notification $notification
  * @param Ticket $ticket
  *
  * @return string
  */
 private function getFormattedUserName(Notification $notification, Ticket $ticket)
 {
     $author = $notification->getAuthor();
     if (is_null($author)) {
         $reporterId = $ticket->getReporter()->getId();
         $user = $this->diamanteUserRepository->get($reporterId);
     } else {
         $user = $this->getUserDependingOnType($author);
     }
     $name = $this->nameFormatter->format($user);
     if (empty($name)) {
         $format = $this->nameFormatter->getNameFormat();
         $name = str_replace(array('%first_name%', '%last_name%', '%prefix%', '%middle_name%', '%suffix%'), array($user->getFirstName(), $user->getLastName(), '', '', ''), $format);
     }
     $name = preg_replace('/\\s+/', ' ', $name);
     return trim($name);
 }
 /**
  * @param Ticket $ticket
  */
 private function removePrivateComments(Ticket $ticket)
 {
     $user = $this->authorizationService->getLoggedUser();
     if (!$user instanceof ApiUser) {
         return;
     }
     $comments = $ticket->getComments();
     $commentsList = $comments->toArray();
     $comments->clear();
     foreach ($commentsList as $comment) {
         if (!$comment->isPrivate()) {
             $comments->add($comment);
         }
     }
     $comments->takeSnapshot();
 }