find() public method

This is just a convenient shortcut for getRepository($entityName)->find($id).
public find ( string $entityName, mixed $identifier, integer $lockMode = LockMode::NONE, integer $lockVersion = null ) : object
$entityName string
$identifier mixed
$lockMode integer
$lockVersion integer
return object
 private function verifyBrands()
 {
     for ($i = 1; $i <= 10; ++$i) {
         /* @var $brand \Hautelook\AliceBundle\Tests\SymfonyApp\TestBundle\Entity\Brand */
         $this->entityManager->find('Hautelook\\AliceBundle\\Tests\\SymfonyApp\\TestBundle\\Entity\\Brand', $i);
     }
 }
Ejemplo n.º 2
0
 /**
  * @param $location_id
  * @param array $resources
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function storeLocation($location_id, array $resources)
 {
     $location = $this->em->find('riki34GameBundle:Location', $location_id);
     $this->jsonLoader->storeFile($location->getFile(), $resources);
     $message = "Location saved";
     return $this->response->generateSuccessResponse(array($message));
 }
Ejemplo n.º 3
0
 public function getMainAdvs()
 {
     $advs = ['trade' => [], 'find' => [], 'gift' => []];
     $qb = $this->em->createQueryBuilder();
     $trade = $qb->select('a')->from('NaidusvoeBundle:Advertisment', 'a')->where($qb->expr()->andX($qb->expr()->isNotNull('a.onMainUntill'), $qb->expr()->eq('a.typeID', Advertisment::TRADE)))->getQuery()->getResult();
     $type = $this->em->find('NaidusvoeBundle:AdvertismentType', Advertisment::TRADE);
     $advsCount = count($trade);
     $advs['trade'] = $this->getRandom($trade, AdvertisementService::MAIN_ADV_COUNT);
     if ($advsCount < 5) {
         $advs['trade'] = array_merge($advs['trade'], $this->generateDummyAdvs(AdvertisementService::MAIN_ADV_COUNT - $advsCount, $type));
     }
     $qb = $this->em->createQueryBuilder();
     $find = $qb->select('a')->from('NaidusvoeBundle:Advertisment', 'a')->where($qb->expr()->andX($qb->expr()->isNotNull('a.onMainUntill'), $qb->expr()->eq('a.typeID', Advertisment::FIND)))->getQuery()->getResult();
     $type = $this->em->find('NaidusvoeBundle:AdvertismentType', Advertisment::FIND);
     $advsCount = count($find);
     $advs['find'] = $this->getRandom($find, AdvertisementService::MAIN_ADV_COUNT);
     if ($advsCount < 5) {
         $advs['find'] = array_merge($advs['find'], $this->generateDummyAdvs(AdvertisementService::MAIN_ADV_COUNT - $advsCount, $type));
     }
     $qb = $this->em->createQueryBuilder();
     $gift = $qb->select('a')->from('NaidusvoeBundle:Advertisment', 'a')->where($qb->expr()->andX($qb->expr()->isNotNull('a.onMainUntill'), $qb->expr()->eq('a.typeID', Advertisment::GIFT)))->getQuery()->getResult();
     $type = $this->em->find('NaidusvoeBundle:AdvertismentType', Advertisment::GIFT);
     $advsCount = count($gift);
     $advs['gift'] = $this->getRandom($gift, AdvertisementService::MAIN_ADV_COUNT);
     if ($advsCount < 5) {
         $advs['gift'] = array_merge($advs['gift'], $this->generateDummyAdvs(AdvertisementService::MAIN_ADV_COUNT - $advsCount, $type));
     }
     return $advs;
 }
Ejemplo n.º 4
0
 public function postVoteAction(Request $request)
 {
     $data = $request->getContent();
     $voteData = json_decode($data, true);
     $vote = new Vote();
     if (isset($voteData['user_id']) && ($userId = $voteData['user_id'])) {
         $user = $this->em->find('\\HackdayProject\\Entity\\User', $userId);
         if (!$user) {
             throw new NotFound('User cannot be found');
         }
         $vote->setUser($user);
     }
     if (isset($voteData['entry_id']) && ($entryId = $voteData['entry_id'])) {
         $entry = $this->em->find('\\HackdayProject\\Entity\\Entry', $entryId);
         if (!$entry) {
             throw new NotFound('User cannot be found');
         }
         $vote->setEntry($entry);
     } else {
         throw new BadRequestHttpException();
     }
     $vote->setValue($voteData['value']);
     $this->em->persist($vote);
     $this->em->flush($vote);
     return new JsonResponse($vote->toArray(), 201);
 }
Ejemplo n.º 5
0
 public function insertUpdateProcessing(EntityManager $em, $data, $id = null)
 {
     $update = !is_null($id);
     try {
         $em->beginTransaction();
         if ($update) {
             $language = $em->find('Model\\Language', $id);
         } else {
             $language = new Language();
         }
         $language->setCode($data['code']);
         $language->setDescription($data['description']);
         $language->setFlagImageURL($data['flagimageurl']);
         $menu = $em->find('Model\\Menu', $data['menuid']);
         $language->setMenu($menu);
         if ($update) {
             $em->merge($language);
         } else {
             $em->persist($language);
         }
         $em->flush();
         $em->commit();
     } catch (\Exception $e) {
         $em->rollback();
         throw $e;
     }
     return $language->getId();
 }
Ejemplo n.º 6
0
 public function testInsertStoresCorrectValue()
 {
     $id = $this->driver->insert('Stuff', array('name' => 'stupid'));
     $entity_name = 'DerpTest\\Machinist\\Store\\TestEntity\\Doctrine\\Stuff';
     $stuff = $this->em->find($entity_name, $id);
     $this->assertEquals('stupid', $stuff->getName());
 }
Ejemplo n.º 7
0
 /**
  * 
  * @param type $id
  * @return \Sticks\Model\Stick
  * @throws Exceptions\EntityNotFound
  */
 public function getIfExist($id)
 {
     if ($row = $this->_em->find(static::$_stickClass, $id)) {
         return $row;
     }
     throw new Exceptions\EntityNotFound($id);
 }
Ejemplo n.º 8
0
 private function getObject($object)
 {
     /** @var ObjectViews $object */
     $entity = $this->objects[$object->getEntity()];
     $object = $this->em->find($entity, $object->getObjectId());
     return $object;
 }
Ejemplo n.º 9
0
 /**
  * Add required filters
  *
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $datagrid = $event->getDatagrid();
     /** @var OrmDatasource $ormDataSource */
     $ormDataSource = $datagrid->getDatasource();
     $queryBuilder = $ormDataSource->getQueryBuilder();
     $parameters = $datagrid->getParameters();
     if ($parameters->has('userId')) {
         $user = $this->entityManager->find('OroUserBundle:User', $parameters->get('userId'));
         $queryBuilder->andWhere('call.owner = :user')->setParameter('user', $user);
     }
     if ($parameters->has('contactId')) {
         $contact = $this->entityManager->find('OroCRMContactBundle:Contact', $parameters->get('contactId'));
         $queryBuilder->andWhere('call.relatedContact = :contact')->setParameter('contact', $contact);
     }
     if ($parameters->has('accountId')) {
         $account = $this->entityManager->find('OroCRMAccountBundle:Account', $parameters->get('accountId'));
         $queryBuilder->andWhere('(call.relatedAccount = :account OR :account MEMBER OF contact.accounts)')->setParameter('account', $account);
     }
     if ($parameters->has('callIds')) {
         $callIds = $parameters->get('callIds');
         if (!is_array($callIds)) {
             $callIds = explode(',', $callIds);
         }
         $queryBuilder->andWhere($queryBuilder->expr()->in('call.id', $callIds));
     }
 }
Ejemplo n.º 10
0
 public function addNotification($users, $notificationType, $notificationDetails)
 {
     /** @var User $user */
     foreach ($users as $user) {
         $initiator = null;
         $notification = new Notification($notificationType, $user);
         $notification->setUserId($user->getId());
         if ($notificationType === Notification::SIMPLE_NOTIFICATION) {
             $notification->setContent($notificationDetails['content']);
             $initiator = "Naidusvoe";
         }
         if ($notificationType === Notification::CONVERSATION_NOTIFICATION) {
             $notification->setConversationId($notificationDetails['conversationId']);
             $notification->setMessageId($notificationDetails['messageId']);
             $notification->setContent("Ви отримали особисте повідомлення");
             $userInitiatorId = $notificationDetails['userInitiatorId'];
             $initiator = $this->em->find('NaidusvoeBundle:User', $userInitiatorId)->getUsername();
             $notification->setInitiatorId($userInitiatorId);
         }
         $this->em->persist($notification);
         $this->em->flush();
         if ($user->getSettings()->getNotificationsEmail()) {
             /** @var \Swift_Message $message */
             $message = $this->mailer->createMessage()->setSubject('You have some new notification')->setFrom('*****@*****.**')->setTo($user->getEmail())->setBody($this->templating->render('@Naidusvoe/mail.html.twig', ['content' => $notification->getContent(), 'Initiator' => $initiator]), 'text/html');
             $this->mailer->send($message);
         }
     }
 }
Ejemplo n.º 11
0
 /**
  * @param string $id Site UUID.
  *
  * @return Site|null
  */
 public function find($id)
 {
     if (!\Undine\Functions\valid_uuid($id)) {
         return null;
     }
     return $this->em->find(Site::class, (string) $id);
 }
Ejemplo n.º 12
0
 public function getImageAction($id)
 {
     $image = $this->em->find('HackdayProject\\Entity\\Image', $id);
     if (!$image) {
         throw new NotFound('Image cannot be found');
     }
     return new JsonResponse($image->toArray());
 }
Ejemplo n.º 13
0
 /**
  * @param int $id
  * @return User
  * @throws Exception
  */
 public function findById($id)
 {
     $user = $this->entityManager->find('Janus\\ServiceRegistry\\Entity\\User', $id);
     if (!$user instanceof User) {
         throw new Exception("User '{$id}' not found");
     }
     return $user;
 }
 public function find($id)
 {
     $author = $this->entityManager->find('Doctrine\\Bundle\\LicenseManagerBundle\\Entity\\Author', $id);
     if (!$author) {
         throw new AuthorNotFoundException($id);
     }
     return $author;
 }
Ejemplo n.º 15
0
 public function loginAction()
 {
     $this->authSession->Login = null;
     $id = $this->getRequest()->getParam("Id");
     $login = $this->em->find("eCamp\\Entity\\Login", $id);
     $this->authSession->Login = $login;
     $this->view->LoginPMod = new eCamp\PMod\LoginPMod($login);
 }
Ejemplo n.º 16
0
 /**
  * Perform authentication attempt
  *
  * @return \Zend_Auth_Result
  */
 public function authenticate()
 {
     $identity = $this->em->find('Newscoop\\Entity\\UserIdentity', array('provider' => $this->provider, 'provider_user_id' => $this->providerUserId));
     if (empty($identity)) {
         return new \Zend_Auth_Result(\Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND, NULL);
     }
     return new \Zend_Auth_Result(\Zend_Auth_Result::SUCCESS, $identity->getUser()->getId());
 }
Ejemplo n.º 17
0
 /**
  * Get get cart products for given $userId
  *
  * @param int $productId
  *
  * @return Product $product
  */
 public function loadProductById($productId)
 {
     $product = $this->dm->find('Aisel\\ProductBundle\\Entity\\Product', $productId);
     if (!$product) {
         throw new LogicException('Product was not found');
     }
     return $product;
 }
Ejemplo n.º 18
0
 /**
  * @return null|User
  * @throws \Doctrine\ORM\ORMException
  * @throws \Doctrine\ORM\OptimisticLockException
  * @throws \Doctrine\ORM\TransactionRequiredException
  */
 protected function findUser()
 {
     if ($this->user->isLoggedIn()) {
         return $this->em->find(User::class, $this->user->id);
     } else {
         return null;
     }
 }
 public function testFormView()
 {
     $form = $this->makeForm();
     $form->setData($this->em->find('Infinite\\FormBundle\\Tests\\EntitySearch\\Entity\\Fruit', 6));
     $view = $form->createView();
     $this->assertEquals(6, $view->vars['value']['id']);
     $this->assertEquals('pineapple', $view->vars['value']['name']);
 }
Ejemplo n.º 20
0
 /**
  * @param Integration $integration
  * @return Integration|null
  */
 protected function getIntegration(Integration $integration)
 {
     if (!$integration->getId()) {
         return null;
     }
     $oldIntegration = $this->em->find('OroIntegrationBundle:Channel', $integration->getId());
     return $oldIntegration ? clone $oldIntegration : null;
 }
Ejemplo n.º 21
0
 public function getPhoneNumber($user, $id)
 {
     foreach ($user->getPhonenumbers() as $element) {
         if ($element->getId() == $id) {
             return $this->em->find(Phonenumbers::class, $id);
         }
     }
     return new Phonenumbers();
 }
Ejemplo n.º 22
0
 /**
  * @param int|Order $order
  * @param int $status
  */
 function changeStatus($order, $status)
 {
     if (is_object($order)) {
         $order->setStatus($status);
     } else {
         $this->em->find(Order::class, $order)->setStatus($status);
     }
     $this->em->flush();
 }
Ejemplo n.º 23
0
 /**
  * @param $entityClassName
  * @param $id
  * @return mixed
  * @throws EntityNotFoundException
  * @throws \Exception
  */
 protected function findEntityById($entityClassName, $id)
 {
     $this->assertEntityManager();
     $entity = $this->entityManager->find($entityClassName, $id);
     if (is_null($entity)) {
         throw new NotFoundException('We could not find a resource with the given id');
     }
     return $entity;
 }
Ejemplo n.º 24
0
 public function isInstalled()
 {
     try {
         $this->em->find("malkusch\\bav\\MetaData", MetaData::LASTMODIFIED);
         return true;
     } catch (DBALException $e) {
         return false;
     }
 }
Ejemplo n.º 25
0
 /**
  * Check user action token
  *
  * @param Newscoop\Entity\User $user
  * @param string $token
  * @param string $action
  * @return bool
  */
 public function checkToken(User $user, $token, $action = 'any')
 {
     $userToken = $this->em->find('Newscoop\\Entity\\UserToken', array('user' => $user->getId(), 'action' => $action, 'token' => $token));
     if (empty($userToken)) {
         return false;
     }
     $now = new \DateTime();
     return $now->sub(new \DateInterval(self::TOKEN_LIFETIME))->getTimestamp() < $userToken->getCreated()->getTimestamp();
 }
Ejemplo n.º 26
0
 /**
  * @param $subject
  * @param $template
  * @param $data
  * @param Request $request
  * @return mixed
  * @throws \Doctrine\ORM\ORMException
  * @throws \Doctrine\ORM\OptimisticLockException
  * @throws \Doctrine\ORM\TransactionRequiredException
  * @throws \Exception
  * @throws \Twig_Error
  *
  * @return \Swift_Message
  */
 public function createMessage($subject, $template, $data, Request $request = null)
 {
     $history = null;
     if ($request && $request->cookies->has('tracker_id')) {
         /** @var \keltanas\Bundle\TrackingBundle\Entity\History $history */
         $history = $this->em->find('keltanasTrackingBundle:History', $request->cookies->get('tracker_id'));
     }
     $message = $this->mailer->createMessage()->setSubject($subject)->setFrom($this->from)->setTo($this->to)->setBody($this->templating->render($template, ['data' => $data, 'history' => $history]), 'text/html', 'utf-8');
     return $message;
 }
Ejemplo n.º 27
0
 /**
  * Retrieve a single record according to given identifer
  * @param type $id identifier of the record
  * @return type 
  */
 function get($id)
 {
     try {
         $object = $this->em->find($this->entity, $id);
         return $object;
     } catch (Exception $err) {
         log_message("error", $err->getMessage(), false);
         return NULL;
     }
 }
Ejemplo n.º 28
0
 public function testFindById()
 {
     $s1 = $this->em->find('\\AppBundle\\Entity\\Source', 1);
     $this->assertNotNull($s1);
     $s1 = $this->em->find('\\AppBundle\\Entity\\Riff', 1);
     $this->assertNotNull($s1);
     $r = $s1->getRating()->getText();
     echo $r;
     $s1 = $this->em->find('\\AppBundle\\Entity\\Riff', 77);
     $this->assertNull($s1);
 }
Ejemplo n.º 29
0
 /**
  * @param int $id Order id.
  */
 function handleCancel($id)
 {
     /** @var Order $order */
     $order = $this->em->find(Order::class, $id);
     if ($order) {
         $order->setStatus(Order::STATUS_CANCELLED);
         $this->em->flush();
         $this->presenter->flashMessage('Order has been cancelled', 'info');
         $this->presenter->redirect('Homepage:default');
     }
 }
Ejemplo n.º 30
0
 /**
  * {@inheritdoc}
  */
 public function expand($className, $value, array $options = [])
 {
     if ($this->isTransient($className)) {
         return null;
     }
     $entity = $this->em->find($className, $value, $this->getLockMode($options));
     if ($entity) {
         return $entity;
     }
     throw new ObjectNotFoundException();
 }