Skip to content

Instantly share code, notes, and snippets.

@manuakasam
Created November 23, 2013 12:58
Show Gist options
  • Select an option

  • Save manuakasam/7614325 to your computer and use it in GitHub Desktop.

Select an option

Save manuakasam/7614325 to your computer and use it in GitHub Desktop.
I got a couple of understanding problems. 1) How to fetch Entities that have to match multiple criterias? 2) How to fetch all enabled users from today from a certain user? -
class EntitiesFromToday extends Criteria
{
public function __construct(Expression $expression = null, array $orderings = null, $firstResult = null, $maxResults = null)
{
parent::__construct($expression, $orderings, $firstResult, $maxResults);
$this->andWhere(
$this->expr()->qt(
'published',
new \DateTime('-1 day')
)
);
}
}
class EntitiesThatAreEnabled extends Criteria
{
public function __construct(Expression $expression = null, array $orderings = null, $firstResult = null, $maxResults = null)
{
parent::__construct($expression, $orderings, $firstResult, $maxResults);
$this->andWhere(
$this->expr()->eq('enabled', true)
);
}
}
<?php
class MyRepository extends EntityRepository
{
public function findAll()
{
return $this->matching(
new EntitiesThatAreEnabled()
);
}
public function findAllFromToday()
{
return $this->matching(
new EntitiesFromToday()
);
}
}
<?php
class MyService
{
protected $repo;
public function __construct(MyRepository $repo)
{
$this->repo = $repo;
}
public function findAll()
{
return $this->repo->findAll();
}
public functin findAllFromToday()
{
return $this->repo->findAllFromToday();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment