/** * @return Strategy */ public function getStrategy() { if ($this->strategy instanceof Strategy) { return $this->strategy; } $strategyClass = __NAMESPACE__ . '\\' . $this->mapping[$this->user->getType()]; $this->strategy = new $strategyClass(); $this->strategy->setUser($this->user); return $this->strategy; }
/** * @param User $user * * @return DiamanteUser|OroUser */ public function getByUser(User $user) { if ($user->isOroUser()) { $user = $this->oroUserManager->findUserBy(array('id' => $user->getId())); } else { $user = $this->diamanteUserRepository->get($user->getId()); } if (!$user) { throw new \RuntimeException('User loading failed. User not found'); } return $user; }
public function testFetchOroUser() { $id = 'oro_1'; $user = User::fromString($id); $this->userService->expects($this->once())->method('getOroUser')->with($this->equalTo($user))->will($this->returnValue(new \Oro\Bundle\UserBundle\Entity\User())); $this->userDetailsExtension->fetchOroUser($user); }
/** * {@inheritdoc} */ public function reverseTransform($value) { if (filter_var($value, FILTER_VALIDATE_EMAIL)) { return $value; } elseif (preg_match('/^(diamante|oro)_\\d+$/i', $value)) { return User::fromString($value); } else { return null; } }
/** * @test */ public function testConvertItem() { $id = 'diamante_1'; $userObj = User::fromString($id); $userDetails = $this->createUserDetails(User::TYPE_DIAMANTE); $this->userService->expects($this->once())->method('fetchUserDetails')->with($this->equalTo($userObj))->will($this->returnValue($userDetails)); $result = $this->diamanteUserSearchHandler->convertItem($userObj); $this->assertInternalType('array', $result); $this->assertEquals($id, $result['id']); $this->assertEquals(User::TYPE_DIAMANTE, $result['type']); }
/** * @param array $conditions * @param PagingProperties $pagingProperties * @param ApiUser $user * @return \Doctrine\Common\Collections\Collection|static * @throws \Exception */ public function filter(array &$conditions, PagingProperties $pagingProperties, $user = null) { if ('key' == $pagingProperties->getSort()) { $qb = $this->orderByTicketKey($conditions, $pagingProperties); } else { $qb = $this->createFilterQuery($conditions, $pagingProperties); } if ($user instanceof DiamanteUser) { $user = new User($user->getId(), User::TYPE_DIAMANTE); $qb->addSelect('w')->join(self::SELECT_ALIAS . '.watcherList', 'w')->andWhere('w.userType = :watcher')->setParameter('watcher', $user); $conditions[] = ['w', 'userType', 'eq', $user]; } $query = $qb->getQuery(); try { $result = $query->getResult(Query::HYDRATE_OBJECT); } catch (\Exception $e) { $result = null; } return $result; }
/** * @test * @expectedException \RuntimeException * @expectedExceptionMessage User loading failed. User not found */ public function testThrowsExceptionIfUserNotFound() { $userValueObject = new User(1, User::TYPE_DIAMANTE); $this->diamanteUserRepository->expects($this->once())->method('get')->with($this->equalTo($userValueObject->getId()))->will($this->returnValue(null)); $this->diamanteUserService->getByUser($userValueObject); }
/** * Creates Comment for Ticket * * @param $content * @param $authorId * @param $messageId * @param array $attachments * @return Ticket|null */ public function createCommentForTicket($content, $authorId, $messageId, array $attachments = null) { $reference = $this->messageReferenceRepository->getReferenceByMessageId($messageId); if (is_null($reference)) { $this->logger->error(sprintf('Ticket not found for message: %s', $messageId)); throw new \RuntimeException('Ticket loading failed, ticket not found.'); } $ticket = $reference->getTicket(); $author = User::fromString($authorId); if (empty($content)) { return null; } $comment = $this->commentFactory->create($content, $ticket, $author); if ($attachments) { $this->createAttachments($attachments, $comment); } $ticket->postNewComment($comment); $this->ticketRepository->store($ticket); $this->dispatchEvents($ticket); return $ticket; }
/** * @Route( * "/watchers/ticket/{ticketId}", * name="diamante_ticket_watchers", * requirements={"ticketId"="\d+"} * ) * @Template("DiamanteDeskBundle:Ticket:widget/watchers.html.twig") * * @param int $ticketId * @return array */ public function watchers($ticketId) { $ticket = $this->get('diamante.ticket.service')->loadTicket($ticketId); $users = []; foreach ($ticket->getWatcherList() as $watcher) { $users[] = User::fromString($watcher->getUserType()); } return ['watchers' => $users]; }
/** * @param array $conditions * @param PagingProperties $pagingProperties * @param ApiUser|null $user * @return \Doctrine\Common\Collections\Collection|static * @throws \Exception */ public function filter(array &$conditions, PagingProperties $pagingProperties, $user = null) { if ('key' == $pagingProperties->getSort()) { $qb = $this->orderByTicketKey($conditions, $pagingProperties); } else { $qb = $this->createFilterQuery($conditions, $pagingProperties); } if ($user instanceof DiamanteUser) { $user = new User($user->getId(), User::TYPE_DIAMANTE); $qb->andWhere(self::SELECT_ALIAS . '.reporter = :reporter'); $watchedTickets = $this->getWatchedTicketsIds($user); if (!empty($watchedTickets)) { $qb->orWhere($qb->expr()->in('e.id', array_reverse($watchedTickets))); } $qb->setParameter('reporter', $user); $conditions[] = ['w', 'userType', 'eq', $user]; } $query = $qb->getQuery(); try { $result = $query->getResult(Query::HYDRATE_OBJECT); } catch (\Exception $e) { $result = null; } return $result; }
/** * Creates Comment for Ticket * * @param $content * @param $authorId * @param $messageId * @param array|null $attachments * @return Ticket|null */ public function createCommentForTicket($content, $authorId, $messageId, array $attachments = null) { if (empty($content)) { return null; } $reference = $this->messageReferenceRepository->getReferenceByMessageId($messageId); if (is_null($reference)) { $this->logger->error(sprintf('Ticket not found for message: %s', $messageId)); throw new \RuntimeException('Ticket loading failed, ticket not found.'); } $ticket = $reference->getTicket(); $command = new CommentCommand(); $command->ticket = $ticket->getId(); $command->content = $content; $command->author = User::fromString($authorId); $command->ticketStatus = $ticket->getStatus(); $command->attachmentsInput = $this->convertAttachments($attachments); $this->commentService->postNewCommentForTicket($command); return $ticket; }
/** * @Route( * "/watchers/ticket/{ticket}", * name="diamante_ticket_watchers", * requirements={"ticket"="\d+"} * ) * @Template("DiamanteDeskBundle:Ticket:widget/watchers.html.twig") * * @param Ticket $ticket * @return array */ public function watchersAction($ticket) { $ticket = $this->container->get('diamante.ticket.repository')->get($ticket); $users = []; foreach ($ticket->getWatcherList() as $watcher) { $users[] = User::fromString($watcher->getUserType()); } return ['ticket' => $ticket, 'watchers' => $users]; }
/** * @return string */ public function getAuthorType() { return $this->author->getType(); }
/** * @test */ public function testCreatesFromString() { $user = User::fromString(User::TYPE_ORO . User::DELIMITER . self::TEST_ID); $this->assertEquals(User::TYPE_ORO, $user->getType()); $this->assertEquals(self::TEST_ID, $user->getId()); }
/** * @param Notification $notification * @return \ArrayAccess */ private function postProcessChangesList(Notification $notification) { $changes = $notification->getChangeList(); if (isset($changes['Reporter']) && strpos($changes['Reporter'], '_')) { $r = $changes['Reporter']; $u = User::fromString($r); $details = $this->userService->fetchUserDetails($u); $changes['Reporter'] = $details->getFullName(); } return $changes; }
/** * @Route( * "/watcher/ticket/{ticketId}/{user}", * name="diamante_remove_watcher", * requirements={"ticketId"="\d+"} * ) * * @param int $ticketId * @param string $user * @return array|Response */ public function deleteWatcherAction($ticketId, $user) { $repository = $this->getDoctrine()->getManager()->getRepository('DiamanteDeskBundle:Ticket'); $ticket = $repository->get($ticketId); $ticketKey = $ticket->getKey(); try { $user = User::fromString($user); $this->get('diamante.watcher.service.api')->removeWatcher($ticket, $user); $this->addSuccessMessage('diamante.desk.ticket.messages.watcher_remove.success'); $response = $this->redirect($this->generateUrl('diamante_ticket_view', array('key' => $ticketKey))); } catch (TicketNotFoundException $e) { $this->handleException($e); $response = $this->redirect($this->generateUrl('diamante_ticket_list')); } catch (\Exception $e) { $this->handleException($e); $response = $this->redirect($this->generateUrl('diamante_ticket_view', array('key' => $ticketKey))); } return $response; }
/** * Post Comment for Ticket * @param Command\CommentCommand $command * @return \Diamante\DeskBundle\Model\Ticket\Comment */ public function postNewCommentForTicket(Command\CommentCommand $command) { $this->isGranted('CREATE', 'Entity:DiamanteDeskBundle:Comment'); \Assert\that($command->attachmentsInput)->nullOr()->all()->isInstanceOf('Diamante\\DeskBundle\\Api\\Dto\\AttachmentInput'); /** * @var $ticket \Diamante\DeskBundle\Model\Ticket\Ticket */ $ticket = $this->loadTicketBy($command->ticket); $author = User::fromString($command->author); $comment = $this->commentFactory->create($command->content, $ticket, $author, $command->private); if ($command->attachmentsInput) { foreach ($command->attachmentsInput as $each) { $this->attachmentManager->createNewAttachment($each->getFilename(), $each->getContent(), $comment); } } $ticket->updateStatus(new Status($command->ticketStatus)); $ticket->postNewComment($comment); $this->ticketRepository->store($ticket); $this->dispatchEvents($comment, $ticket); return $comment; }
/** * Post Comment for Ticket * @param Command\CommentCommand $command * @return Comment * * @throws ForbiddenException * @throws TicketNotFoundException */ public function postNewCommentForTicket(Command\CommentCommand $command) { $this->isGranted('CREATE', 'Entity:DiamanteDeskBundle:Comment'); \Assert\that($command->attachmentsInput)->nullOr()->all()->isInstanceOf('Diamante\\DeskBundle\\Api\\Dto\\AttachmentInput'); /** * @var $ticket \Diamante\DeskBundle\Model\Ticket\Ticket */ $ticket = $this->loadTicketBy($command->ticket); $author = User::fromString($command->author); $comment = $this->commentFactory->create($command->content, $ticket, $author, $command->private); $this->createAttachments($command, $comment); $ticket->updateStatus(new Status($command->ticketStatus)); $ticket->updatedTimestamps(); $ticket->postNewComment($comment); $this->ticketRepository->store($ticket); $this->dispatchWorkflowEvent($this->registry, $this->dispatcher, $comment); return $comment; }
/** * @param string $id * @return $this */ public function setReporter($id) { $reporter = User::fromString($id); $this->reporter = $reporter; return $this; }
/** * @param User $user * @return bool */ public function isDiamanteUserDeleted(User $user) { if (!$user->isDiamanteUser()) { return false; } $diamanteUser = $this->userService->getDiamanteUser($user); return $diamanteUser->isDeleted(); }
/** * Delete Watcher from ticket * * @ApiDoc( * description="Delete watcher", * uri="/tickets/{id}/watchers/{userId}.{_format}", * method="DELETE", * resource=true, * requirements={ * { * "name"="id", * "dataType"="integer", * "requirement"="\d+", * "description"="Ticket Id" * }, * { * "name"="userId", * "dataType"="string", * "description"="User id" * } * }, * statusCodes={ * 201="Returned when successful", * 403="Returned when the user is not authorized", * 404="Returned when the ticket not found" * } * ) * * @param Command\RemoveWatcherCommand $command * @return null */ public function removeWatcherById(Command\RemoveWatcherCommand $command) { $ticket = $this->getTicket($command); /** @var WatcherList $watcher */ foreach ($ticket->getWatcherList() as $watcher) { if ($watcher->getUserType() == $command->userId) { $user = User::fromString($command->userId); $this->removeWatcher($ticket, $user); break; } } }
/** * @return string */ public function getReporterId() { return $this->reporter->getId(); }
/** * @param Ticket $ticket */ protected function startAutoReply(Ticket $ticket) { $ticketText = $ticket->getSubject() . ' ' . $ticket->getDescription(); $repository = $this->registry->getManager()->getRepository('DiamanteDeskBundle:Article'); $results = []; /** @var Article $article */ foreach ($repository->findByStatus(1) as $article) { $articleText = $article->getTitle() . ' ' . $article->getContent(); $results[$article->getId()] = $this->compare($ticketText, $articleText); } $maxResult = max($results); /** * TODO: should be configured by admin */ if ($maxResult < 3) { return; } $articleId = array_search(max($results), $results); /** * TODO: should be extracted from previous call of $repository->getAll() */ $article = $repository->find($articleId); /** * TODO: should be extracted from configuration??? */ $user = User::fromString('oro_1'); $content = $this->getAutoReplayNoticeHtml() . $article->getContent(); $comment = new Comment($content, $ticket, $user, false); $this->registry->getManager()->persist($comment); $this->uow->computeChangeSet($this->em->getClassMetadata($comment->getClassName()), $comment); /** * TODO: should be executed workflowEven? */ }