getRepository() public method

Gets the repository for a document class.
public getRepository ( string $documentName ) : DocumentRepository
$documentName string The name of the Document.
return DocumentRepository The repository.
Beispiel #1
0
 /**
  * Implement loading data for pas-admin
  *
  * Use services with tag wealthbot_admin.pas_files_loader
  *
  * @param \DateTime $date
  * @param int $page
  * @return Array
  */
 public function load(\DateTime $date, $page = 0)
 {
     $tableData = array();
     $shortDate = $date->format('Y-m-d');
     $accounts = $this->mongoManager->getRepository('WealthbotAdminBundle:Portfolio')->findBy(array('importDate' => $shortDate));
     $advisorCodes = $this->em->getRepository('WealthbotRiaBundle:AdvisorCode')->findAll();
     $advisorByCode = array();
     foreach ($advisorCodes as $advisorCode) {
         $advisorByCode[$advisorCode->getName()] = $advisorCode->getRiaCompany()->getRia();
     }
     foreach ($accounts as $account) {
         $advisorCode = $account->getAdvisorId();
         $advisorName = '';
         if (array_key_exists($advisorCode, $advisorByCode)) {
             $advisorName = $advisorByCode[$advisorCode]->getRiaCompanyInformation()->getName();
         }
         $tableData[] = array('ria' => $advisorName, 'last_name' => $account->getLastName(), 'first_name' => $account->getFirstName(), 'acct_number' => $account->getAccountNumber(), 'type' => $account->getAccountType(), 'warning' => false);
     }
     //Find ALL accounts needs to be in this day, add it to list and mark by red color.
     $transferAccountDate = new \DateTime();
     $transferAccountDate->setTime(0, 0, 0);
     $transferAccountDate = $this->businessCalendar->addBusinessDays($transferAccountDate, -SystemAccount::DAYS_WAIT_TRANSFER_OR_ROLLOVER_ACCOUNT);
     $newAccountDate = new \DateTime();
     $newAccountDate->setTime(0, 0, 0);
     $newAccountDate = $this->businessCalendar->addBusinessDays($newAccountDate, -SystemAccount::DAYS_WAIT_NEW_ACCOUNT);
     /** @var SystemAccount[] $notAcceptedAccounts */
     $notAcceptedAccounts = $this->em->getRepository('WealthbotClientBundle:SystemAccount')->getMustBeAcceptedAlready($transferAccountDate, $newAccountDate);
     foreach ($notAcceptedAccounts as $account) {
         $advisorName = $account->getClient()->getRia()->getRiaCompanyInformation()->getName();
         $tableData[] = array('ria' => $advisorName, 'last_name' => $account->getClient()->getLastName(), 'first_name' => $account->getClient()->getFirstName(), 'acct_number' => $account->getAccountNumber(), 'type' => $account->getType(), 'warning' => true);
     }
     return array('data' => $tableData);
 }
 /**
  * @param mixed $credentials
  * @param UserProviderInterface $userProvider
  * @return null|object
  */
 public function getUser($credentials, UserProviderInterface $userProvider)
 {
     $apiKey = $credentials['token'];
     // if null, authentication will fail
     // if a User object, checkCredentials() is called
     return $this->dm->getRepository('Documents:User')->findOneBy(array('apiKey' => $apiKey));
 }
 /**
  * @return \Doctrine\ODM\MongoDB\DocumentRepository
  */
 public function getPageVisitRepository()
 {
     if (!$this->pageVisitRepo) {
         $this->pageVisitRepo = $this->dm->getRepository('Soil\\UserTrackBundle\\Entity\\PageVisit');
     }
     return $this->pageVisitRepo;
 }
Beispiel #4
0
 /**
  * Get single invoice by Id
  *
  * @param int $id
  *
  * @return Invoice $invoice
  *
  * @throws LogicException
  */
 public function getInvoice($id)
 {
     $invoice = $this->dm->getRepository('Aisel\\OrderBundle\\Document\\Invoice')->find($id);
     if (!$invoice) {
         throw new LogicException('Nothing found');
     }
     return $invoice;
 }
Beispiel #5
0
 /**
  * @param string $id
  * @return Folder
  */
 private function getFolder($id)
 {
     $folder = $this->dm->getRepository('App\\Documents\\Folder')->find($id);
     if (!$folder) {
         throw new \RuntimeException('Missing test data!');
     }
     return $folder;
 }
 /**
  * {@inheritDoc}
  */
 public function find($id)
 {
     $image = $this->dm->getRepository($this->class)->findAll()->getCollection()->findOne(array("_id" => new \MongoId($id)));
     if (!$image) {
         throw new NotFoundHttpException(sprintf('Source image not found with id "%s"', $id));
     }
     return $this->imagine->load($image['file']->getBytes());
 }
 /**
  * {@inheritDoc}
  */
 public function find($id)
 {
     $image = $this->dm->getRepository($this->class)->find(new \MongoId($id));
     if (!$image) {
         throw new NotLoadableException(sprintf('Source image was not found with id "%s"', $id));
     }
     return $image['file']->getBytes();
 }
Beispiel #8
0
 /**
  * Get list of results
  *
  * @param array $params
  *
  * @return array $return
  */
 public function search($params)
 {
     $pageRepository = $this->dm->getRepository('AiselPageBundle:Page');
     $total = $pageRepository->getTotalFromRequest($params);
     $collection = $pageRepository->searchFromRequest($params);
     $return = array('total' => $total, 'collection' => $collection);
     return $return;
 }
Beispiel #9
0
 public function getOne($id) : ImageInterface
 {
     $image = $this->dm->getRepository(Image::class)->find($id);
     if (!$image) {
         throw new \Exception('Image not found', 404);
     }
     return $image;
 }
Beispiel #10
0
 /**
  * {@inheritdoc}
  */
 public function get($id, $grantType = null, $clientId = null)
 {
     /** @var Scope $scope */
     $scope = $this->dm->getRepository(Scope::class)->find($id);
     if ($scope === null) {
         return null;
     }
     return (new ScopeEntity($this->server))->hydrate(['id' => $scope->getId(), 'description' => $scope->getDescription()]);
 }
Beispiel #11
0
 /**
  * {@inheritdoc}
  */
 public function getBySession(SessionEntity $sessionEntity)
 {
     /** @var Session $session */
     $session = $this->dm->getRepository(Session::class)->find($sessionEntity->getId());
     if ($session && $session->getClientId() === $this->clientId) {
         return (new ClientEntity($this->server))->hydrate(['id' => $this->clientId]);
     }
     return null;
 }
Beispiel #12
0
 /**
  * @param $id
  * @param $entity
  * @return string
  */
 private function getDownloadStat($id, $entity)
 {
     /** @var ObjectView $data */
     $data = $this->dm->getRepository('OjsAnalyticsBundle:ObjectDownload')->findOneBy(['objectId' => "{$id}", 'entity' => $entity]);
     if (!$data) {
         return 0;
     }
     return $data->getTotal();
 }
Beispiel #13
0
 public function remove($key)
 {
     $cache = $this->dm->getRepository('SGLiveChatBundle:CacheEntry')->getByKey($key);
     if ($cache) {
         $this->dm->remove($cache);
     }
     $this->dm->flush();
     return true;
 }
 /**
  * @return array
  */
 protected function getDuplications()
 {
     if (is_null($this->duplications)) {
         $duplications = $this->dm->getRepository($this->documentClass)->findAll();
         /*@var $duplications DuplicableInterface[]*/
         $this->duplications = [];
         foreach ($duplications as $duplicate) {
             $this->duplications[] = $duplicate->getUniqueKey();
         }
     }
     return $this->duplications;
 }
Beispiel #15
0
 /**
  * Test Protocol Document
  * @depends testForm
  * @param Form $form
  */
 public function testProtocol(Form $form)
 {
     $formRepo = $this->documentManager->getRepository('FormBundle:Form');
     $formObj = $formRepo->find($form->getId());
     $protocol = new Protocol();
     $protocol->setForm($formObj);
     $protocol->setFirstSaveDate(new \MongoDate());
     $protocol->setLastSaveDate(new \MongoDate());
     $protocol->setConclusion('Conclusion');
     $file = new ProtocolFile();
     $upload = new UploadedFile(__FILE__, get_class());
     $file->setFile($upload);
     $file->setTitle('file_title');
     $file->setDescription('file_description');
     $file->setFilename($upload->getClientOriginalName());
     $file->setMimeType($upload->getClientMimeType());
     $file->setUploadDate(new \MongoDate());
     $file->setLength($upload->getSize());
     $file->setMd5('123');
     $file->setChunkSize(123);
     $file->setProtocol($protocol);
     $protocol->addFile($file);
     // Comment, User and NonUser are tested on ProtocolControllerTest
     $this->documentManager->persist($file);
     $this->documentManager->persist($protocol);
     $this->documentManager->flush();
     //        $this->documentManager->clear();
     $protocol = $this->documentManager->getRepository('FormBundle:Protocol')->find($protocol->getId());
     $this->assertNotEmpty($protocol->getId());
     $this->assertNotEmpty($protocol->getCreatedAt());
     $this->assertNotEmpty($protocol->getFirstSaveDate());
     $this->assertNotEmpty($protocol->getLastSaveDate());
     $this->assertNotEmpty($protocol->getForm());
     $this->assertEquals('Conclusion', $protocol->getConclusion());
     $this->assertTrue($protocol->getForm() instanceof Form);
     $this->assertEmpty($protocol->getOneComment('fake_123'));
     // Testing ProtocolFile
     //        $this->assertInstanceOf(get_class(new ArrayCollection()), $protocol->getFile());
     /** @var ProtocolFile $protocolFile */
     $protocolFile = $protocol->getFile()->first();
     $this->assertEquals('file_title', $protocolFile->getTitle());
     $this->assertEquals('file_description', $protocolFile->getDescription());
     $this->assertNotNull($protocolFile->getUploadDate());
     $this->assertNotNull($protocolFile->getLength());
     $this->assertNotNull($protocolFile->getChunkSize());
     $this->assertNotNull($protocolFile->getMd5());
     $protocol->removeFile($file);
     $this->documentManager->remove($protocol);
     $this->documentManager->remove($formObj);
     $this->documentManager->flush();
 }
Beispiel #16
0
 /**
  * @param \JMS\Serializer\JsonDeserializationVisitor $visitor
  * @param string $model
  * @param array $type
  * @return mixed
  */
 public function deserializeModelFromJson(JsonDeserializationVisitor $visitor, $model, array $type)
 {
     if ($model && count($type['params'])) {
         if (!$this->documentManager) {
             throw new \Staffim\DTOBundle\Exception\Exception('You should set document manager for using document auto-fetching.');
         }
         $className = $type['params'][0]['name'];
         $object = $this->documentManager->getRepository($className)->find($model);
         if (!$object) {
             throw new \Staffim\DTOBundle\Exception\ObjectNotFoundException($className, $model);
         }
     }
     return $object;
 }
Beispiel #17
0
 /**
  * Разбор xml и сохранение в базу данных
  * @return $this
  */
 public function parse()
 {
     $this->_dm = $this->getServiceLocator()->get('doctrine-document');
     $this->_repository = $this->_dm->getRepository($this->_document);
     if (isset($this->_xml->Valute)) {
         /** @var \SimpleXMLElement $item */
         foreach ($this->_xml->Valute as $item) {
             if (isset($item->CharCode)) {
                 $this->save((string) $item->CharCode, $item);
             }
         }
     }
     $this->_dm->flush();
     return $this;
 }
Beispiel #18
0
 /**
  * @param PersistentCollection $collection
  *
  * @return CursorInterface
  */
 public function createReferenceManyWithRepositoryMethodCursor(PersistentCollection $collection)
 {
     $hints = $collection->getHints();
     $mapping = $collection->getMapping();
     $repositoryMethod = $mapping['repositoryMethod'];
     $cursor = $this->dm->getRepository($mapping['targetDocument'])->{$repositoryMethod}($collection->getOwner());
     if (!$cursor instanceof CursorInterface) {
         throw new \BadMethodCallException("Expected repository method {$repositoryMethod} to return a CursorInterface");
     }
     if (isset($mapping['sort'])) {
         $cursor->sort($mapping['sort']);
     }
     if (isset($mapping['limit'])) {
         $cursor->limit($mapping['limit']);
     }
     if (isset($mapping['skip'])) {
         $cursor->skip($mapping['skip']);
     }
     if (!empty($hints[Query::HINT_SLAVE_OKAY])) {
         $cursor->slaveOkay(true);
     }
     if (!empty($hints[Query::HINT_READ_PREFERENCE])) {
         $cursor->setReadPreference($hints[Query::HINT_READ_PREFERENCE], $hints[Query::HINT_READ_PREFERENCE_TAGS]);
     }
     return $cursor;
 }
 /**
  * @param array $criteria
  * @param integer $page
  *
  * @return \Sonata\AdminBundle\Datagrid\ODM\Pager
  */
 public function getPager(array $criteria, $page)
 {
     $parameters = array();
     $qb = $this->dm->getRepository($this->class)->createQueryBuilder()->sort('createdAt', 'desc');
     $criteria['status'] = isset($criteria['status']) ? $criteria['status'] : CommentInterface::STATUS_VALID;
     $qb->field('status')->equals($criteria['status']);
     if (isset($criteria['postId'])) {
         $qb->field('post')->equals($criteria['postId']);
     }
     $pager = new Pager(500);
     // no limit
     $pager->setQuery(new ProxyQuery($qb));
     $pager->setPage($page);
     $pager->init();
     return $pager;
 }
 /**
  * @param PersistentCollection $collection
  *
  * @return Cursor|EagerCursor
  */
 public function createReferenceManyWithRepositoryMethodCursor(PersistentCollection $collection)
 {
     $hints = $collection->getHints();
     $mapping = $collection->getMapping();
     $cursor = $this->dm->getRepository($mapping['targetDocument'])->{$mapping}['repositoryMethod']($collection->getOwner());
     $wrappedCursor = $cursor;
     if ($cursor instanceof EagerCursor) {
         $wrappedCursor = $cursor->getCursor();
     }
     if (isset($mapping['sort'])) {
         $wrappedCursor->sort($mapping['sort']);
     }
     if (isset($mapping['limit'])) {
         $wrappedCursor->limit($mapping['limit']);
     }
     if (isset($mapping['skip'])) {
         $wrappedCursor->skip($mapping['skip']);
     }
     if (!empty($hints[Query::HINT_SLAVE_OKAY])) {
         $wrappedCursor->slaveOkay(true);
     }
     if (!empty($hints[Query::HINT_READ_PREFERENCE])) {
         $wrappedCursor->setReadPreference($hints[Query::HINT_READ_PREFERENCE], $hints[Query::HINT_READ_PREFERENCE_TAGS]);
     }
     return $cursor;
 }
 /**
  * @param $date
  * @param $lineNumber
  * @param $from
  * @param $to
  * @param $lineDeparture
  * @return int|mixed
  */
 public function getCapacity($date, $lineNumber, $from, $to, $lineDeparture)
 {
     /** @var null|Trip $trip */
     $trip = $this->documentManager->getRepository('AppBundle:Trip')->findOneBy(['date' => $date, 'lineNumber' => (int) $lineNumber, 'departure' => (int) $lineDeparture]);
     $capacity = $trip ? $trip->getAvailableCapacity($from, $to) : $this->trainInformation->getCapacity();
     return $capacity;
 }
Beispiel #22
0
 /**
  * Update parent for Node
  *
  * @param  array $params
  * @return Category $child
  *
  * @throws LogicException
  */
 public function updateParent($params)
 {
     /**
      * @var $child Category
      * @var $parent Category
      */
     $repo = $this->dm->getRepository($this->model);
     if ($categoryParentId = $params['parentId']) {
         $parent = $repo->find($categoryParentId);
         if (!$parent) {
             throw new LogicException('Nothing found');
         }
     }
     if ($categoryId = $params['id']) {
         $child = $repo->find($categoryId);
         if (!$child) {
             throw new LogicException('Nothing found');
         }
     }
     $child->setParent($parent);
     $this->dm->persist($child);
     $this->dm->flush();
     $parent->removeChild($child);
     $parent->addChild($child);
     $this->dm->persist($parent);
     $this->dm->flush();
     return $child;
 }
Beispiel #23
0
 /**
  * Initializes the choices and returns them
  *
  * The choices are generated from the documents.
  *
  * If the documents were passed in the "choices" option, this method
  * does not have any significant overhead. Otherwise, if a query builder
  * was passed in the "query_builder" option, this builder is now used
  * to construct a query which is executed. In the last case, all documents
  * for the underlying class are fetched from the repository.
  *
  * If the option "property" was passed, the property path in that option
  * is used as option values. Otherwise this method tries to convert
  * objects to strings using __toString().
  *
  * @return array  An array of choices
  */
 protected function load()
 {
     parent::load();
     if ($this->choices) {
         $documents = $this->choices;
     } else {
         if ($queryBuilder = $this->queryBuilder) {
             $documents = $queryBuilder->getQuery()->execute();
         } else {
             $documents = $this->documentManager->getRepository($this->class)->findAll();
         }
     }
     $this->choices = array();
     $this->documents = array();
     foreach ($documents as $key => $document) {
         if ($this->propertyPath) {
             // If the property option was given, use it
             $value = $this->propertyPath->getValue($document);
         } else {
             // Otherwise expect a __toString() method in the document
             $value = $document->__toString();
         }
         $id = $this->getIdentifierValue($document);
         $this->choices[$id] = $value;
         $this->documents[$id] = $document;
     }
 }
 /**
  * Constructor.
  *
  * @param DocumentManager         $dm
  * @param string                  $class
  * @param SortingFactory          $factory
  */
 public function __construct(DocumentManager $dm, $class, SortingFactory $factory)
 {
     $this->dm = $dm;
     $this->repository = $dm->getRepository($class);
     $this->class = $dm->getClassMetadata($class)->name;
     $this->setSortingFactory($factory);
 }
 function let(DocumentManager $manager, ChannelInterface $ecommerce, ChannelInterface $mobile, LocaleInterface $enUs, LocaleInterface $frFr, CategoryInterface $category, ChannelManager $channelManager, CategoryRepositoryInterface $categoryRepository, ProductRepository $productRepository, QueryBuilder $ormQb, Builder $odmQb, Query $odmQuery, Cursor $cursor)
 {
     $enUs->getCode()->willReturn('en_US');
     $frFr->getCode()->willReturn('fr_FR');
     $ecommerce->getCode()->willReturn('ecommerce');
     $ecommerce->getLabel()->willReturn('ECommerce');
     $ecommerce->getLocales()->willReturn(array($enUs, $frFr));
     $ecommerce->getCategory()->willReturn($category);
     $mobile->getCode()->willReturn('mobile');
     $mobile->getLabel()->willReturn('Mobile');
     $mobile->getLocales()->willReturn(array($enUs));
     $mobile->getCategory()->willReturn($category);
     $odmQuery->execute()->willReturn($cursor);
     $productRepository->createQueryBuilder()->willReturn($odmQb);
     $odmQb->hydrate(Argument::any())->willReturn($odmQb);
     $odmQb->field(Argument::any())->willReturn($odmQb);
     $odmQb->in(Argument::any())->willReturn($odmQb);
     $odmQb->equals(Argument::any())->willReturn($odmQb);
     $odmQb->select('_id')->willReturn($odmQb);
     $odmQb->getQuery()->willReturn($odmQuery);
     $categoryRepository->getAllChildrenQueryBuilder($category, true)->willReturn($ormQb);
     $categoryRepository->getCategoryIds($category, $ormQb)->willReturn(array(1, 2, 3));
     $channelManager->getFullChannels()->willReturn(array($ecommerce, $mobile));
     $manager->getRepository('pim_product_class')->willReturn($productRepository);
     $this->beConstructedWith($manager, $channelManager, $categoryRepository, 'pim_product_class');
 }
 /**
  * Return list of resources
  *
  * @return mixed
  */
 public function getList()
 {
     $users = $this->dm->getRepository('User\\Document\\User')->findAll();
     if (is_array($users)) {
         foreach ($users as $user) {
             $reflect = new \ReflectionObject($user);
             $props = $reflect->getProperties(\ReflectionProperty::IS_PROTECTED);
             $props_array = array();
             foreach ($props as $prop) {
                 if ($prop->getName() == "password") {
                     continue;
                 } elseif ($user[$prop->getName()] instanceof PersistentCollection) {
                     foreach ($user[$prop->getName()] as $obj) {
                         $props_array[$prop->getName()]['Ref'][]['id'] = $obj['id'];
                     }
                 } else {
                     $props_array[$prop->getName()] = $user[$prop->getName()];
                 }
             }
             $collectionArray['collection'][] = $props_array;
         }
         /**/
         return new JsonModel($collectionArray);
     } else {
         return new JsonModel(['Error' => ['message' => 'Invalid User Id!']]);
     }
 }
Beispiel #27
0
 /**
  * @param  Journal $journal
  * @return array
  */
 public function journalsArticlesStats(Journal $journal)
 {
     $object_view = $this->dm->getRepository('OjsAnalyticsBundle:ObjectViews');
     $stats = [];
     $affetted_articles = [];
     foreach ($journal->getArticles() as $article) {
         $articleStats = $object_view->findBy(['entity' => 'article', 'objectId' => $article->getId()]);
         if (!$articleStats) {
             continue;
         }
         foreach ($articleStats as $stat) {
             $dateKey = $stat->getLogDate()->format("d-M-Y");
             $stats[$dateKey][$article->getId()] = ['hit' => isset($stats[$dateKey][$article->getId()]['hit']) ? $stats[$dateKey][$article->getId()]['hit'] + 1 : 1, 'title' => $article->getTitle()];
         }
         $affetted_articles[] = ['id' => $article->getId(), 'title' => $article->getTitle()];
     }
     foreach ($stats as $date => $stat) {
         foreach ($affetted_articles as $article) {
             if (!isset($stats[$date][$article['id']])) {
                 $stats[$date][$article['id']] = ['hit' => 0, 'title' => $article['title']];
             }
         }
     }
     ksort($stats);
     return ['stats' => $stats, 'articles' => $affetted_articles];
 }
Beispiel #28
0
 public function __construct(DocumentManager $dm, $class)
 {
     $this->dm = $dm;
     $this->repository = $dm->getRepository($class);
     $metadata = $dm->getClassMetadata($class);
     $this->class = $metadata->name;
 }
Beispiel #29
0
 /**
  * Constructor.
  *
  * @param EncoderFactoryInterface $encoderFactory
  * @param string                  $algorithm
  * @param CanonicalizerInterface  $usernameCanonicalizer
  * @param CanonicalizerInterface  $emailCanonicalizer
  * @param DocumentManager         $dm
  * @param string                  $class
  */
 public function __construct(EncoderFactoryInterface $encoderFactory, $algorithm, CanonicalizerInterface $usernameCanonicalizer, CanonicalizerInterface $emailCanonicalizer, DocumentManager $dm, $class)
 {
     parent::__construct($encoderFactory, $algorithm, $usernameCanonicalizer, $emailCanonicalizer);
     $this->dm = $dm;
     $this->repository = $dm->getRepository($class);
     $metadata = $dm->getClassMetadata($class);
     $this->class = $metadata->name;
 }
 /**
  * Constructor.
  *
  * @param DocumentManager $dm
  * @param string          $class
  * @param string          $metaClass
  * @param MessageManager  $messageManager
  */
 public function __construct(DocumentManager $dm, $class, $metaClass, MessageManager $messageManager)
 {
     $this->dm = $dm;
     $this->repository = $dm->getRepository($class);
     $this->class = $dm->getClassMetadata($class)->name;
     $this->metaClass = $dm->getClassMetadata($metaClass)->name;
     $this->messageManager = $messageManager;
 }