/** * (non-PHPdoc) * @see \Symfony\Component\Form\DataTransformerInterface::reverseTransform() */ public function reverseTransform($value) { if (null === $value || '' === $value) { return null; } return $this->om->getReference($this->class, $value); }
public function load(ObjectManager $manager) { $role = new Role(); $role->setNome('visitante'); $manager->persist($role); $visitante = $manager->getReference('SONAcl\\Entity\\Role', 1); $role = new Role(); $role->setNome('registrado'); $role->setParent($visitante); $manager->persist($role); $registrado = $manager->getReference('SONAcl\\Entity\\Role', 2); $role = new Role(); $role->setNome('redator'); $role->setParent($registrado); $manager->persist($role); $redator = $manager->getReference('SONAcl\\Entity\\Role', 3); $role = new Role(); $role->setNome('editor'); $role->setParent($redator); $manager->persist($role); $editor = $manager->getReference('SONAcl\\Entity\\Role', 4); $role = new Role(); $role->setNome('admin'); $role->setIsAdmin(true); $role->setParent($editor); $manager->persist($role); $manager->flush(); }
/** * {@inheritdoc} */ public function getResourceProxy($className, $identifier) { if ($this->objectManager instanceof EntityManagerInterface) { return $this->objectManager->getReference($className, $identifier); } return $this->getResource($className, $identifier); }
/** * @param ObjectManager|EntityManager $manager */ public function load(ObjectManager $manager) { $settingsProvider = $this->container->get('orocrm_channel.provider.settings_provider'); $lifetimeSettings = $settingsProvider->getLifetimeValueSettings(); if (!array_key_exists(ChannelType::TYPE, $lifetimeSettings)) { return; } $magentoChannelSettings = $lifetimeSettings[ChannelType::TYPE]; $customerIdentityClass = $magentoChannelSettings['entity']; $lifetimeField = $magentoChannelSettings['field']; $accountClass = $this->container->getParameter('orocrm_account.account.entity.class'); $channelClass = $this->container->getParameter('orocrm_channel.entity.class'); /** @var LifetimeHistoryRepository $lifetimeRepo */ $lifetimeRepo = $manager->getRepository('OroCRMChannelBundle:LifetimeValueHistory'); $brokenAccountQb = $this->getBrokenAccountsQueryBuilder($customerIdentityClass, $lifetimeField, $lifetimeRepo); $brokenAccountsData = new BufferedQueryResultIterator($brokenAccountQb); $toOutDate = []; foreach ($brokenAccountsData as $brokenDataRow) { /** @var Account $account */ $account = $manager->getReference($accountClass, $brokenDataRow['account_id']); /** @var Channel $channel */ $channel = $manager->getReference($channelClass, $brokenDataRow['channel_id']); $lifetimeAmount = $lifetimeRepo->calculateAccountLifetime($customerIdentityClass, $lifetimeField, $account, $channel); $history = new LifetimeValueHistory(); $history->setAmount($lifetimeAmount); $history->setDataChannel($channel); $history->setAccount($account); $manager->persist($history); $toOutDate[] = [$account, $channel, $history]; } $manager->flush(); foreach (array_chunk($toOutDate, self::MAX_UPDATE_CHUNK_SIZE) as $chunks) { $lifetimeRepo->massStatusUpdate($chunks); } }
public function load(ObjectManager $manager) { $dev = $manager->getReference('Zf2User\\Entity\\User', 1); $admin = $manager->getReference('Zf2User\\Entity\\User', 2); $boot = $manager->getReference('Zf2User\\Entity\\User', 3); $perfil = new Perfil(); $perfil->setUser($dev)->setName("Developer")->setDateBirth("14-05-1992"); $manager->persist($perfil); $perfil = new Perfil(); $perfil->setUser($admin)->setName("Administrator")->setDateBirth("14-05-1992"); $manager->persist($perfil); $perfil = new Perfil(); $perfil->setUser($boot)->setName("Boot Functionary")->setDateBirth("14-05-1992"); $manager->persist($perfil); $manager->flush(); }
/** * Add associations to call item * * @param Call $entity */ protected function handleAssociations(Call $entity) { $associationsFormField = $this->form->get('associations'); if (!$associationsFormField) { return; } $associations = $associationsFormField->getData(); if (empty($associations)) { return; } foreach ($associations as $association) { $associationType = isset($association['type']) ? $association['type'] : null; $target = $this->manager->getReference($association['entityName'], $association['entityId']); call_user_func([$entity, AssociationNameGenerator::generateAddTargetMethodName($associationType)], $target); } }
public function load(ObjectManager $manager) { /** @var EntityManager $manager */ $this->customerRepository = $manager->getRepository('OroCRMMagentoBundle:Customer'); // Calculate lifetime value for all customers $queryBuilder = $this->customerRepository->createQueryBuilder('customer'); $queryBuilder->select('SUM( CASE WHEN customerOrder.subtotalAmount IS NOT NULL THEN customerOrder.subtotalAmount ELSE 0 END - CASE WHEN customerOrder.discountAmount IS NOT NULL THEN ABS(customerOrder.discountAmount) ELSE 0 END ) AS lifetime', 'customer.id as customerId', 'customer.lifetime AS oldLifetime', 'IDENTITY(customer.dataChannel) as dataChannelId')->leftJoin('customer.orders', 'customerOrder', 'WITH', $queryBuilder->expr()->neq($queryBuilder->expr()->lower('customerOrder.status'), ':status'))->groupBy('customer.account, customer.id')->orderBy('customer.account')->setParameter('status', Order::STATUS_CANCELED); // Get lifetime value only for customers that have canceled orders $this->addFilterByOrderStatus($queryBuilder, Order::STATUS_CANCELED); $iterator = new BufferedQueryResultIterator($queryBuilder); $iterator->setBufferSize(self::BUFFER_SIZE); $channels = []; foreach ($iterator as $row) { if ($row['lifetime'] == $row['oldLifetime']) { continue; } $this->updateCustomerLifetimeValue($row['customerId'], $row['lifetime']); if (!isset($channels[$row['dataChannelId']])) { $channels[$row['dataChannelId']] = $row['dataChannelId']; } } foreach ($channels as $channelId) { /** @var Channel $channel */ $channel = $manager->getReference('OroCRMChannelBundle:Channel', $channelId); $this->updateLifetimeForAccounts($channel); } }
/** * @param ObjectManager $manager * @param string $name * @param array $address * @return OrderAddress */ protected function createOrderAddress(ObjectManager $manager, $name, array $address) { /** @var Country $country */ $country = $manager->getReference('OroAddressBundle:Country', $address['country']); if (!$country) { throw new \RuntimeException('Can\'t find country with ISO ' . $address['country']); } /** @var Region $region */ $region = $manager->getReference('OroAddressBundle:Region', $address['region']); if (!$region) { throw new \RuntimeException(sprintf('Can\'t find region with code %s', $address['country'])); } $orderAddress = new OrderAddress(); $orderAddress->setCountry($country)->setCity($address['city'])->setRegion($region)->setStreet($address['street'])->setPostalCode($address['postalCode']); $manager->persist($orderAddress); $this->addReference($name, $orderAddress); return $orderAddress; }
public function load(ObjectManager $manager) { $role = new Role(); $role->setNome('Visitante'); $manager->persist($role); $visitante = $manager->getReference('EOSAcl\\Entity\\Role', 1); $role = new Role(); $role->setNome('Registrado')->setParent($visitante); $manager->persist($role); $registrado = $manager->getReference('EOSAcl\\Entity\\Role', 2); $role = new Role(); $role->setNome('Redator')->setParent($registrado); $manager->persist($role); $role = new Role(); $role->setNome('Admin')->setIsAdmin(TRUE); $manager->persist($role); $manager->flush(); }
public function load(ObjectManager $manager) { $visit = $manager->getReference('Zf2Acl\\Entity\\Role', 1); $client = $manager->getReference('Zf2Acl\\Entity\\Role', 2); $functionary = $manager->getReference('Zf2Acl\\Entity\\Role', 3); $admin = $manager->getReference('Zf2Acl\\Entity\\Role', 4); $developer = $manager->getReference('Zf2Acl\\Entity\\Role', 5); $user = new User(); $user->setEmail("*****@*****.**")->setUsername("developer")->setPassword(123456)->setPasswordClue('123456')->setStatus(true)->setRole($developer); $manager->persist($user); $user = new User(); $user->setEmail("*****@*****.**")->setUsername("admin")->setPassword(123456)->setPasswordClue('123456')->setStatus(true)->setRole($admin); $manager->persist($user); $user = new User(); $user->setEmail("*****@*****.**")->setUsername("functionary")->setPassword(123456)->setPasswordClue('123456')->setStatus(true)->setRole($functionary); $manager->persist($user); $manager->flush(); }
public function load(ObjectManager $manager) { $role = new Role(); $role->setNome("Visitante"); $manager->persist($role); $visitante = $manager->getReference('SONAcl\\Entity\\Role', 1); $role = new Role(); $role->setNome("Registrado")->setParent($visitante); $manager->persist($role); $registrado = $manager->getReference('SONAcl\\Entity\\Role', 2); $role = new Role(); $role->setNome("Redator")->setParent($registrado); $manager->persist($role); $role = new Role(); $role->setNome("Admin")->setIsAdmin(true); $manager->persist($role); $manager->flush(); }
public function load(ObjectManager $manager) { $role = new Role(); $role->setName("Visit"); $manager->persist($role); $visit = $manager->getReference('Zf2Acl\\Entity\\Role', 1); $role = new Role(); $role->setName("Client")->setParent($visit)->setRedirect("dashboard"); $manager->persist($role); $role = new Role(); $role->setName("Functionary")->setParent($visit)->setRedirect("dashboard"); $manager->persist($role); $functionary = $manager->getReference('Zf2Acl\\Entity\\Role', 3); $role = new Role(); $role->setName("Administrator")->setParent($functionary)->setRedirect("dashboard"); $manager->persist($role); $role = new Role(); $role->setName("Developer")->setDeveloper(1)->setRedirect("dashboard"); $manager->persist($role); $manager->flush(); }
/** * Loads an object using stored reference * named by $name * * @param string $name * @return object */ public function getReference($name) { $reference = $this->references[$name]; $meta = $this->manager->getClassMetadata(get_class($reference)); $uow = $this->manager->getUnitOfWork(); if (!$uow->isInIdentityMap($reference) && isset($this->identities[$name])) { $reference = $this->manager->getReference($meta->name, $this->identities[$name]); $this->references[$name] = $reference; // allready in identity map } return $reference; }
/** * Loads an object using stored reference * named by $name * * @param string $name * @throws OutOfBoundsException - if repository does not exist * @return object */ public function getReference($name) { if (!$this->hasReference($name)) { throw new \OutOfBoundsException("Reference to: ({$name}) does not exist"); } $reference = $this->references[$name]; $meta = $this->manager->getClassMetadata(get_class($reference)); if (!$this->manager->contains($reference) && isset($this->identities[$name])) { $reference = $this->manager->getReference($meta->name, $this->identities[$name]); $this->references[$name] = $reference; // already in identity map } return $reference; }
/** * Returns the object with the (internal) identifier, if it is known to the * backend. Otherwise NULL is returned. * * @param mixed $identifier * @param string $objectType * @param boolean $useLazyLoading Set to TRUE if you want to use lazy loading for this object * @return object The object for the identifier if it is known, or NULL * @throws \RuntimeException * @api */ public function getObjectByIdentifier($identifier, $objectType = null, $useLazyLoading = false) { if ($objectType === null) { throw new \RuntimeException('Using only the identifier is not supported by Doctrine 2. Give classname as well or use repository to query identifier.', 1296646103); } if (isset($this->newObjects[$identifier])) { return $this->newObjects[$identifier]; } if ($useLazyLoading === true) { return $this->entityManager->getReference($objectType, $identifier); } else { return $this->entityManager->find($objectType, $identifier); } }
public function load(ObjectManager $manager) { $role1 = $manager->getReference('EOSAcl\\Entity\\Role', 1); $resource1 = $manager->getReference('EOSAcl\\Entity\\Resource', 1); $role2 = $manager->getReference('EOSAcl\\Entity\\Role', 2); $resource2 = $manager->getReference('EOSAcl\\Entity\\Resource', 2); $role3 = $manager->getReference('EOSAcl\\Entity\\Role', 3); $resource3 = $manager->getReference('EOSAcl\\Entity\\Resource', 3); $role4 = $manager->getReference('EOSAcl\\Entity\\Role', 4); $resource4 = $manager->getReference('EOSAcl\\Entity\\Resource', 4); $privilege = new Privilege(); $privilege->setNome("Visualizar")->setRole($role1)->setResource($resource1); $manager->persist($privilege); $privilege = new Privilege(); $privilege->setNome("Novo / Editar")->setRole($role3)->setResource($resource1); $manager->persist($privilege); $privilege = new Privilege(); $privilege->setNome("Excluir")->setRole($role4)->setResource($resource1); $manager->persist($privilege); $manager->flush(); }
/** * Create new activated user * * @param string $email * @param string $password * @param string $firstName * @param string $lastName * @param integer $publication */ public function createUser($email, $password, $username, $firstName = null, $lastName = null, $publication = 0, $public = true, $userTypes = array()) { $users = $this->findBy(array('email' => $email)); if (!empty($users)) { throw new \Newscoop\Exception\ResourcesConflictException("User with this email already exists"); } $user = new User($email); $user->setPassword($password); $user->setUsername($username); $user->setPublic($public); $user->setActive(); $user->setFirstName($firstName); $user->setLastName($lastName); $user->setPublication($publication); foreach ($userTypes as $type) { $user->addUserType($this->em->getReference('Newscoop\\Entity\\User\\Group', $type)); } $this->em->persist($user); $this->em->flush(); return $user; }
public function load(ObjectManager $manager) { $role = $manager->getReference('SONAcl\\Entity\\Role', 3); $resource = $manager->getReference('SONAcl\\Entity\\Resource', 1); $privilege = new Privilege(); $privilege->setNome('Visualizar')->setRole($role)->setResource($resource); $manager->persist($privilege); $role = $manager->getReference('SONAcl\\Entity\\Role', 2); $resource = $manager->getReference('SONAcl\\Entity\\Resource', 2); $privilege = new Privilege(); $privilege->setNome('Novo/Editar')->setRole($role)->setResource($resource); $manager->persist($privilege); $role = $manager->getReference('SONAcl\\Entity\\Role', 1); $resource = $manager->getReference('SONAcl\\Entity\\Resource', 4); $privilege = new Privilege(); $privilege->setNome('Administrar')->setRole($role)->setResource($resource); $manager->persist($privilege); $manager->flush(); }
/** * Creates form and validates it or saves data in case some data * were already submitted. * * @param mixed $id Id of poll to be created * * @throws NotFoundHttpException * @throws Exception */ public function create($id, Response &$response) { $this->id = $id; $this->poll = $this->pollManager->findOneById($id); if (!$this->poll) { throw new NotFoundHttpException(sprintf("Poll with id '%s' was not found.", $id)); } if (!$this->poll->isActive()) { $this->isActive = false; return; } $this->form = $this->formFactory->create($id); $formName = $this->form->getName(); if ($this->request->getMethod() === 'POST' && $this->request->request->has($formName) && !$this->voteManager->hasVoted($this->poll)) { $this->form->bindRequest($this->request); if ($this->form->isValid()) { $data = $this->form->getData(); $votes = array(); foreach ($data as $fieldId => $answer) { $fieldId = str_replace('field_', '', $fieldId); $answers = (array) $answer; $field = $this->objectManager->getReference($this->fieldClass, $fieldId); foreach ($answers as $answer) { $vote = $this->voteManager->create($field, $answer); $votes[] = $vote; } } $response = new RedirectResponse($this->request->getUri()); $pollType = $this->poll->getType(); // Checks if poll type is proper one, defined in PollInterface $fieldClassReflection = new \ReflectionClass($this->pollClass); $fieldConstants = $fieldClassReflection->getConstants(); if (!in_array($pollType, $fieldConstants)) { throw new \Exception(sprintf('"%s" is incorrect poll type.', $pollType)); } // Checks what multi-vote prevention mechanisms should be triggered // and error that might occur. $doPersist = false; if ($this->poll instanceof SignedPollInterface) { $isAuthenticated = $this->securityContext->isGranted('IS_AUTHENTICATED_FULLY'); if (in_array($pollType, array(PollInterface::POLL_TYPE_USER, PollInterface::POLL_TYPE_MIXED)) && $isAuthenticated) { $user = $this->securityContext->getToken()->getUser(); foreach ($votes as $vote) { $vote->setAuthor($user); } $doPersist = true; } } else { if (in_array($pollType, array(PollInterface::POLL_TYPE_USER, PollInterface::POLL_TYPE_MIXED))) { throw new \Exception(sprintf('Poll type is "%s", but your Poll class doesn\'t (%s) implement Bait\\PollBundle\\Model\\SignedPollInterface', $pollType, $this->pollClass)); } } if (in_array($pollType, array(PollInterface::POLL_TYPE_ANONYMOUS, PollInterface::POLL_TYPE_MIXED))) { $cookie = new Cookie(sprintf('%svoted_%s', $this->cookiePrefix, $id), true, time() + $this->cookieDuration); $response->headers->setCookie($cookie); $doPersist = true; } // If everything went ok, save all votes if ($doPersist) { $this->voteManager->save($votes); } } } }
public function load(ObjectManager $manager) { // Users $userNew = new User(); $userNew->setUsername('rasben'); $userNew->setPassword('rasben2'); $userNew->setFullName('Benjamin Rasmussen'); $userNew->setApiKey('apirasben'); $manager->persist($userNew); $manager->flush(); $userNew = new User(); $userNew->setUsername('elvis'); $userNew->setPassword('elvis2'); $userNew->setFullName('Elvis Presley'); $userNew->setApiKey('apielvis'); $manager->persist($userNew); $manager->flush(); $userNew = new User(); $userNew->setUsername('sherlock'); $userNew->setPassword('sherlock2'); $userNew->setFullName('Sherlock Holmes'); $userNew->setApiKey('apisherlock'); $manager->persist($userNew); $manager->flush(); $userNew = new User(); $userNew->setUsername('alexander'); $userNew->setPassword('alexander2'); $userNew->setFullName('Alexander The Great'); $userNew->setApiKey('apialexander'); $manager->persist($userNew); $manager->flush(); // Kitchens $kitchenNew = new Kitchen(); $kitchenNew->setName('The Copenhagen Kitchen'); $kitchenNew->setLocation('Copenhagen, DK'); $manager->persist($kitchenNew); $manager->flush(); $kitchenNew = new Kitchen(); $kitchenNew->setName('The London Kitchen'); $kitchenNew->setLocation('London, UK'); $manager->persist($kitchenNew); $manager->flush(); $kitchenNew = new Kitchen(); $kitchenNew->setName('The Berlin Kitchen'); $kitchenNew->setLocation('Berlin, DE'); $manager->persist($kitchenNew); $manager->flush(); // Languages $languageNew = new Language(); $languageNew->setCode('en'); $manager->persist($languageNew); $manager->flush(); $languageNew = new Language(); $languageNew->setCode('da'); $manager->persist($languageNew); $manager->flush(); $languageNew = new Language(); $languageNew->setCode('fr'); $manager->persist($languageNew); $manager->flush(); // User Settings $userSettingNew = new UserSetting(); $userSettingNew->setUserID($manager->getReference('AppBundle:User', 1)); $userSettingNew->setDefaultKitchenID($manager->getReference('AppBundle:Kitchen', 1)); $userSettingNew->setAutoOpenDefaultKitchen(2); $userSettingNew->setModerator(2); $userSettingNew->setLanguageCode($manager->getReference('AppBundle:Language', 'en')); $manager->persist($userSettingNew); $manager->flush(); $userSettingNew = new UserSetting(); $userSettingNew->setUserID($manager->getReference('AppBundle:User', 2)); $userSettingNew->setDefaultKitchenID($manager->getReference('AppBundle:Kitchen', 2)); $userSettingNew->setAutoOpenDefaultKitchen(1); $userSettingNew->setModerator(1); $userSettingNew->setLanguageCode($manager->getReference('AppBundle:Language', 'en')); $manager->persist($userSettingNew); $manager->flush(); $userSettingNew = new UserSetting(); $userSettingNew->setUserID($manager->getReference('AppBundle:User', 3)); $userSettingNew->setDefaultKitchenID($manager->getReference('AppBundle:Kitchen', 2)); $userSettingNew->setAutoOpenDefaultKitchen(2); $userSettingNew->setModerator(1); $userSettingNew->setLanguageCode($manager->getReference('AppBundle:Language', 'en')); $manager->persist($userSettingNew); $manager->flush(); $userSettingNew = new UserSetting(); $userSettingNew->setUserID($manager->getReference('AppBundle:User', 4)); $userSettingNew->setDefaultKitchenID($manager->getReference('AppBundle:Kitchen', 2)); $userSettingNew->setAutoOpenDefaultKitchen(4); $userSettingNew->setModerator(2); $userSettingNew->setLanguageCode($manager->getReference('AppBundle:Language', 'en')); $manager->persist($userSettingNew); $manager->flush(); // Roles $roleNew = new Role(); $roleNew->setTitle('owner'); $manager->persist($roleNew); $manager->flush(); $roleNew = new Role(); $roleNew->setTitle('editor'); $manager->persist($roleNew); $manager->flush(); $roleNew = new Role(); $roleNew->setTitle('reader'); $manager->persist($roleNew); $manager->flush(); // Categories $categoryNew = new Category(); $categoryNew->setName('vegtables'); $manager->persist($categoryNew); $manager->flush(); $categoryNew = new Category(); $categoryNew->setName('meats'); $manager->persist($categoryNew); $manager->flush(); $categoryNew = new Category(); $categoryNew->setName('spices'); $manager->persist($categoryNew); $manager->flush(); $categoryNew = new Category(); $categoryNew->setName('poultry'); $manager->persist($categoryNew); $manager->flush(); $categoryNew = new Category(); $categoryNew->setName('bakery'); $manager->persist($categoryNew); $manager->flush(); // Kitchen Users $kitchenUserNew = new kitchenUser(); $kitchenUserNew->setUserID($manager->getReference('AppBundle:User', 1)); $kitchenUserNew->setRoleID($manager->getReference('AppBundle:Role', 1)); $kitchenUserNew->setKitchenID($manager->getReference('AppBundle:Kitchen', 1)); $manager->persist($kitchenUserNew); $manager->flush(); $kitchenUserNew = new kitchenUser(); $kitchenUserNew->setUserID($manager->getReference('AppBundle:User', 1)); $kitchenUserNew->setRoleID($manager->getReference('AppBundle:Role', 2)); $kitchenUserNew->setKitchenID($manager->getReference('AppBundle:Kitchen', 2)); $manager->persist($kitchenUserNew); $manager->flush(); $kitchenUserNew = new kitchenUser(); $kitchenUserNew->setUserID($manager->getReference('AppBundle:User', 2)); $kitchenUserNew->setRoleID($manager->getReference('AppBundle:Role', 1)); $kitchenUserNew->setKitchenID($manager->getReference('AppBundle:Kitchen', 2)); $manager->persist($kitchenUserNew); $manager->flush(); $kitchenUserNew = new kitchenUser(); $kitchenUserNew->setUserID($manager->getReference('AppBundle:User', 3)); $kitchenUserNew->setRoleID($manager->getReference('AppBundle:Role', 2)); $kitchenUserNew->setKitchenID($manager->getReference('AppBundle:Kitchen', 2)); $manager->persist($kitchenUserNew); $manager->flush(); // Amounts $amountNew = new Amount(); $amountNew->setName('Kilogram'); $amountNew->setShortName('kg'); $manager->persist($amountNew); $manager->flush(); $amountNew = new Amount(); $amountNew->setName('Gram'); $amountNew->setShortName('g'); $manager->persist($amountNew); $manager->flush(); $amountNew = new Amount(); $amountNew->setName('Liter'); $amountNew->setShortName('l'); $manager->persist($amountNew); $manager->flush(); $amountNew = new Amount(); $amountNew->setName('Mililiter'); $amountNew->setShortName('ml'); $manager->persist($amountNew); $manager->flush(); $amountNew = new Amount(); $amountNew->setName('Teaspoon'); $amountNew->setShortName('ts'); $manager->persist($amountNew); $manager->flush(); $amountNew = new Amount(); $amountNew->setName('Table spoon'); $amountNew->setShortName('tbls'); $manager->persist($amountNew); $manager->flush(); // Ingredients & names $ingredientNew = new Ingredient(); $ingredientNew->setGlobal(2); $ingredientNew->setCategoryID($manager->getReference('AppBundle:Category', 4)); $ingredientNew->setAmountID($manager->getReference('AppBundle:Amount', 2)); $manager->persist($ingredientNew); $manager->flush(); $ingredientNew = new IngredientName(); $ingredientNew->setName('Toast'); $ingredientNew->setIngredientID($manager->getReference('AppBundle:Ingredient', 1)); $ingredientNew->setMaster(1); $ingredientNew->setLanguageCode($manager->getReference('AppBundle:Language', 'en')); $manager->persist($ingredientNew); $manager->flush(); $ingredientNew = new Ingredient(); $ingredientNew->setGlobal(2); $ingredientNew->setCategoryID($manager->getReference('AppBundle:Category', 2)); $ingredientNew->setAmountID($manager->getReference('AppBundle:Amount', 2)); $manager->persist($ingredientNew); $manager->flush(); $ingredientNew = new IngredientName(); $ingredientNew->setName('Veal'); $ingredientNew->setIngredientID($manager->getReference('AppBundle:Ingredient', 2)); $ingredientNew->setMaster(0); $ingredientNew->setLanguageCode($manager->getReference('AppBundle:Language', 'en')); $manager->persist($ingredientNew); $manager->flush(); $ingredientNew = new Ingredient(); $ingredientNew->setGlobal(2); $ingredientNew->setCategoryID($manager->getReference('AppBundle:Category', 3)); $ingredientNew->setAmountID($manager->getReference('AppBundle:Amount', 2)); $manager->persist($ingredientNew); $manager->flush(); $ingredientNew = new IngredientName(); $ingredientNew->setName('Chicken Wings'); $ingredientNew->setIngredientID($manager->getReference('AppBundle:Ingredient', 3)); $ingredientNew->setMaster(1); $ingredientNew->setLanguageCode($manager->getReference('AppBundle:Language', 'en')); $manager->persist($ingredientNew); $manager->flush(); }
/** * Creates form and validates it or saves data in case some data * were already submitted. * * @param mixed $id Id of poll to be created * * @throws NotFoundHttpException * @throws Exception */ public function create($id, Response &$response, $options = array()) { $this->id = $id; $this->poll = $this->pollManager->findOneById($id); if (!$this->poll || $this->poll->getDeletedAt()) { throw new NotFoundHttpException(sprintf("Poll with id '%s' was not found.", $id)); } if (!$this->poll->isActive()) { $this->isActive = false; return; } $this->form = $this->formFactory->create($id); $formName = $this->form->getName(); if ($this->request->getMethod() === 'POST' && $this->request->request->has($formName) && !$this->answerGroupManager->hasAnswered($this->poll)) { $this->form->bindRequest($this->request); if ($this->form->isValid()) { $data = $this->form->getData(); $answers = array(); $answerGroup = $this->answerGroupManager->create($this->poll); foreach ($data as $fieldId => $userAnswer) { $fieldId = str_replace('field_', '', $fieldId); $field = $this->objectManager->getReference($this->fieldClass, $fieldId); if ($field->getType() === FieldInterface::TYPE_FILE) { if ($field->isRequired()) { $userAnswers = (array) $userAnswer->getClientOriginalName(); } } else { $userAnswers = (array) $userAnswer; } foreach ($userAnswers as $userAnswer) { $answer = $this->answerManager->create($field, $userAnswer, $answerGroup); $answers[] = $answer; } } $response = new RedirectResponse($this->request->getUri()); $pollType = $this->poll->getType(); // Checks if poll type is proper one, defined in PollInterface $fieldClassReflection = new \ReflectionClass($this->pollClass); $fieldConstants = $fieldClassReflection->getConstants(); if (!in_array($pollType, $fieldConstants)) { throw new \Exception(sprintf('"%s" is incorrect poll type.', $pollType)); } // Checks what multi-answer prevention mechanisms should be triggered // and error that might occur. $doPersist = false; if ($this->poll instanceof SignedPollInterface) { $isAuthenticated = $this->securityContext->isGranted('IS_AUTHENTICATED_FULLY'); if (in_array($pollType, array(PollInterface::POLL_TYPE_USER, PollInterface::POLL_TYPE_MIXED)) && $isAuthenticated) { $user = $this->securityContext->getToken()->getUser(); $answerGroup->setAuthor($user); $doPersist = true; } } else { if (in_array($pollType, array(PollInterface::POLL_TYPE_USER, PollInterface::POLL_TYPE_MIXED))) { throw new \Exception(sprintf('Poll type is "%s", but your Poll class (%s) doesn\'t implement Bait\\PollBundle\\Model\\SignedPollInterface', $pollType, $this->pollClass)); } } if (in_array($pollType, array(PollInterface::POLL_TYPE_ANONYMOUS, PollInterface::POLL_TYPE_MIXED))) { $cookieDuration = array_key_exists('cookieDuration', $options) ? (int) $options['cookieDuration'] : $this->cookieDuration; $cookie = new Cookie(sprintf('%sanswered_%s', $this->cookiePrefix, $id), true, time() + $cookieDuration); $response->headers->setCookie($cookie); $doPersist = true; } // Checks if any upload occurred/should have occurred // and handles it if ($this->fieldManager->hasUploadFields($this->poll)) { if ("" == $this->uploadDir) { throw new \Exception("You should configure the bait_poll.upload_dir directive in your config.yml"); } if (!is_writable($this->uploadDir . '/')) { throw new \Exception(sprintf('"%s" is not a writable folder for uploads.', $this->uploadDir)); } $answerGroup = $this->answerGroupManager->save($answerGroup); $folder = $this->uploadDir . '/' . $this->poll->getId() . '/answergroups/' . $answerGroup->getId(); mkdir($folder, 0777, true); foreach ($data as $fieldName => $field) { if ($field instanceof UploadedFile) { $field->move($folder, $fieldName . '.' . $field->guessExtension()); } } } // If everything went ok, save all answers if ($doPersist) { $this->answerGroupManager->save($answerGroup); $this->answerManager->save($answers); } } } }
public function load(ObjectManager $manager) { $visit = $manager->getReference('Zf2Acl\\Entity\\Role', 1); $client = $manager->getReference('Zf2Acl\\Entity\\Role', 2); $functionary = $manager->getReference('Zf2Acl\\Entity\\Role', 3); $admin = $manager->getReference('Zf2Acl\\Entity\\Role', 4); $developer = $manager->getReference('Zf2Acl\\Entity\\Role', 5); $aclRole = $manager->getReference('Zf2Acl\\Entity\\Resource', 1); $aclResource = $manager->getReference('Zf2Acl\\Entity\\Resource', 2); $aclPrivi = $manager->getReference('Zf2Acl\\Entity\\Resource', 3); $application = $manager->getReference('Zf2Acl\\Entity\\Resource', 4); $auth = $manager->getReference('Zf2Acl\\Entity\\Resource', 5); $user = $manager->getReference('Zf2Acl\\Entity\\Resource', 6); // Visitante $privilege = new Privilege(); $privilege->setName("All")->setRole($visit)->setResource($auth); $manager->persist($privilege); $privilege = new Privilege(); $privilege->setName("index")->setRole($visit)->setResource($application); $manager->persist($privilege); // Cliente $privilege = new Privilege(); $privilege->setName("client")->setRole($client)->setResource($application); $manager->persist($privilege); // Cliente FIM // Funcionario $privilege = new Privilege(); $privilege->setName("admin")->setRole($functionary)->setResource($application); $manager->persist($privilege); // Funcionario FIm // Admin $privilege = new Privilege(); $privilege->setName("All")->setRole($admin)->setResource($user); $manager->persist($privilege); // Admin fim $manager->flush(); }