/** * 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); }
/** * 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; } }
/** * @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); }
/** * @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)); }
/** * 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)); }
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; } }
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; } }
/** * {@inheritDoc} */ public function hasPermission($permission) { $criteria = Criteria::create()->where(Criteria::expr()->eq('name', (string) $permission)); $result = $this->permissions->matching($criteria); return count($result) > 0; }
/** * @return ParameterInterface[] */ public function getParameters() { return $this->parameters->matching(Criteria::create()->where(Criteria::expr()->isNull('parent'))); }
public function getProductsCountChecked() { $criteria = Criteria::create(); $criteria->where(Criteria::expr()->eq('checked', true)); return $this->products->matching($criteria)->count(); }
/** * @return Collection */ public function getActiveChildren() { $criteria = Criteria::create()->where(Criteria::expr()->eq("isActive", true)); $result = $this->children->matching($criteria); return $result; }
/** * {@inheritdoc} */ public function getAcceptedReviews() { $criteria = Criteria::create()->where(Criteria::expr()->eq('status', ReviewInterface::STATUS_ACCEPTED)); return $this->reviews->matching($criteria); }
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); }
/** * * @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]; }
/** * @return Episode[] */ public function getEpisodes() { $criteria = Criteria::create(); $criteria->orderBy(['number' => Criteria::ASC]); return $this->episodes->matching($criteria)->toArray(); }