/** * @param AccountUser $accountUser * @return QueryBuilder */ public function getAvailableRolesByAccountUserQueryBuilder(AccountUser $accountUser) { $qb = $this->createQueryBuilder('accountUserRole'); $qb->where($qb->expr()->andX($qb->expr()->orX($qb->expr()->isNull('accountUserRole.account'), $qb->expr()->eq('accountUserRole.account', ':account')), $qb->expr()->eq('accountUserRole.organization', ':organization'))); $qb->setParameter('account', $accountUser->getAccount()); $qb->setParameter('organization', $accountUser->getOrganization()); return $qb; }
/** * @param ObjectManager $manager * @param AccountUser $accountUser * @param string $label * @param boolean $current * * @return ShoppingList */ protected function createShoppingList(ObjectManager $manager, AccountUser $accountUser, $label, $current) { $shoppingList = new ShoppingList(); $shoppingList->setOrganization($accountUser->getOrganization()); $shoppingList->setAccountUser($accountUser); $shoppingList->setAccount($accountUser->getAccount()); $shoppingList->setNotes('Some notes for ' . $label); $shoppingList->setCurrent($current); $shoppingList->setLabel($label); $manager->persist($shoppingList); }
/** * @param ObjectManager $manager * @param string $name * @param AccountUser $accountUser * @param bool $isCurrent * * @return ShoppingList */ protected function createShoppingList(ObjectManager $manager, AccountUser $accountUser, $name, $isCurrent = false) { $shoppingList = new ShoppingList(); $shoppingList->setOrganization($accountUser->getOrganization()); $shoppingList->setAccountUser($accountUser); $shoppingList->setAccount($accountUser->getAccount()); $shoppingList->setLabel($name . '_label'); $shoppingList->setNotes($name . '_notes'); $shoppingList->setCurrent($isCurrent); $manager->persist($shoppingList); $this->addReference($name, $shoppingList); return $shoppingList; }
/** * {@inheritdoc} * @dataProvider supportedMethods */ public function testProcessSupportedRequest($method, $isValid, $isProcessed) { $organization = null; if ($isValid) { $organization = new Organization(); $organization->setName('test'); $organizationToken = $this->getMock('Oro\\Bundle\\SecurityBundle\\Authentication\\Token\\OrganizationContextTokenInterface'); $organizationToken->expects($this->any())->method('getOrganizationContext')->willReturn($organization); $this->securityFacade->expects($this->any())->method('getToken')->willReturn($organizationToken); $this->form->expects($this->at(2))->method('get')->with('passwordGenerate')->will($this->returnValue($this->passwordGenerateForm)); $this->form->expects($this->at(3))->method('get')->with('sendEmail')->will($this->returnValue($this->sendEmailForm)); $this->passwordGenerateForm->expects($this->once())->method('getData')->will($this->returnValue(false)); $this->sendEmailForm->expects($this->once())->method('getData')->will($this->returnValue(false)); } $this->form->expects($this->any())->method('isValid')->will($this->returnValue($isValid)); $this->request->setMethod($method); $this->form->expects($this->once())->method('submit')->with($this->request); $this->assertEquals($isProcessed, $this->handler->process($this->entity)); if ($organization) { $this->assertEquals($organization, $this->entity->getOrganization()); $this->assertTrue($this->entity->hasOrganization($organization)); } }
/** * "Success" form handler * * @param ShoppingList $entity * @return bool */ protected function onSuccess(ShoppingList $entity) { $rfpRequest = new RFPRequest(); $rfpRequest->setFirstName($this->user->getFirstName())->setLastName($this->user->getLastName())->setEmail($this->user->getEmail())->setPhone('')->setRole('')->setBody('')->setCompany($this->user->getOrganization() ? $this->user->getOrganization()->getName() : '')->setAccountUser($this->user)->setAccount($this->user->getAccount())->setStatus($this->requestStatus); foreach ($entity->getLineItems() as $shoppingListLineItem) { $requestProduct = new RequestProduct(); $requestProduct->setProduct($shoppingListLineItem->getProduct()); $requestProductItem = new RequestProductItem(); $requestProductItem->setQuantity($shoppingListLineItem->getQuantity())->setProductUnit($shoppingListLineItem->getUnit()); $requestProduct->addRequestProductItem($requestProductItem); $rfpRequest->addRequestProduct($requestProduct); } try { $this->manager->persist($rfpRequest); $this->manager->flush(); $this->rfpRequest = $rfpRequest; } catch (DBALException $e) { $this->exception = $e; return false; } return true; }