Пример #1
0
 protected function getTagsForEntityClass($entityClass, array $ids)
 {
     return array_reduce($this->tagManager->getTagsByEntityIds($entityClass, $ids), function ($tags, $item) {
         $tags[$item['entityId']][] = $item;
         return $tags;
     }, []);
 }
Пример #2
0
 /**
  * Transform submitted data to model data
  *
  * @param FormEvent $event
  */
 public function preSubmit(FormEvent $event)
 {
     $values = $event->getData();
     $entities = array('all' => array(), 'owner' => array());
     foreach (array_keys($entities) as $type) {
         if (isset($values[$type]) && !empty($values[$type])) {
             try {
                 if (!is_array($values[$type])) {
                     $values[$type] = json_decode($values[$type]);
                 }
                 $names[$type] = array();
                 foreach ($values[$type] as $value) {
                     if (!empty($value->name)) {
                         // new tag
                         $names[$type][] = $value->name;
                     }
                 }
                 $entities[$type] = $this->manager->loadOrCreateTags($names[$type]);
             } catch (\Exception $e) {
                 $entities[$type] = array();
             }
         }
     }
     $event->setData($entities);
 }
 /**
  * @param $tickets
  * @param TagManager $tagManager
  * @return mixed
  */
 public function afterResult($tickets, $tagManager)
 {
     foreach ($tickets as $ticket) {
         /** @var Ticket $ticket */
         $tagManager->loadTagging($ticket);
     }
     return $tickets;
 }
Пример #4
0
 public function testAfterMergeEntity()
 {
     $this->entityData->expects($this->any())->method('getMasterEntity')->will($this->returnValue($this->createTaggableEntity('foo')));
     $event = new EntityDataEvent($this->entityData);
     $this->manager->expects($this->once())->method('saveTagging');
     $this->helper->expects($this->once())->method('isTaggable')->willReturn(true);
     $this->listener->afterMergeEntity($event);
 }
Пример #5
0
 /**
  * @param MailboxSaved $event
  */
 public function onMailboxSave(MailboxSaved $event)
 {
     $processSetings = $event->getMailbox()->getProcessSettings();
     if (!$processSetings instanceof CaseMailboxProcessSettings) {
         return;
     }
     $this->tagManager->saveTagging($processSetings);
 }
Пример #6
0
 protected function onSuccess(User $user)
 {
     $this->manager->updateUser($user);
     $this->tagManager->saveTagging($user);
     // Reloads the user to reset its username. This is needed when the
     // username or password have been changed to avoid issues with the
     // security layer.
     $this->manager->reloadUser($user);
 }
Пример #7
0
 /**
  * "Success" form handler
  *
  * @param Contact $entity
  * @param array $appendAccounts
  * @param array $removeAccounts
  */
 protected function onSuccess(Contact $entity, array $appendAccounts, array $removeAccounts)
 {
     $this->appendAccounts($entity, $appendAccounts);
     $this->removeAccounts($entity, $removeAccounts);
     $this->manager->persist($entity);
     $this->setUpdatedAt($entity);
     $this->manager->flush();
     $this->tagManager->saveTagging($entity);
 }
Пример #8
0
 /**
  * {@inheritdoc}
  */
 protected function onSuccess($entity)
 {
     $this->entityManager->persist($entity);
     $this->dispatcher->dispatch(Events::BEFORE_SAVE, new FormHandlerEvent($this->form, $entity));
     $this->entityManager->flush();
     if ($this->tagManager) {
         $this->tagManager->saveTagging($entity);
     }
 }
Пример #9
0
 /**
  * @param LifecycleEventArgs $args
  */
 public function preRemove(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if ($this->taggableHelper->isTaggable($entity)) {
         if (null === $this->tagManager && $this->container) {
             $this->tagManager = $this->container->get('oro_tag.tag.manager');
         }
         $this->tagManager->deleteTagging($entity, []);
     }
 }
Пример #10
0
 /**
  * Save tags
  *
  * @param EntityDataEvent $event
  */
 public function afterMergeEntity(EntityDataEvent $event)
 {
     $entityData = $event->getEntityData();
     $entityMetadata = $entityData->getMetadata();
     if (!$this->isTaggable($entityMetadata)) {
         return;
     }
     $entity = $entityData->getMasterEntity();
     $this->tagManager->saveTagging($entity);
 }
Пример #11
0
 /**
  * {@inheritdoc}
  */
 protected function executeAction($context)
 {
     $source = $this->getTaggable($context, static::PATH_SOURCE);
     $destination = $this->getTaggable($context, static::PATH_DESTINATION);
     $organization = $this->getOrganization($context);
     $this->tagManager->loadTagging($source, $organization);
     $tags = $this->tagManager->getTags($source);
     $this->tagManager->setTags($destination, $tags);
     $this->tagManager->saveTagging($destination, true, $organization);
 }
Пример #12
0
 /**
  * {@inheritdoc}
  */
 protected function executeAction($context)
 {
     $source = $this->getObject($context, static::PATH_SOURCE);
     $destination = $this->getObject($context, static::PATH_DESTINATION);
     $this->tagManager->loadTagging($source);
     $tags = $source->getTags();
     $preparedTags = ['all' => $tags->toArray(), 'owner' => $tags->toArray()];
     $destination->setTags($preparedTags);
     $this->tagManager->saveTagging($destination);
 }
Пример #13
0
 /**
  * @param FormEvent $event
  */
 public function preSet(FormEvent $event)
 {
     $entity = $event->getForm()->getParent()->getData();
     if (!$this->taggableHelper->isTaggable($entity)) {
         return;
     }
     $this->tagManager->loadTagging($entity);
     $tags = $this->tagManager->getPreparedArray($entity, null, $this->organization);
     $event->setData($tags);
 }
Пример #14
0
 /**
  * Save tags
  *
  * @param EntityDataEvent $event
  */
 public function afterMergeEntity(EntityDataEvent $event)
 {
     $entityData = $event->getEntityData();
     $entityMetadata = $entityData->getMetadata();
     if (!$this->isTaggable($entityMetadata)) {
         return;
     }
     $masterEntity = $entityData->getMasterEntity();
     $masterTags = $this->tagManager->getTags($masterEntity)->getValues();
     $this->tagManager->setTags($masterEntity, ['all' => $masterTags, 'owner' => $masterTags]);
     $this->tagManager->saveTagging($masterEntity);
 }
Пример #15
0
 /**
  * {@inheritdoc}
  */
 protected function onSuccess($entity)
 {
     $targetEntity = $entity['target'];
     /** @var ArrayCollection $tags */
     $tags = $entity['tags'];
     $names = array_map(function ($tag) {
         return $tag['name'];
     }, $tags->getValues());
     $tags = $this->tagManager->loadOrCreateTags($names);
     $this->tagManager->setTags($targetEntity, new ArrayCollection($tags));
     $this->tagManager->saveTagging($targetEntity);
 }
Пример #16
0
 /**
  * {@inheritdoc}
  */
 public function transform($value)
 {
     // transform to JSON if we have array of entities
     // needed to correct rendering form if validation not passed
     if (is_array($value)) {
         $result = array();
         if ($this->entity) {
             $result = $this->manager->getPreparedArray($this->entity, new ArrayCollection($value), $this->organization);
         }
         $value = json_encode($result);
     }
     return $value;
 }
Пример #17
0
 /**
  * Deletes tags relations for $className in cases when "tagging" option has been disabled for it.
  *
  * @param PostFlushConfigEvent $event
  */
 public function postFlush(PostFlushConfigEvent $event)
 {
     foreach ($event->getModels() as $model) {
         if ($model instanceof EntityConfigModel) {
             $configManager = $event->getConfigManager();
             $className = $model->getClassName();
             $changeSet = $configManager->getConfigChangeSet($configManager->getProvider('tag')->getConfig($className));
             if (isset($changeSet['enabled']) && $changeSet['enabled'][0] && !$changeSet['enabled'][1]) {
                 $this->tagManager->deleteRelations($className);
             }
         }
     }
 }
 /**
  * @test
  */
 public function updateBranchWithAllValues()
 {
     $this->fileMock = new UploadedFileStub(self::DUMMY_LOGO_PATH, self::DUMMY_LOGO_NAME);
     $uploadedFile = $this->fileMock->move(self::DUMMY_LOGO_PATH, self::DUMMY_LOGO_NAME);
     $this->branchRepository->expects($this->once())->method('get')->will($this->returnValue($this->branch));
     $this->branch->expects($this->exactly(2))->method('getLogo')->will($this->returnValue($this->logo));
     $this->branchLogoHandler->expects($this->once())->method('remove')->with($this->equalTo($this->logo));
     $this->branchLogoHandler->expects($this->once())->method('upload')->with($this->equalTo($this->fileMock))->will($this->returnValue($uploadedFile));
     $name = 'DUMMY_NAME_UPDT';
     $description = 'DUMMY_DESC_UPDT';
     $assigneeId = 1;
     $assignee = new User($assigneeId, User::TYPE_ORO);
     $defaultAssignee = new OroUser();
     $tags = array('autocomplete' => array(), 'all' => array(), 'owner' => array());
     $this->branch->expects($this->once())->method('update')->with($this->equalTo($name), $this->equalTo($description), $this->equalTo($defaultAssignee), $this->equalTo(new Logo($uploadedFile->getFilename(), $uploadedFile->getFilename())));
     $this->branch->expects($this->once())->method('setTags')->with($this->equalTo($tags));
     $this->registry->expects($this->exactly(2))->method('getManager')->will($this->returnValue($this->entityManager));
     $this->entityManager->expects($this->once())->method('persist')->with($this->branch);
     $this->entityManager->expects($this->once())->method('flush');
     $this->tagManager->expects($this->once())->method('saveTagging')->with($this->equalTo($this->branch));
     $this->authorizationService->expects($this->once())->method('isActionPermitted')->with($this->equalTo('EDIT'), $this->equalTo('Entity:DiamanteDeskBundle:Branch'))->will($this->returnValue(true));
     $this->registry->expects($this->once())->method('getRepository')->with($this->equalTo('OroUserBundle:User'))->will($this->returnValue($this->userRepo));
     $this->userRepo->expects($this->once())->method('find')->with($this->equalTo($assigneeId))->will($this->returnValue($defaultAssignee));
     $command = new BranchCommand();
     $command->name = $name;
     $command->description = $description;
     $command->defaultAssignee = $assigneeId;
     $command->logoFile = $this->fileMock;
     $command->tags = $tags;
     $this->branchServiceImpl->updateBranch($command);
 }
 /**
  * Update Branch
  *
  * @param Command\BranchCommand $branchCommand
  * @return int
  */
 public function updateBranch(Command\BranchCommand $branchCommand)
 {
     $this->isGranted('EDIT', 'Entity:DiamanteDeskBundle:Branch');
     /**
      * @var $branch \Diamante\DeskBundle\Model\Branch\Branch
      */
     $branch = $this->branchRepository->get($branchCommand->id);
     if ($branchCommand->defaultAssignee) {
         $assignee = $this->userService->getByUser(new User($branchCommand->defaultAssignee, User::TYPE_ORO));
     } else {
         $assignee = null;
     }
     /** @var \Symfony\Component\HttpFoundation\File\File $file */
     $file = null;
     if ($branchCommand->isRemoveLogo()) {
         $this->branchLogoHandler->remove($branch->getLogo());
         $file = new Logo();
     } elseif ($branchCommand->logoFile) {
         if ($branch->getLogo()) {
             $this->branchLogoHandler->remove($branch->getLogo());
         }
         $logo = $this->handleLogoUpload($branchCommand->logoFile);
         $file = new Logo($logo->getFilename(), $branchCommand->logoFile->getClientOriginalName());
     }
     $branch->update($branchCommand->name, $branchCommand->description, $assignee, $file);
     $this->branchRepository->store($branch);
     //TODO: Refactor tag manipulations.
     $this->tagManager->deleteTaggingByParams($branch->getTags(), get_class($branch), $branch->getId());
     $tags = $branchCommand->tags;
     $tags['owner'] = $tags['all'];
     $branch->setTags($tags);
     $this->tagManager->saveTagging($branch);
     return $branch->getId();
 }
Пример #20
0
 /**
  * {@inheritdoc}
  */
 protected function onSuccess(User $user)
 {
     $this->manager->updateUser($user);
     $this->tagManager->saveTagging($user);
     if ($this->form->has('inviteUser') && $this->form->has('plainPassword') && $this->form->get('inviteUser')->getViewData() && $this->form->get('plainPassword')->getViewData()) {
         try {
             $this->sendInviteMail($user, $this->form->get('plainPassword')->getViewData()['first']);
         } catch (\Exception $ex) {
             $this->logger->error('Invitation email sending failed.', ['exception' => $ex]);
             $this->flashBag->add('warning', $this->translator->trans('oro.user.controller.invite.fail.message'));
         }
     }
     // Reloads the user to reset its username. This is needed when the
     // username or password have been changed to avoid issues with the
     // security layer.
     // Additional checking for userConfigManager !== null is added because of API
     // to avoid "Call to a member function on a non-object".
     $this->manager->reloadUser($user);
     if ($this->form->has('signature') && $this->userConfigManager !== null) {
         $signature = $this->form->get('signature')->getData();
         if ($signature) {
             $this->userConfigManager->set('oro_email.signature', $signature);
         } else {
             $this->userConfigManager->reset('oro_email.signature');
         }
         $this->userConfigManager->flush();
     }
 }
 /**
  * Rendering tags depend on context..
  *
  * @param \Twig_Environment $twig
  * @param $entityId
  * @param $context
  * @return string
  */
 public function renderTag(\Twig_Environment $twig, $entityId, $context)
 {
     switch ($context) {
         case 'branch':
             /** @var \Diamante\DeskBundle\Entity\Branch $entity */
             $entity = $this->registry->getRepository('DiamanteDeskBundle:Branch')->get($entityId);
             break;
         case 'ticket':
             /** @var \Diamante\DeskBundle\Entity\Ticket $entity */
             $entity = $this->registry->getRepository('DiamanteDeskBundle:Ticket')->get($entityId);
             break;
         default:
             throw new \InvalidArgumentException('Entity didn\'t get.');
     }
     $this->tagManager->loadTagging($entity);
     return $twig->render('DiamanteDeskBundle:Tag/Datagrid/Property:tag.html.twig', ['tags' => $entity->getTags()->getValues()]);
 }
Пример #22
0
 public function testGetPreparedArrayFromArray()
 {
     $resource = new Taggable(array('id' => 1));
     $this->user->expects($this->exactly(2))->method('getId')->will($this->returnValue(self::TEST_USER_ID));
     $this->router->expects($this->once())->method('generate');
     $repo = $this->getMockBuilder('Oro\\Bundle\\TagBundle\\Entity\\Repository\\TagRepository')->disableOriginalConstructor()->getMock();
     $repo->expects($this->never())->method('getTagging');
     $this->manager->getPreparedArray($resource, $this->tagForPreparing());
 }
Пример #23
0
 /**
  * {@inheritdoc}
  */
 public function reverseTransform($value)
 {
     if (!$value) {
         return new ArrayCollection();
     }
     $tags = explode(';;', $value);
     $names = [];
     foreach ($tags as $tag) {
         $tag = json_decode($tag, true);
         if ($tag && array_key_exists('name', $tag) === true) {
             $names[] = $tag['name'];
         }
     }
     if (!empty($names)) {
         return new ArrayCollection($this->tagManager->loadOrCreateTags($names));
     }
     return new ArrayCollection();
 }
Пример #24
0
 public function loadContactsTags()
 {
     $userTagsCount = count($this->tagsUser);
     $accountTagsCount = count($this->tagsAccount);
     foreach ($this->contactsRepository as $contact) {
         $this->tagManager->setTags($contact, new ArrayCollection([$this->tagsUser[rand(0, $userTagsCount - 1)], $this->tagsAccount[rand(0, $accountTagsCount - 1)]]));
         $this->tagManager->saveTagging($contact, false);
     }
     $this->flush($this->em);
 }
 /**
  * Update Article
  *
  * @param Command\ArticleCommand $articleCommand
  * @return int
  */
 public function updateArticle(Command\ArticleCommand $articleCommand)
 {
     /** @var $article Article */
     $article = $this->repository->get($articleCommand->id);
     $article->update($articleCommand->title, $articleCommand->content, $articleCommand->status);
     $this->registry->getManager()->persist($article);
     $this->handleTagging($articleCommand, $article);
     $this->registry->getManager()->flush();
     $this->tagManager->saveTagging($article);
     return $article->getId();
 }
 public function testRenderTicket()
 {
     $tags = array(array('id' => 1, 'name' => 'Ticket Tag'));
     $renderTagResult = '<span class="tag-inline">Ticket Tag</span>';
     $this->registry->expects($this->once())->method('getRepository')->will($this->returnValue($this->sharedRepository));
     $this->tagManager->expects($this->once())->method('loadTagging')->will($this->returnValue($this->tagManager));
     $this->twig->expects($this->once())->method('render')->will($this->returnValue($renderTagResult));
     $this->sharedRepository->expects($this->once())->method('get')->will($this->returnValue($this->ticket));
     $this->ticket->expects($this->once())->method('getTags')->will($this->returnValue($this->commonCollection));
     $this->commonCollection->expects($this->once())->method('getValues')->will($this->returnValue($tags));
     $ticketResult = $this->renderTagExtensionExtension->renderTag($this->twig, 1, 'ticket');
     $this->assertEquals($renderTagResult, $ticketResult);
 }
Пример #27
0
 public function loadContactsTags()
 {
     foreach ($this->contactsRepository as $contact) {
         $user = $this->usersRepository[rand(0, $this->randomUser)];
         $securityContext = $this->container->get('security.context');
         $token = new UsernamePasswordOrganizationToken($user, $user->getUsername(), 'main', $this->organization);
         $securityContext->setToken($token);
         $ownTags = array($this->tagsUser[rand(0, $this->randomUserTag)], $this->tagsAccount[rand(0, $this->randomAccountTag - 1)]);
         $contact->setTags(array('owner' => $ownTags, 'all' => array()));
         $this->persist($this->em, $contact);
         $this->tagManager->saveTagging($contact, false);
     }
     $this->flush($this->em);
     $this->em->clear('Oro\\Bundle\\ContactBundle\\Entity\\Contact');
 }
Пример #28
0
 /**
  * {@inheritdoc}
  */
 protected function onSuccess(User $user)
 {
     $this->manager->updateUser($user);
     $this->tagManager->saveTagging($user);
     if ($this->form->has('inviteUser') && $this->form->has('plainPassword') && $this->form->get('inviteUser')->getViewData() && $this->form->get('plainPassword')->getViewData()) {
         try {
             $this->sendInviteMail($user, $this->form->get('plainPassword')->getViewData()['first']);
         } catch (\Exception $ex) {
             $this->logger->error('Invitation email sending failed.', array('exception' => $ex));
             $this->flashBag->add('warning', $this->translator->trans('oro.user.controller.invite.fail.message'));
         }
     }
     // Reloads the user to reset its username. This is needed when the
     // username or password have been changed to avoid issues with the
     // security layer.
     $this->manager->reloadUser($user);
 }
 /**
  * Update Branch
  *
  * @param Command\BranchCommand $branchCommand
  * @return int
  */
 public function updateBranch(Command\BranchCommand $branchCommand)
 {
     $this->isGranted('EDIT', 'Entity:DiamanteDeskBundle:Branch');
     /**
      * @var $branch \Diamante\DeskBundle\Entity\Branch
      */
     $branch = $this->branchRepository->get($branchCommand->id);
     $assignee = $this->extractDefaultBranchAssignee($branchCommand);
     if ($branchCommand->isRemoveLogo() || $branchCommand->logoFile) {
         $this->removeBranchLogo($branch);
     }
     $file = $this->uploadBranchLogoIfExists($branchCommand);
     $branch->update($branchCommand->name, $branchCommand->description, $assignee, $file);
     $this->registry->getManager()->persist($branch);
     $this->handleTagging($branchCommand, $branch);
     $this->registry->getManager()->flush();
     $this->tagManager->saveTagging($branch);
     return $branch->getId();
 }
 /**
  * Retrieves list of all Tickets. Performs filtering of tickets if provided with criteria as GET parameters.
  * Time filtering parameters as well as paging/sorting configuration parameters can be found in \Diamante\DeskBundle\Api\Command\Filter\CommonFilterCommand class.
  * Time filtering values should be converted to UTC
  *
  * @ApiDoc(
  *  description="Returns all tickets.",
  *  uri="/tickets.{_format}",
  *  method="GET",
  *  resource=true,
  *  statusCodes={
  *      200="Returned when successful",
  *      403="Returned when the user is not authorized to list tickets"
  *  }
  * )
  *
  * @param Command\Filter\FilterTicketsCommand $ticketFilterCommand
  * @return \Diamante\DeskBundle\Entity\Ticket[]
  */
 public function listAllTickets(Command\Filter\FilterTicketsCommand $ticketFilterCommand)
 {
     $criteriaProcessor = new TicketFilterCriteriaProcessor();
     $repository = $this->getTicketRepository();
     $user = $this->getAuthorizationService()->getLoggedUser();
     if ($user instanceof ApiUser) {
         $user = $this->userService->getUserFromApiUser($user);
     }
     $pagingProperties = $this->buildPagination($criteriaProcessor, $repository, $ticketFilterCommand, $this->apiPagingService);
     $criteria = $criteriaProcessor->getCriteria();
     $tickets = $repository->filter($criteria, $pagingProperties, $user);
     if ($this->loggedUser instanceof OroUser) {
         foreach ($tickets as $ticket) {
             /** @var Ticket $ticket */
             $this->tagManager->loadTagging($ticket);
         }
     }
     $pagingInfo = $this->apiPagingService->getPagingInfo($repository, $pagingProperties, $criteria);
     $this->populatePagingHeaders($this->apiPagingService, $pagingInfo);
     return $tickets;
 }