This class is designed for inheritance and users can subclass this class to write their own repositories with business-specific methods to locate documents.
Since: 1.0
Author: Jonathan H. Wage (jonwage@gmail.com)
Author: Roman Borschel (roman@code-factory.org)
Inheritance: implements Doctrine\Common\Persistence\ObjectRepository, implements Doctrine\Common\Collections\Selectable
示例#1
0
 public function findVisible($owner)
 {
     if (!$owner instanceof UserInterface) {
         return array();
     }
     $qb = $this->repo->createQueryBuilder()->field('owner.$id')->equals(new \MongoId($owner->getId()))->field('visibility')->equals(CalendarInterface::VISIBILITY_PUBLIC);
     return $qb->getQuery()->execute();
 }
示例#2
0
 public function loadUserByUsername($username)
 {
     /* @var $user UserDocument  */
     $user = $this->repository->findOneByUsername($username);
     if (!$user) {
         throw new UsernameNotFoundException();
     }
     return new User($user->getUsername(), $user->getPassword(), $user->getRoles());
 }
 /**
  * Performs an authentication
  * @param  array
  * @return Nette\Security\Identity
  * @throws Nette\Security\AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     list($email, $password) = $credentials;
     $user = $this->adminRepository->findOneBy(['email' => $email]);
     if (!$user or !$this->passwordHasher->checkPassword($password, $user->getPassword())) {
         throw new NS\AuthenticationException("Invalid credentials", self::FAILURE);
     }
     return $user;
 }
示例#4
0
 /**
  * @return DomainEvent[]
  */
 public function getAll()
 {
     $events = [];
     /** @var $storedEvent StoredEvent */
     $storedEvents = $this->repository->findAll();
     foreach ($storedEvents as $storedEvent) {
         $events[] = $storedEvent->getEvent();
     }
     return $events;
 }
 /**
  * @param LifecycleEventArgs $args
  */
 public function postPersist(LifecycleEventArgs $args)
 {
     $document = $args->getDocument();
     if (!$document instanceof Event) {
         return;
     }
     $location = $document->getPlace()->getLocation();
     $subscribers = $this->subscriberRepository->createQueryBuilder()->field('location')->near((double) $location->getLongitude(), (double) $location->getLatitude())->maxDistance(5 / 111.12)->getQuery()->execute();
     foreach ($subscribers as $subscriber) {
         $body = $this->templating->render('ApiBundle:Email:subscriber.html.twig', ['event' => $document]);
         $message = \Swift_Message::newInstance()->setSubject('Ping - New event on you area !')->setFrom('*****@*****.**')->setTo($subscriber->getEmail())->setBody($body, 'text/html');
         $this->mailer->send($message);
     }
 }
 /**
  * {@inheritDoc}
  * @see \Rhapsody\SocialBundle\Doctrine\ActivityManagerInterface::findActivityBySource()
  */
 public function findActivityBySource($sources = array(), $date = null, $limit = 50)
 {
     if (empty($date)) {
         $date = new \DateTime();
     }
     return $this->repository->findAllBySource($sources, $date, $limit);
 }
 /**
  * @return \Cubiche\Infrastructure\Repository\Doctrine\ODM\MongoDB\DocumentDataSource
  */
 protected function documentDataSource()
 {
     if ($this->documentDataSource === null) {
         $this->documentDataSource = $this->documentDataSourceFactory->create($this->repository->getDocumentName());
     }
     return $this->documentDataSource;
 }
 /**
  * {@inheritdoc}
  */
 public function __construct(DocumentManager $dm, UnitOfWork $uow, ClassMetadata $class)
 {
     if ($class->getReflectionClass()->isSubclassOf('Gedmo\\Translatable\\Document\\MappedSuperclass\\AbstractPersonalTranslation')) {
         throw new \Gedmo\Exception\UnexpectedValueException('This repository is useless for personal translations');
     }
     parent::__construct($dm, $uow, $class);
 }
示例#9
0
 public function findOneById($id)
 {
     if (strlen($id) == 24) {
         $user = parent::findOneById($id);
     } else {
         $user = parent::findOneBy(array("username" => $id));
     }
     return $user;
 }
 protected function init(Request $request)
 {
     $this->request = $request;
     $this->baseUrl = 'http://' . $this->request->getHost() . $this->request->getBaseUrl() . $this->request->getPathInfo();
     $this->manager = $this->get('doctrine_mongodb')->getManager();
     $this->repository = $this->manager->getRepository('AppBundle:UserEvent');
     $this->queryBuilder = $this->repository->createQueryBuilder();
     $this->dbCount = $this->queryBuilder->getQuery()->execute()->count();
 }
示例#11
0
 public function findOneById($id)
 {
     if (is_numeric($id)) {
         $item = parent::findOneBy(array("rdbms_id" => $id));
     } else {
         $item = parent::findOneById($id);
     }
     return $item;
 }
示例#12
0
 public function findOneById($id)
 {
     $qb = $this->createQueryBuilder('Project');
     if (strlen($id) == 24) {
         $project = parent::findOneById($id);
     } else {
         $project = parent::findOneBy(array("publicId" => $id));
     }
     return $project;
 }
 /**
  * @param string $field
  * @return string
  */
 private function getField($field)
 {
     if ($this->fields === null) {
         $dm = $this->repository->getDocumentManager();
         /** @todo Investigate if produces performance problems */
         $entityMeta = $dm->getClassMetadata($this->repository->getDocumentName());
         foreach ($entityMeta->fieldMappings as $fieldName => $fieldMapping) {
             $this->fields[$fieldMapping['name']] = $fieldName;
         }
     }
     return isset($this->fields[$field]) ? $this->fields[$field] : $field;
 }
 /**
  * {@inheritdoc}
  */
 public function __construct(DocumentManager $em, UnitOfWork $uow, ClassMetadata $class)
 {
     parent::__construct($em, $uow, $class);
     $treeListener = null;
     foreach ($em->getEventManager()->getListeners() as $listeners) {
         foreach ($listeners as $listener) {
             if ($listener instanceof \Gedmo\Tree\TreeListener) {
                 $treeListener = $listener;
                 break;
             }
         }
         if ($treeListener) {
             break;
         }
     }
     if (is_null($treeListener)) {
         throw new \Gedmo\Exception\InvalidMappingException('This repository can be attached only to ODM MongoDB tree listener');
     }
     $this->listener = $treeListener;
     if (!$this->validate()) {
         throw new \Gedmo\Exception\InvalidMappingException('This repository cannot be used for tree type: ' . $treeListener->getStrategy($em, $class->name)->getName());
     }
 }
示例#15
0
 /**
  * @param \Doctrine\ODM\MongoDB\DocumentManager $dm
  * @param \Doctrine\ODM\MongoDB\UnitOfWork $uow
  * @param \Doctrine\ODM\MongoDB\Mapping\ClassMetadata $classMetadata
  */
 public function __construct($dm, $uow, $classMetadata)
 {
     parent::__construct($dm, $uow, $classMetadata);
     $this->builder = new PhotoFactory();
 }
示例#16
0
 /**
  * @param $projectionName
  * @param AggregateId $aggregateId
  * @return Projection
  */
 public function findById($projectionName, AggregateId $aggregateId)
 {
     $storedProjection = $this->repository->findOneBy(['projectionName' => (string) $projectionName, 'aggregateId' => (string) $aggregateId]);
     return empty($storedProjection) ? null : $storedProjection->getProjection();
 }
 /**
  * (non-PHPDoc)
  * @see Rhapsody\SocialBundle\Doctrine\TopicManagerInterface::search()
  */
 public function search($query, $paginate = true)
 {
     return $this->repository->search($query, $paginate);
 }
 /**
  * {@inheritdoc}
  */
 public function deleteExpired()
 {
     $result = $this->repository->createQueryBuilder()->remove()->field('expiresAt')->lt(time())->getQuery(array('safe' => true))->execute();
     return $result['n'];
 }
示例#19
0
 /**
  * Populate the DocumentRepository $repo with $count documents.
  *
  * @see \Population\Populator::populate
  *
  * @access public
  * @param DocumentRepository $repo
  * @param int $count
  * @param callable $callback Function which populates the data for each instance. It is passed a single argument,
  *     the document to be populated. If $callback returns false, the document will not be persisted.
  * @param array $options (default: array())
  *     perFlush:        Limit the number of insertions performed in a single flush (default: 100)
  *     clearAfterFlush: Clear the DocumentManager after each flush (default:true)
  *     factory:         Optionally, specify a factory callback for populated objects
  *     constructorArgs: An array of args, passed directly to the document's constructor (default: null)
  * @return void
  */
 public function populateDocument(DocumentRepository $repo, $count, $callback, array $options = array())
 {
     $dm = $repo->getDocumentManager();
     if (isset($options['factory'])) {
         $factory = $options['factory'];
     } else {
         $reflClass = $repo->getClassMetadata()->reflClass;
         $factory = array($reflClass, 'newInstanceArgs');
     }
     $this->populateObject($dm, $factory, $count, $callback, $options);
 }
 /**
  * Repository constructor overridden to reuse field maps
  * Initializes a new <tt>DocumentRepository</tt>.
  *
  * @param DocumentManager $dm            The DocumentManager to use.
  * @param UnitOfWork      $uow           The UnitOfWork to use.
  * @param ClassMetadata   $classMetadata The class descriptor.
  */
 public function __construct(DocumentManager $dm, UnitOfWork $uow, ClassMetadata $classMetadata)
 {
     parent::__construct($dm, $uow, $classMetadata);
     $this->orderByFields = array_merge($this->orderByFields, $this->orderByRelationFields);
     $this->filterByFields = $this->orderByFields;
 }
示例#21
0
 /**
  * Try to find similar resources
  *
  * @param \Bpi\ApiBundle\Domain\Repository\ResourceRepository $repository
  * @return array
  */
 public function findSimilar(\Doctrine\ODM\MongoDB\DocumentRepository $repository)
 {
     // @todo replace with query
     return $repository->findOneBy(array('resource.hash' => $this->hash, 'deleted' => false));
 }
示例#22
0
 /**
  * {@inheritdoc}
  */
 public function findClientBy(array $criteria)
 {
     return $this->repository->findOneBy($criteria);
 }
 /**
  * (non-PHPDoc)
  * @see Rhapsody\SocialBundle\Doctrine\PostManagerInterface::search()
  */
 public function search($query)
 {
     return $this->repository->search($query);
 }
示例#24
0
 /**
  * @Rest\View
  *
  * @return array
  */
 public function cgetAction()
 {
     return $this->repository->findAll();
 }
示例#25
0
 public function findByRiaQuery(User $ria, $limit = null)
 {
     $qb = $this->repository->createQueryBuilder()->field('riaUserId')->equals($ria->getId())->field('isShowRia')->equals(true)->limit($limit)->sort('createdAt', 'desc');
     return $qb->getQuery();
 }
示例#26
0
 /**
  * @param DocumentManager   $dm
  * @param UnitOfWork        $uow
  * @param ClassMetadata     $class
  * @param ResourceInterface $resource
  */
 public function __construct(DocumentManager $dm, UnitOfWork $uow, ClassMetadata $class, ResourceInterface $resource)
 {
     parent::__construct($dm, $uow, $class);
     $this->resource = $resource;
 }
 /**
  * (non-PHPDoc)
  * @see Rhapsody\SocialBundle\Doctrine\SocialContextManagerInterface::findById()
  */
 public function findById($id)
 {
     return $this->repository->findById($id);
 }
 public function __construct(ODM\DocumentManager $dm, ODM\UnitOfWork $uow, ODM\Mapping\ClassMetadata $class)
 {
     parent::__construct($dm, $uow, $class);
     $eventArgs = new DoctrineMongoODM\Event\EventArgs(array('repository' => $this));
     $dm->getEventManager()->dispatchEvent(DoctrineMongoODM\Event\RepositoryEventsSubscriber::postConstruct, $eventArgs);
 }
 /**
  * @expectedException \Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException
  */
 public function testFindWithInValidDocument()
 {
     $this->repo->expects($this->atLeastOnce())->method('find')->with($this->isInstanceOf('\\MongoId'))->will($this->returnValue(null));
     $this->loader->find('0123456789abcdef01234567');
 }
 /**
  * {@inheritdoc}
  */
 public function findMappedStatements(array $criteria)
 {
     return parent::findBy($criteria);
 }