Exemplo n.º 1
1
 /**
  * Sort existing value collection utility.
  *
  * @param Collection $values
  * @param string $sortKey
  * @return Collection
  */
 public static function sort(Collection $values, $sortKey)
 {
     $criteria = new Criteria();
     switch ($sortKey) {
         case self::BY_ALPHA_ASC:
             $criteria->orderBy(array('value' => Criteria::ASC));
             break;
         case self::BY_ALPHA_DESC:
             $criteria->orderBy(array('value' => Criteria::DESC));
             break;
         case self::BY_ID_ASC:
             $criteria->orderBy(array('id' => Criteria::ASC));
             break;
         case self::BY_ID_DESC:
             $criteria->orderBy(array('id' => Criteria::DESC));
             break;
         case self::BY_NUMBER:
         default:
             $criteria->orderBy(array('order' => Criteria::ASC));
             break;
     }
     return $values->matching($criteria);
 }
Exemplo n.º 2
0
 /**
  * Finds a data entity
  *
  * @param string $key
  *
  * @return object|null
  */
 protected function findData($key)
 {
     $criteria = Criteria::create()->where(Criteria::expr()->eq('key', $key));
     $result = $this->data->matching($criteria);
     if (is_array($result)) {
         $result = reset($result);
         return $result;
     }
 }
Exemplo n.º 3
0
 /**
  * @group DDC-1637
  */
 public function testMatchingSlice()
 {
     $this->fillMatchingFixture();
     $col = $this->_coll->matching(new Criteria(null, null, 1, 1));
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\Collection', $col);
     $this->assertNotSame($col, $this->_coll);
     $this->assertEquals(1, count($col));
     $this->assertEquals('baz', $col[0]->foo);
 }
 /**
  * @return Collection
  */
 private function getFilteredCollection()
 {
     return $this->data_source->matching($this->criteria);
 }
Exemplo n.º 5
0
 /**
  * @param string $currency
  * @return PriceListCurrency
  */
 public function getPriceListCurrencyByCode($currency)
 {
     $criteria = Criteria::create()->where(Criteria::expr()->eq('currency', $currency));
     return $this->currencies->matching($criteria)->first();
 }
 /**
  * Selects all elements from a selectable that match the expression and
  * return a new collection containing these elements.
  *
  * @param \Doctrine\Common\Collections\Criteria $criteria
  *
  * @return Collection
  *
  * @throws \RuntimeException
  */
 public function matching(Criteria $criteria)
 {
     if ($this->isDirty) {
         $this->initialize();
     }
     if ($this->initialized) {
         return $this->coll->matching($criteria);
     }
     if ($this->association['type'] === ClassMetadata::MANY_TO_MANY) {
         $persister = $this->em->getUnitOfWork()->getCollectionPersister($this->association);
         return new ArrayCollection($persister->loadCriteria($this, $criteria));
     }
     $builder = Criteria::expr();
     $ownerExpression = $builder->eq($this->backRefFieldName, $this->owner);
     $expression = $criteria->getWhereExpression();
     $expression = $expression ? $builder->andX($expression, $ownerExpression) : $ownerExpression;
     $criteria->where($expression);
     $persister = $this->em->getUnitOfWork()->getEntityPersister($this->association['targetEntity']);
     return $this->association['fetch'] === ClassMetadataInfo::FETCH_EXTRA_LAZY ? new LazyCriteriaCollection($persister, $criteria) : new ArrayCollection($persister->loadCriteria($criteria));
 }
Exemplo n.º 7
0
 /**
  * Select all elements from a selectable that match the expression and
  * return a new collection containing these elements.
  *
  * @param \Doctrine\Common\Collections\Criteria $criteria
  * @return Collection
  */
 public function matching(Criteria $criteria)
 {
     if ($this->isDirty) {
         $this->initialize();
     }
     if ($this->initialized) {
         return $this->coll->matching($criteria);
     }
     if ($this->association['type'] !== ClassMetadata::ONE_TO_MANY) {
         throw new \RuntimeException("Matching Criteria on PersistentCollection only works on OneToMany assocations at the moment.");
     }
     $id = $this->em->getClassMetadata(get_class($this->owner))->getSingleIdReflectionProperty()->getValue($this->owner);
     $builder = Criteria::expr();
     $ownerExpression = $builder->eq($this->backRefFieldName, $id);
     $expression = $criteria->getWhereExpression();
     $expression = $expression ? $builder->andX($expression, $ownerExpression) : $ownerExpression;
     $criteria->where($expression);
     $persister = $this->em->getUnitOfWork()->getEntityPersister($this->association['targetEntity']);
     return new ArrayCollection($persister->loadCriteria($criteria));
 }
Exemplo n.º 8
0
 public function getCaratteristica($caratteristica)
 {
     try {
         $criteria = Criteria::create()->where(Criteria::expr()->eq("gruppo", $caratteristica));
         $out = $this->caratteristiche->matching($criteria);
         /* @var $out \Doctrine\Common\Collections\ArrayCollection */
         if (count($out) == 0) {
             $scheda = new SchedaCaratteristica();
             $scheda->setValue('');
             return $scheda;
         }
         return $out->first();
     } catch (Exception $ex) {
         throw $ex;
     }
 }
Exemplo n.º 9
0
 public function getDoc($tipo)
 {
     try {
         $criteria = Criteria::create()->where(Criteria::expr()->eq("tipo", $tipo));
         $out = $this->documenti->matching($criteria);
         /* @var $out \Doctrine\Common\Collections\ArrayCollection */
         if (count($out) == 0) {
             return false;
         }
         return $out->first();
     } catch (Exception $ex) {
         throw $ex;
     }
 }
Exemplo n.º 10
0
 /**
  * {@inheritDoc}
  */
 public function hasPermission($permission)
 {
     $criteria = Criteria::create()->where(Criteria::expr()->eq('name', (string) $permission));
     $result = $this->permissions->matching($criteria);
     return count($result) > 0;
 }
Exemplo n.º 11
0
 /**
  * @return ParameterInterface[]
  */
 public function getParameters()
 {
     return $this->parameters->matching(Criteria::create()->where(Criteria::expr()->isNull('parent')));
 }
Exemplo n.º 12
0
 public function getProductsCountChecked()
 {
     $criteria = Criteria::create();
     $criteria->where(Criteria::expr()->eq('checked', true));
     return $this->products->matching($criteria)->count();
 }
Exemplo n.º 13
0
 /**
  * @return Collection
  */
 public function getActiveChildren()
 {
     $criteria = Criteria::create()->where(Criteria::expr()->eq("isActive", true));
     $result = $this->children->matching($criteria);
     return $result;
 }
Exemplo n.º 14
0
 /**
  * {@inheritdoc}
  */
 public function getAcceptedReviews()
 {
     $criteria = Criteria::create()->where(Criteria::expr()->eq('status', ReviewInterface::STATUS_ACCEPTED));
     return $this->reviews->matching($criteria);
 }
Exemplo n.º 15
0
 public function getLatestActivities($type = Activity::ACTIVITY_TYPE_COMMIT)
 {
     if (!in_array($type, array(Activity::ACTIVITY_TYPE_COMMIT, Activity::ACTIVITY_TYPE_RECOMMEND, Activity::ACTIVITY_TYPE_TRAVIS_BUILD))) {
         throw new \InvalidArgumentException();
     }
     $criteria = Criteria::create()->where(Criteria::expr()->eq('type', $type))->orderBy(array("createdAt" => "DESC"))->setFirstResult(0)->setMaxResults(30);
     return $this->activities->matching($criteria);
 }
Exemplo n.º 16
0
 /**
  * 
  * @return RegistrationStatus
  */
 public function getCurrentRegistrationStatus()
 {
     $criteria = Criteria::create()->where(Criteria::expr()->eq("isCurrent", true))->setMaxResults(1);
     $result = $this->registrationStatus->matching($criteria);
     return $result->toArray()[0];
 }
Exemplo n.º 17
0
 /**
  * @return Episode[]
  */
 public function getEpisodes()
 {
     $criteria = Criteria::create();
     $criteria->orderBy(['number' => Criteria::ASC]);
     return $this->episodes->matching($criteria)->toArray();
 }