Author: Paweł Jędrzejewski (pawel@sylius.org)
Inheritance: extends Doctrine\ORM\EntityRepository, implements Sylius\Component\Resource\Repository\RepositoryInterface
 function it_generates_an_order_number_when_sequence_is_null(EntityRepository $sequenceRepository, FactoryInterface $sequenceFactory, OrderSequenceInterface $sequence, OrderInterface $order)
 {
     $sequence->getIndex()->willReturn(0);
     $sequenceRepository->findOneBy([])->willReturn(null);
     $sequenceFactory->createNew()->willReturn($sequence);
     $sequenceRepository->add($sequence)->shouldBeCalled();
     $sequence->incrementIndex()->shouldBeCalled();
     $this->generate($order)->shouldReturn('000000001');
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function removeReviewerReviews(ReviewerInterface $author)
 {
     $reviewSubjectsToRecalculate = [];
     foreach ($this->reviewRepository->findBy(['author' => $author]) as $review) {
         $reviewSubjectsToRecalculate = $this->removeReviewsAndExtractSubject($review, $reviewSubjectsToRecalculate);
     }
     $this->reviewManager->flush();
     foreach ($reviewSubjectsToRecalculate as $reviewSubject) {
         $this->averageRatingUpdater->update($reviewSubject);
     }
 }
示例#3
0
 /**
  * @param mixed $id
  *
  * @return null|object
  */
 public function find($id)
 {
     if (is_array($id)) {
         $id = current($id);
     }
     return parent::find($id);
 }
 /**
  * {@inheritdoc}
  */
 protected function getPropertyName($name)
 {
     if (in_array($name, $this->translatableFields)) {
         return 'translation.' . $name;
     }
     return parent::getPropertyName($name);
 }
示例#5
0
 /**
  * @param array $criteria
  * @param array $sorting
  * @param bool  $deleted
  *
  * @return Pagerfanta
  */
 public function createFilterPaginator($criteria = array(), $sorting = array(), $deleted = false)
 {
     $queryBuilder = parent::getCollectionQueryBuilder()->leftJoin($this->getPropertyName('user'), 'user');
     if ($deleted) {
         $this->_em->getFilters()->disable('softdeleteable');
     }
     if (isset($criteria['query'])) {
         // Every tokenized search term should appear in at least one of the searchable fields,
         // for the entity to be included in the filtered results.
         $queryParts = preg_split('/\\s+/', $criteria['query']);
         for ($i = 0; $i < count($queryParts); $i++) {
             $queryBuilder->andWhere($queryBuilder->expr()->orX($queryBuilder->expr()->like($this->getPropertyName('emailCanonical'), ":query{$i}"), $queryBuilder->expr()->like($this->getPropertyName('firstName'), ":query{$i}"), $queryBuilder->expr()->like($this->getPropertyName('lastName'), ":query{$i}"), $queryBuilder->expr()->like('user.username', ":query{$i}")))->setParameter("query{$i}", '%' . $queryParts[$i] . '%');
         }
     }
     if (isset($criteria['enabled'])) {
         $queryBuilder->andWhere($queryBuilder->expr()->eq('user.enabled', ':enabled'))->setParameter('enabled', $criteria['enabled']);
     }
     if (empty($sorting)) {
         if (!is_array($sorting)) {
             $sorting = array();
         }
         $sorting['updatedAt'] = 'desc';
     }
     $this->applySorting($queryBuilder, $sorting);
     return $this->getPaginator($queryBuilder);
 }
 protected function applyCriteria(QueryBuilder $queryBuilder, array $criteria = null)
 {
     if (isset($criteria['groups'])) {
         $queryBuilder->innerJoin($this->getAlias() . '.machine', 'm', 'WITH', $this->getAlias() . '.machine = m.id')->innerJoin('m.groups', 'g', 'WITH', $queryBuilder->expr()->andX($queryBuilder->expr()->in('g.id', $criteria['groups'])));
         unset($criteria['groups']);
     }
     parent::applyCriteria($queryBuilder, $criteria);
 }
示例#7
0
 /**
  * @param array $criteria
  * @param array $sorting
  *
  * @return Pagerfanta
  */
 public function createFilterPaginator($criteria = [], $sorting = [])
 {
     $queryBuilder = parent::getCollectionQueryBuilder();
     if (isset($criteria['query'])) {
         $queryBuilder->leftJoin($this->getAlias() . '.customer', 'customer')->where('customer.emailCanonical LIKE :query')->orWhere('customer.firstName LIKE :query')->orWhere('customer.lastName LIKE :query')->orWhere($this->getAlias() . '.username LIKE :query')->setParameter('query', '%' . $criteria['query'] . '%');
     }
     if (isset($criteria['enabled'])) {
         $queryBuilder->andWhere('o.enabled = :enabled')->setParameter('enabled', $criteria['enabled']);
     }
     if (empty($sorting)) {
         if (!is_array($sorting)) {
             $sorting = [];
         }
         $sorting['updatedAt'] = 'desc';
     }
     $this->applySorting($queryBuilder, $sorting);
     return $this->getPaginator($queryBuilder);
 }
 /**
  * @param array $criteria
  * @param array $sorting
  *
  * @return Pagerfanta
  */
 public function createFilterPaginator($criteria = [], $sorting = [])
 {
     $queryBuilder = parent::getCollectionQueryBuilder()->leftJoin($this->getPropertyName('user'), 'user');
     if (isset($criteria['query'])) {
         $queryBuilder->where($queryBuilder->expr()->like($this->getPropertyName('emailCanonical'), ':query'))->orWhere($queryBuilder->expr()->like($this->getPropertyName('firstName'), ':query'))->orWhere($queryBuilder->expr()->like($this->getPropertyName('lastName'), ':query'))->orWhere($queryBuilder->expr()->like('user.username', ':query'))->setParameter('query', '%' . $criteria['query'] . '%');
     }
     if (isset($criteria['enabled'])) {
         $queryBuilder->andWhere($queryBuilder->expr()->eq('user.enabled', ':enabled'))->setParameter('enabled', $criteria['enabled']);
     }
     if (empty($sorting)) {
         if (!is_array($sorting)) {
             $sorting = [];
         }
         $sorting['updatedAt'] = 'desc';
     }
     $this->applySorting($queryBuilder, $sorting);
     return $this->getPaginator($queryBuilder);
 }
示例#9
0
 /**
  * Create filter paginator.
  *
  * @param array $criteria
  * @param array $sorting
  * @param bool  $deleted
  *
  * @return PagerfantaInterface
  */
 public function createFilterPaginator($criteria = array(), $sorting = array(), $deleted = false)
 {
     $queryBuilder = parent::getCollectionQueryBuilder();
     if ($deleted) {
         $this->_em->getFilters()->disable('softdeleteable');
     }
     if (isset($criteria['query'])) {
         $queryBuilder->where('o.username LIKE :query')->orWhere('o.email LIKE :query')->orWhere('o.firstName LIKE :query')->orWhere('o.lastName LIKE :query')->setParameter('query', '%' . $criteria['query'] . '%');
     }
     if (isset($criteria['enabled'])) {
         $queryBuilder->andWhere('o.enabled = :enabled')->setParameter('enabled', $criteria['enabled']);
     }
     if (empty($sorting)) {
         if (!is_array($sorting)) {
             $sorting = array();
         }
         $sorting['updatedAt'] = 'desc';
     }
     $this->applySorting($queryBuilder, $sorting);
     return $this->getPaginator($queryBuilder);
 }
示例#10
0
 /**
  * {@inheritdoc}
  */
 protected function getQueryBuilder()
 {
     return parent::getQueryBuilder()->select($this->getAlias() . ', option, variant')->leftJoin($this->getAlias() . '.options', 'option')->leftJoin($this->getAlias() . '.variants', 'variant');
 }
 /**
  * {@inheritdoc}
  */
 public function createUserPaginator(array $criteria = null, array $orderBy = null)
 {
     if (empty($criteria['user'])) {
         throw new NotFoundHttpException('Not found user.');
     }
     return parent::createPaginator($criteria, $orderBy);
 }
示例#12
0
 protected function getCollectionQueryBuilder()
 {
     return parent::getCollectionQueryBuilder()->leftJoin($this->getAlias() . '.rules', 'r')->addSelect('r')->leftJoin($this->getAlias() . '.actions', 'a')->addSelect('a');
 }
示例#13
0
 protected function getCollectionQueryBuilder()
 {
     return parent::getCollectionQueryBuilder()->leftJoin($this->getPropertyName('rules'), 'r')->addSelect('r')->leftJoin($this->getPropertyName('actions'), 'a')->addSelect('a');
 }
示例#14
0
 /**
  * {@inheritdoc}
  */
 protected function getCollectionQueryBuilder()
 {
     return parent::getQueryBuilder()->select('taxonomy, root, taxons')->leftJoin('taxonomy.root', 'root')->leftJoin('root.children', 'taxons');
 }
示例#15
0
 /**
  * {@inheritdoc}
  */
 protected function getQueryBuilder()
 {
     return parent::getQueryBuilder()->leftJoin('o.items', 'item')->addSelect('item');
 }
 protected function getQueryBuilder()
 {
     $queryBuilder = parent::getQueryBuilder();
     return $queryBuilder->join($this->getAlias() . '.orderItem', 'i')->join('i.order', 'O')->andWhere($queryBuilder->expr()->isNotNull('O.completedAt'));
 }
示例#17
0
 public function getArrayPaginator($objects)
 {
     return parent::getArrayPaginator($objects);
 }
示例#18
0
 protected function getCollectionQueryBuilder()
 {
     return parent::getCollectionQueryBuilder()->join($this->getAlias() . '.object', 'product')->addSelect('product')->leftJoin($this->getAlias() . '.options', 'option')->addSelect('option');
 }