Advertisement
Guest User

Untitled

a guest
May 26th, 2015
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. <?php namespace Api\Test;
  2.  
  3. use Api\Entity\CategoryEntity;
  4. use Api\Entity\SubscriptionEntity;
  5. use Api\Entity\TestEntity;
  6. use Api\Model\Test;
  7. use DeSmart\DomainCore\Repository\AbstractEloquentRepository;
  8. use DeSmart\DomainCore\Repository\BaseEloquentRepositoryTrait;
  9.  
  10. class TestRepository extends AbstractEloquentRepository
  11. {
  12. use BaseEloquentRepositoryTrait;
  13.  
  14. public function __construct(Test $query)
  15. {
  16. $this->query = $query;
  17. }
  18.  
  19. /**
  20. * Zwraca dostępne testy dla użytkownika.
  21. *
  22. * @param string $gender
  23. * @return \Illuminate\Database\Eloquent\Collection
  24. */
  25. public function getAvailableTests($gender)
  26. {
  27. $query = $this->query->where('is_active', 1)
  28. ->whereRaw('finished_at >= NOW()')
  29. ->applyGender($gender)
  30. ->with([
  31. 'subscription',
  32. 'category'
  33. ]);
  34.  
  35. $items = $this->hydrate($query->get());
  36.  
  37. return $items->each(function (TestEntity $test) {
  38. $eloquent = $test->getEloquentModel();
  39.  
  40. $test->setSubscription(new SubscriptionEntity($eloquent->subscription));
  41. $test->setCategory(new CategoryEntity($eloquent->category));
  42. });
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement