/** * @param BeforeListRenderEvent $event */ public function onAccountGroupView(BeforeListRenderEvent $event) { if (!$this->request) { return; } $groupId = (int) $this->request->get('id'); /** @var AccountGroup $group */ $group = $this->doctrineHelper->getEntityReference('OroB2BAccountBundle:AccountGroup', $groupId); $paymentTermRepository = $this->getPaymentTermRepository(); $paymentTerm = $paymentTermRepository->getOnePaymentTermByAccountGroup($group); $paymentTermData = ['paymentTerm' => $paymentTerm, 'paymentTermLabel' => $paymentTerm ? $paymentTerm->getLabel() : null, 'empty' => $this->translator->trans('N/A'), 'defineToTheGroup' => false]; $template = $event->getEnvironment()->render('OroB2BPaymentBundle:Account:payment_term_view.html.twig', ['paymentTermData' => $paymentTermData]); $event->getScrollData()->addSubBlockData(0, 0, $template); }
/** * @param BeforeListRenderEvent $event */ public function onProductView(BeforeListRenderEvent $event) { if (!$this->request) { return; } $productId = $this->request->get('id'); /** @var Product $product */ $product = $this->doctrineHelper->getEntityReference('OroB2BProductBundle:Product', $productId); /** @var CategoryRepository $repository */ $repository = $this->doctrineHelper->getEntityRepository('OroB2BCatalogBundle:Category'); $category = $repository->findOneByProduct($product); $template = $event->getEnvironment()->render('OroB2BCatalogBundle:Product:category_view.html.twig', ['entity' => $category]); $this->addCategoryBlock($event->getScrollData(), $template); }
/** * @param BeforeListRenderEvent $event */ public function onFrontendProductView(BeforeListRenderEvent $event) { if (!$this->request) { return; } $productId = (int) $this->request->get('id'); if (!$productId) { return; } if (!$this->doctrineHelper->getEntityReference('OroB2BProductBundle:Product', $productId)) { return; } $template = $event->getEnvironment()->render('OroB2BShoppingListBundle:Product/Frontend:view.html.twig', ['productId' => $productId]); $this->addShoppingListBlock($event->getScrollData(), $template); }
/** * @param $className * @return null|object */ protected function getEntityFromRequestId($className) { if (!$this->request) { return null; } $entityId = (int) $this->request->get('id'); if (!$entityId) { return null; } $entity = $this->doctrineHelper->getEntityReference($className, $entityId); if (!$entity) { return null; } return $entity; }
/** * Deserialize data of WorkflowItem * * @param WorkflowItem $workflowItem */ protected function deserialize(WorkflowItem $workflowItem) { // Pass serializer into $workflowItem to make lazy loading of workflow item data. $workflowItem->setSerializer($this->serializer, $this->format); // Set related entity $relatedEntity = $this->doctrineHelper->getEntityReference($workflowItem->getDefinition()->getRelatedEntity(), $workflowItem->getEntityId()); $workflowItem->setEntity($relatedEntity); }
public function testGetEntityReference() { $expectedResult = $this->getMock('MockEntityReference'); $entityClass = 'MockEntity'; $entityId = 100; $this->em->expects($this->once())->method('getReference')->with($entityClass, $entityId)->will($this->returnValue($expectedResult)); $this->registry->expects($this->any())->method('getManagerForClass')->with($entityClass)->will($this->returnValue($this->em)); $this->assertEquals($expectedResult, $this->doctrineHelper->getEntityReference($entityClass, $entityId)); }
/** * Returns the reference to the entity object by its class name and id * * If entity id is not specified the reference to the new entity object is returned * * @param string $entityClass The class name. Also the _ char can be used instead of \ * @param mixed|null $entityId The object id * * @return object The entity reference * * @throws BadRequestHttpException */ public function getEntityReference($entityClass, $entityId = null) { $entityClass = $this->decodeClassName($entityClass); try { $entity = $entityId ? $this->doctrineHelper->getEntityReference($entityClass, $entityId) : $this->doctrineHelper->createEntityInstance($entityClass); } catch (NotManageableEntityException $e) { throw new BadRequestHttpException($e->getMessage(), $e); } return $entity; }
/** * @param BeforeListRenderEvent $event */ public function onProductView(BeforeListRenderEvent $event) { if (!$this->request) { return; } $productId = $this->request->get('id'); /** @var Customer $customer */ $product = $this->doctrineHelper->getEntityReference('OroB2BProductBundle:Product', $productId); $template = $event->getEnvironment()->render('OroB2BPricingBundle:Product:prices_view.html.twig', ['entity' => $product]); $this->addProductPricesBlock($event->getScrollData(), $template); }
/** * @param BeforeListRenderEvent $event */ public function onFrontendProductView(BeforeListRenderEvent $event) { if (!$this->request) { return; } $productId = (int) $this->request->get('id'); /** @var Product $product */ $product = $this->doctrineHelper->getEntityReference('OroB2BProductBundle:Product', $productId); $priceList = $this->frontendPriceListRequestHandler->getPriceList(); /** @var ProductPriceRepository $priceRepository */ $priceRepository = $this->doctrineHelper->getEntityRepository('OroB2BPricingBundle:ProductPrice'); $prices = $priceRepository->findByPriceListIdAndProductIds($priceList->getId(), [$product->getId()]); $template = $event->getEnvironment()->render('OroB2BPricingBundle:Frontend/Product:productPrice.html.twig', ['prices' => $prices]); $scrollData = $event->getScrollData(); $subBlockId = $scrollData->addSubBlock(0); $scrollData->addSubBlockData(0, $subBlockId, $template); }
/** * @param object $entity * @param array $data */ protected function fillEntityData($entity, array $data = []) { if (!$data) { return; } if (!$this->propertyAccessor) { $this->propertyAccessor = PropertyAccess::createPropertyAccessor(); } $metadata = $this->doctrineHelper->getEntityMetadata($entity); foreach ($data as $property => $value) { try { if ($metadata->hasAssociation($property)) { $value = $this->doctrineHelper->getEntityReference($metadata->getAssociationTargetClass($property), $value); } $this->propertyAccessor->setValue($entity, $property, $value); } catch (NoSuchPropertyException $e) { } } }
/** * @param int|string $id * @return object */ protected function getEntityById($id) { return $this->doctrineHelper->getEntityReference($this->class, $id); }
/** * @param object $entity * @return object */ public function getEntityReference($entity) { $entityName = ClassUtils::getClass($entity); $identifier = $this->getIdentifier($entity); return $this->doctrineHelper->getEntityReference($entityName, $identifier); }
/** * @param string $enumCode * @param string $id * @return AbstractEnumValue */ public function getEnumValueByCode($enumCode, $id) { $enumClass = ExtendHelper::buildEnumValueClassName($enumCode); return $this->doctrineHelper->getEntityReference($enumClass, $id); }