Last active
December 16, 2015 14:48
-
-
Save kstefan/5450864 to your computer and use it in GitHub Desktop.
Expample of using Doctrine\Common\Collections\Criteria
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 ExpenseStatement | |
| { | |
| /** | |
| * @param ExpenseStatementState|string $state | |
| * @return ExpenseStatementEvent | |
| */ | |
| public function getLastEvent($state) | |
| { | |
| if (! $state instanceof ExpenseStatementState) { | |
| $state = new ExpenseStatementState($state); | |
| } | |
| if (!array_key_exists($state->getValue(), $this->lastEvents)) { | |
| $criteria = Criteria::create() | |
| ->where(Criteria::expr()->eq("state", $state->getValue())) | |
| ->orderBy(array("date" => "DESC")) | |
| ; | |
| $this->lastEvents[$state->getValue()] = $this->getEvents()->matching($criteria)->first(); | |
| } | |
| return $this->lastEvents[$state->getValue()]; | |
| } | |
| /** | |
| * @param ExpenseStatementState|string $state | |
| * @return DateTime|null | |
| */ | |
| public function getLastEventDate($state) | |
| { | |
| $event = $this->getLastEvent($state); | |
| return $event ? $event->getDate() : null; | |
| } | |
| /** | |
| * @return DateTime|null | |
| */ | |
| public function getLastProposalDate() | |
| { | |
| return $this->getLastEventDate(ExpenseStatementState::STATE_PROPOSAL); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment