Created
November 23, 2013 12:58
-
-
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? -
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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') | |
| ) | |
| ); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
| ); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class MyRepository extends EntityRepository | |
| { | |
| public function findAll() | |
| { | |
| return $this->matching( | |
| new EntitiesThatAreEnabled() | |
| ); | |
| } | |
| public function findAllFromToday() | |
| { | |
| return $this->matching( | |
| new EntitiesFromToday() | |
| ); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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