Esempio n. 1
0
 /**
  * @param RuleAction $action
  * @return string
  */
 public function getLabel(RuleAction $action)
 {
     $params = $this->getParams($action);
     $repo = $this->entityManager->getRepository('HomefinanceBundle:Category');
     $category = $repo->findOneBy(array('id' => $params['category_id']));
     return $this->translator->trans('rules.actions.set_category.label', array('%category%' => $category->getTitle()), 'rules');
 }
Esempio n. 2
0
 /**
  * @param EntityManagerInterface $entityManager
  */
 public function __construct(EntityManagerInterface $entityManager)
 {
     $this->entityManager = $entityManager;
     $this->nextPrimaryKeyRepository = $this->entityManager->getRepository('Sinergi\\Sage50\\NextPrimaryKey\\NextPrimaryKeyEntity');
     $this->journalEntryRepository = $this->entityManager->getRepository('Sinergi\\Sage50\\JournalEntry\\JournalEntryEntity');
     $this->locationInventoryRepository = $this->entityManager->getRepository('Sinergi\\Sage50\\LocationInventory\\LocationInventoryEntity');
 }
 /**
  * {@inheritdoc}
  */
 public function getRepository($entity = null)
 {
     if ($entity === null) {
         return $this->em->getRepository($this->getEntityName());
     }
     return $this->em->getRepository($entity);
 }
 /**
  * @param Schema $schema
  */
 public function down(Schema $schema)
 {
     $rep = $this->em->getRepository('AnimeDbCatalogBundle:Genre');
     foreach (array_keys($this->genres) as $en) {
         $this->em->remove($rep->findOneBy(['name' => $en]));
     }
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function getMassActions()
 {
     $archiveAction = new MassAction('Archive', function ($ids) {
         /** @var InvoiceRepository $invoiceRepository */
         $invoiceRepository = $this->entityManager->getRepository('CSBillInvoiceBundle:Invoice');
         /** @var Invoice[] $invoices */
         $invoices = $invoiceRepository->findBy(array('id' => $ids));
         /** @var FlashBag $flashBag */
         $flashBag = $this->session->getBag('flashes');
         $failed = 0;
         foreach ($invoices as $invoice) {
             try {
                 $this->invoiceManager->archive($invoice);
             } catch (InvalidTransitionException $e) {
                 $flashBag->add('warning', $e->getMessage());
                 ++$failed;
             }
         }
         if ($failed !== count($invoices)) {
             $flashBag->add('success', 'invoice.archive.success');
         }
     }, true);
     $archiveAction->setIcon('archive');
     $archiveAction->setClass('warning');
     return array($archiveAction, new DeleteMassAction());
 }
Esempio n. 6
0
 /**
  * @param $productId
  * @return bool|Product
  */
 public function getItem($productId)
 {
     if (isset($this->cart[$productId])) {
         return $this->entityManager->getRepository('ProductBundle:Product')->find($productId);
     }
     return false;
 }
Esempio n. 7
0
 /**
  * Get repository.
  *
  * @return TaskEntityRepository
  */
 public function getRepository()
 {
     if (null === $this->repository) {
         $this->repository = $this->entityManager->getRepository(TaskEntity::class);
     }
     return $this->repository;
 }
 /**
  * @return \Doctrine\Common\Persistence\ObjectRepository
  */
 private function getRepository()
 {
     if ($this->repository === null) {
         $this->repository = $this->entityManager->getRepository('ItBlasterSingleConfigBundle:Config');
     }
     return $this->repository;
 }
 /**
  * @return array
  */
 private function getOrderInfo()
 {
     $order = $this->entityManager->getRepository('AppBundle:TicketsOrder')->findOneBy(array('ref' => $this->orderRef));
     $orderId = $order->getId();
     $isValidate = $order->isValidate();
     return array($order, $orderId, $isValidate);
 }
Esempio n. 10
0
 /**
  * @medium
  */
 public function testImportExport()
 {
     $sourceStorage = new LocalFileStorage(new \SplFileInfo(__DIR__ . '/../../../metadata/testfiles/100.csv'), new CsvFormat());
     $targetStorage = new DoctrineStorage(self::$em, 'TestEntities\\Address');
     $this->assertEquals(new StorageInfo(['name' => 'SELECT o FROM TestEntities\\Address o', 'count' => 0, 'type' => 'DQL Query']), $targetStorage->info());
     $importer = Importer::build($targetStorage);
     $importConfiguration = new ImportConfiguration();
     $importRun = $importConfiguration->toRun();
     $import = Import::build($importer, $sourceStorage, $importRun);
     $eventDispatcher = new EventDispatcher();
     $importRunner = new ImportRunner(new DefaultWorkflowFactory($eventDispatcher));
     $importRunner->run($import);
     $entities = self::$em->getRepository('TestEntities\\Address')->findAll();
     //import worked
     $this->assertEquals(100, count($entities));
     $exportFile = '/tmp/doctrine_test.csv';
     @unlink($exportFile);
     $sourceStorage = new DoctrineStorage(self::$em, null, self::$em->createQuery("SELECT A FROM TestEntities\\Address A WHERE A.zip LIKE '2%'"));
     $this->assertEquals(new StorageInfo(['name' => "SELECT A FROM TestEntities\\Address A WHERE A.zip LIKE '2%'", 'count' => 10, 'type' => 'DQL Query']), $sourceStorage->info());
     $targetStorage = new LocalFileStorage(new \SplFileInfo($exportFile), new CsvFormat());
     $importer = Importer::build($targetStorage);
     $importConfiguration = new ImportConfiguration();
     $importRun = $importConfiguration->toRun();
     $import = Import::build($importer, $sourceStorage, $importRun);
     $eventDispatcher = new EventDispatcher();
     $importRunner = new ImportRunner(new DefaultWorkflowFactory($eventDispatcher));
     $importRunner->run($import);
     $this->assertFileExists($exportFile);
     $this->assertEquals(11, count(file($exportFile)));
     //+header
     $this->assertEquals(10, $import->getRun()->toArray()['statistics']['processed']);
 }
 public function notify(UrlEvent $event)
 {
     if (!$this->isEnabled() || !$event->getUrl() || $event->getType() !== Shortener::NOTIFY_TYPE_REDIRECT) {
         return false;
     }
     $additional = $event->getAdditional();
     $ip = !empty($additional['ip']) ? $additional['ip'] : null;
     if (!$ip) {
         return false;
     }
     $urlRepository = $this->em->getRepository('Rz\\Bundle\\UrlShortenerBundle\\Entity\\Url');
     $urlStatRepository = $this->em->getRepository('Rz\\Bundle\\UrlShortenerBundle\\Entity\\UrlStat');
     /** @var Url $url */
     $url = $urlRepository->find($event->getUrl()->getId());
     $url->incrementRedirectCount();
     $url->setLastRedirectOn(new \DateTime());
     $urlStat = $urlStatRepository->findOneBy(['Url' => $url, 'ip' => $ip]);
     if (!$urlStat) {
         $url->incrementUniqueRedirectCount();
         $urlStat = new UrlStat();
         $urlStat->setUrl($url);
         $urlStat->setCreated(new \DateTime());
         $urlStat->setIp($ip);
         if (!empty($additional['user-agent'])) {
             $urlStat->setUserAgent($additional['user-agent']);
         }
         $this->em->persist($urlStat);
     }
     $this->em->persist($url);
     $this->em->flush();
     return true;
 }
Esempio n. 12
0
 /**
  * @param EntityManagerInterface $em
  */
 public function __construct(EntityManagerInterface $em)
 {
     $this->em = $em;
     $this->contentRepository = $em->getRepository(ContentItem::class);
     $this->taxonomyRepository = $em->getRepository(Taxonomy::class);
     $this->termRepository = $em->getRepository(Term::class);
 }
 /**
  * UserFiledsetFilter constructor.
  * @param EntityManagerInterface $em
  * @param null $config
  */
 public function __construct(EntityManagerInterface $em, $config = null)
 {
     $this->add(['name' => 'id', 'required' => true, 'filters' => [['name' => 'Int']]]);
     $this->add(['name' => 'username', 'required' => true, 'filters' => [['name' => 'StripTags'], ['name' => 'StringTrim']], 'validators' => [['name' => 'StringLength', 'options' => ['encoding' => 'UTF-8', 'min' => 5, 'max' => 100]], ['name' => 'DoctrineModule\\Validator\\UniqueObject', 'options' => ['use_context' => true, 'object_manager' => $em, 'object_repository' => $em->getRepository($config['identityClass']), 'fields' => $config['identityProperty'], 'messages' => [UniqueObject::ERROR_OBJECT_NOT_UNIQUE => sprintf(_('The username %s already exists'), '\'%value%\'')]]]]]);
     $this->add(['name' => 'email', 'required' => true, 'filters' => [['name' => 'StripTags'], ['name' => 'StringTrim']], 'validators' => [['name' => 'EmailAddress', 'options' => ['message' => _('Invalid email address')]], ['name' => 'DoctrineModule\\Validator\\UniqueObject', 'options' => ['use_context' => true, 'object_manager' => $em, 'object_repository' => $em->getRepository($config['identityClass']), 'fields' => $config['identityEmail'], 'messages' => [UniqueObject::ERROR_OBJECT_NOT_UNIQUE => sprintf(_('The email %s already exists'), '\'%value%\'')]]]]]);
     $this->add(['name' => 'password', 'required' => true, 'filters' => [['name' => 'StringTrim'], ['name' => 'StringTrim']], 'validators' => [['name' => 'StringLength', 'options' => ['encoding' => 'UTF-8', 'min' => 6, 'max' => 128]]]]);
 }
 public function fetchFacebookEvents()
 {
     $events = $this->em->getRepository('NFQKVKScraperBundle:EventData')->getAllEventsWithFacebookId();
     foreach ($events as $eventData) {
         $this->populateFacebookEvent($eventData);
     }
 }
 /**
  * @param $configKey
  * @param $objectId
  * @param $value
  * @param null|string $dataField
  * @throws ContentEditableException
  */
 public function updateEntity($configKey, $objectId, $value, $dataField = null)
 {
     if (!array_key_exists($configKey, $this->configuration['configurations'])) {
         throw new ContentEditableException('Missing configuration "' . $configKey . '"');
     }
     $config = $this->configuration['configurations'][$configKey];
     if ($dataField == null) {
         if (!array_key_exists('data_field', $config)) {
             throw new ContentEditableException('Missing data_field');
         }
         $dataField = $config['data_field'];
     }
     $idField = 'id';
     if (array_key_exists('id_field', $config)) {
         $idField = $config['id_field'];
     }
     $repository = $this->entityManager->getRepository($config['repository_class']);
     $entity = $repository->findOneBy([$idField => $objectId]);
     $setter = 'set' . ucfirst($dataField);
     if (!method_exists($entity, $setter)) {
         throw new ContentEditableException('No setter "' . $setter . '" found for "' . get_class($entity) . '"');
     }
     $entity->{$setter}(trim($value));
     $this->entityManager->persist($entity);
     $this->entityManager->flush();
 }
 /**
  * {@inheritdoc}
  *
  * @see \Symfony\Component\Validator\ConstraintValidatorInterface::validate()
  */
 public function validate($category, Constraint $constraint)
 {
     $result = $this->em->getRepository($this->entityClassName)->findByName($category->getName(), array(CategoryModel::STATE_DRAFT, CategoryModel::STATE_WAITING, CategoryModel::STATE_PUBLISHED));
     if (null !== $result && $result->getId() !== $category->getId()) {
         $this->context->buildViolation($constraint->alreadyExistsMessage)->atPath('name')->addViolation();
     }
 }
 public function getFilters()
 {
     $filterFactory = function ($className) {
         return function ($nodes) use($className) {
             $nodes = is_array($nodes) ? $nodes : ($nodes ? iterator_to_array($nodes) : []);
             return array_filter($nodes, function ($item) use($className) {
                 if ($item instanceof HasRefInterface) {
                     return $item->getRefName() === $className;
                 }
                 return $item instanceof $className;
             });
         };
     };
     $pageFetcher = function ($className) {
         return function ($id) use($className) {
             return $this->em->getRepository($className)->find($id);
         };
     };
     $pageFetchers = $this->pageFetchersConfiguration();
     $filterFactories = $this->filterFactoriesConfiguration();
     return array_combine(array_keys($pageFetchers), array_map(function ($name, $class) use($pageFetcher) {
         return new \Twig_SimpleFilter($name, $pageFetcher($class));
     }, array_keys($pageFetchers), $pageFetchers)) + array_combine(array_keys($filterFactories), array_map(function ($name, $class) use($filterFactory) {
         return new \Twig_SimpleFilter($name, $filterFactory($class));
     }, array_keys($filterFactories), $filterFactories));
 }
Esempio n. 18
0
 /**
  * @param Parser $params
  * @param array &$resourceObject
  * @throws ParseException
  */
 public function hydrate(Params $params, array &$resourceObject)
 {
     if (empty($resourceObject[self::LINKS])) {
         return;
     } elseif (!is_array($resourceObject[self::LINKS])) {
         throw new ParseException(self::ERROR_LINKS_TYPE);
     }
     $metadata = $this->mm->mine($params->primaryClass);
     foreach ($resourceObject[self::LINKS] as $relationship => &$ids) {
         if (is_array($ids)) {
             if (!$metadata->isToManyRelationship($relationship)) {
                 $message = sprintf(self::ERROR_LINKS_CONTENT, $relationship);
                 throw new ParseException($message);
             }
             $class = $metadata->relationships->toMany[$relationship]->class;
             $ids = $this->em->getRepository($class)->findById($ids);
         } elseif (is_string($ids)) {
             if (!$metadata->isToOneRelationship($relationship)) {
                 $message = sprintf(self::ERROR_LINKS_CONTENT, $relationship);
                 throw new ParseException($message);
             }
             $class = $metadata->relationships->toOne[$relationship]->class;
             $ids = $this->em->getRepository($class)->findOneById($ids);
         } elseif (!is_null($ids)) {
             $message = sprintf(self::ERROR_LINKS_CONTENT_TYPE, $relationship);
             throw new ParseException($message);
         }
     }
 }
 public function getFreeWorkTimes(User $user, \DateTime $date = null)
 {
     $allTimes = [];
     //if($date)
     //{
     $startTime = new \DateTime($date->format('Y-m-d H:i'));
     $endTime = new \DateTime($date->format('Y-m-d H:i'));
     $startTime->setTime($user->getStartTime()->format('H'), $user->getStartTime()->format('i'));
     $endTime->setTime($user->getEndTime()->format('H'), $user->getEndTime()->format('i'));
     //}else
     //{
     //    $startTime = new \DateTime($user->getStartTime()->format('H:i'));
     //    $endTime = new \DateTime($user->getEndTime()->format('H:i'));
     //}
     $busyTimes = $this->em->getRepository('WorkerBundle:WorkTime')->getUserBusyTimes($user->getId());
     while ($startTime < $endTime) {
         if ($startTime > new \DateTime()) {
             //    if ($date) {
             $allTimes[] = $startTime->format('Y-m-d H:i');
             //    } else {
             //          $allTimes[] = date('Y-m-d') . ' ' . $startTime->format('H:i');
             //   }
         }
         $startTime->modify('+1hour');
     }
     return $this->removeBlockedTimes($allTimes, $busyTimes);
 }
Esempio n. 20
0
 public function processDelete(ProcessHook $hook)
 {
     $repository = $this->entityManager->getRepository('CmfcmfMediaModule:HookedObject\\HookedObjectEntity');
     $hookedObject = $repository->getByHookOrCreate($hook);
     $this->entityManager->remove($hookedObject);
     $this->entityManager->flush();
 }
 /**
  * {@inheritdcoc}
  */
 public function getTresholds()
 {
     if (is_array($this->cachedTresholds)) {
         return $this->cachedTresholds;
     }
     return $this->cachedTresholds = $this->entitManager->getRepository($this->entityClass)->findAll();
 }
Esempio n. 22
0
 public function onRender(RendererEvent $event)
 {
     $renderer = $event->getRenderer();
     $content = $renderer->getObject();
     $links = $content->getParamValue('link');
     $link = ['url' => '', 'title' => 'Visit', 'target' => '_self'];
     if (!empty($links)) {
         $links = reset($links);
         if (isset($links['pageUid']) && !empty($links['pageUid'])) {
             $page = $this->entityManager->getRepository('BackBee\\CoreDomain\\NestedNode\\Page')->find($links['pageUid']);
             if ($page !== null) {
                 $link['url'] = $page->getUrl();
             }
         }
         if (empty($link['url']) && isset($links['url'])) {
             $link['url'] = $links['url'];
         }
         if (isset($links['title'])) {
             $link['title'] = $links['title'];
         }
         if (isset($links['target'])) {
             $link['target'] = $links['target'];
         }
     }
     $renderer->assign('link', $link);
 }
Esempio n. 23
0
 public function exists(SubscriberInterface $subscriber, $groupNames)
 {
     // subscriber has to be in ALL given groups to return true
     if ($this->getSubscriber($subscriber->getEmail()) === null) {
         return false;
     }
     $groupsSubscriberIsIn = $this->getSubscriber($subscriber->getEmail())->getGroup()->getValues();
     $subscriberGroupNames = [];
     /**
      * @var $group Group
      */
     foreach ($groupsSubscriberIsIn as $group) {
         $subscriberGroupNames[] = $group->getName();
     }
     foreach ($groupNames as $groupName) {
         $group = $this->manager->getRepository(Group::class)->findOneBy(['name' => $groupName]);
         if ($group === null) {
             return false;
         }
         if (!in_array($groupName, $subscriberGroupNames)) {
             return false;
         }
     }
     return true;
 }
 /**
  * @param Schema $schema
  */
 public function down(Schema $schema)
 {
     $rep = $this->em->getRepository('AnimeDbCatalogBundle:Genre');
     /* @var $genre Genre */
     foreach ($this->restore as $from => $to) {
         $genre = $rep->findOneBy(['name' => $from]);
         if (is_array($to)) {
             $genre->setName($to[1])->setTranslatableLocale('ru');
             $this->em->persist($genre);
             $this->em->flush($genre);
             $to = $to[0];
         }
         $genre->setName($to)->setTranslatableLocale('en');
         $this->em->persist($genre);
     }
     // new genre
     $genre = new Genre();
     $genre->setName('Mystery play')->setTranslatableLocale('en');
     $this->em->persist($genre);
     $this->em->flush();
     $genre->setName('Мистерия')->setTranslatableLocale('ru');
     $this->em->persist($genre);
     // rename russian
     $genre = $rep->findOneBy(['name' => 'History']);
     $genre->setName('История')->setTranslatableLocale('ru');
     $this->em->persist($genre);
     $genre = $rep->findOneBy(['name' => 'War']);
     $genre->setName('Война')->setTranslatableLocale('ru');
     $this->em->persist($genre);
     $this->em->flush();
 }
 /**
  * Deletes all the fixtures job
  */
 public function deleteJobs()
 {
     $jobs = $this->em->getRepository($this->container->getParameter('akeneo_batch.entity.job_instance.class'))->findBy(['type' => static::JOB_TYPE]);
     foreach ($jobs as $job) {
         $this->em->remove($job);
     }
     $this->em->flush();
 }
Esempio n. 26
0
 /**
  * @param $key
  * @return File
  * @throws \Exception
  */
 public function getMetadata($key)
 {
     $persistedFile = $this->entityManager->getRepository('FileStorageBundle:File')->find($key);
     if (!$persistedFile) {
         throw new FileNotFoundException('File not found');
     }
     return $persistedFile;
 }
 /**
  * @param User $user
  *
  * @return string
  */
 private function getLocale(User $user)
 {
     $settings = $this->em->getRepository(UserSettings::clazz())->findOneBy(array('user' => $user->getId()));
     if ($settings && $settings->getLanguage() && $settings->getLanguage()->getEnabled()) {
         return $settings->getLanguage()->getLocale();
     }
     return $this->defaultLocale;
 }
 /**
  * {@inheritDoc}
  *
  * @return void
  */
 public function run(EntityInterface $user)
 {
     $user->setActivationKey(base64_encode($this->secureRandom->nextBytes(24)));
     $user->setPassword($this->passwordEncoder->encodePassword($user->getPassword(), User::SALT));
     $user->setRegistrationDate(new \DateTime());
     $this->entityManager->getRepository(User::class)->add($user);
     $this->entityManager->flush();
 }
Esempio n. 29
0
 /**
  * dns_userテーブルよりhtpasswdワークファイルを生成する
  */
 private function generateTmpHtpasswd()
 {
     $entities = $this->em->getRepository(DnsUser::class)->findAll();
     $isFirst = true;
     foreach ($entities as $entity) {
         $this->execHtpasswdCommand($entity, $isFirst);
         $isFirst = false;
     }
 }
Esempio n. 30
0
 /**
  * {@inheritdoc}
  */
 public function getDataSource(array $configuration, Parameters $parameters)
 {
     if (!array_key_exists('class', $configuration)) {
         throw new \InvalidArgumentException('"class" must be configured.');
     }
     $repository = $this->entityManager->getRepository($configuration['class']);
     $queryBuilder = $repository->createQueryBuilder('o');
     return new DataSource($queryBuilder);
 }