Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

74 linhas
2.0KB

  1. <?php
  2. namespace domain\User\UserProducer;
  3. use domain\User\User\User;
  4. use domain\_\AbstractRepository;
  5. class UserProducerRepository extends AbstractRepository
  6. {
  7. protected UserProducerRepositoryQuery $query;
  8. public function loadDependencies(): void
  9. {
  10. $this->loadQuery(UserProducerRepositoryQuery::class);
  11. }
  12. public function getDefaultOptionsSearch(): array
  13. {
  14. return [
  15. self::WITH => [],
  16. self::JOIN_WITH => [],
  17. self::ORDER_BY => '',
  18. self::ATTRIBUTE_ID_PRODUCER => 'user_producer.id_producer'
  19. ];
  20. }
  21. public function findOneUserProducer(User $user)
  22. {
  23. return $this->createDefaultQuery()
  24. ->filterByUser($user)
  25. ->findOne();
  26. }
  27. public function findOneUserProducerById(int $id): ?UserProducer
  28. {
  29. return $this->createQuery()
  30. ->filterById($id)
  31. ->findOne();
  32. }
  33. public function findUserProducersByUser(User $user, bool $active = true, bool $bookmark = true)
  34. {
  35. return $this->createQuery()
  36. ->filterByUser($user)
  37. ->filterByActive($active)
  38. ->filterByBookmark($bookmark)
  39. ->find();
  40. }
  41. public function isProducerBookmarked(User $user): bool
  42. {
  43. $userProducer = $this->findOneUserProducer($user);
  44. return $userProducer ? $userProducer->bookmark : false;
  45. }
  46. public function findUserProducersWithNegativeOrPositiveCredit()
  47. {
  48. return $this->createDefaultQuery()
  49. ->filterHasNegativeOrPositiveCredit()
  50. ->find();
  51. }
  52. public function sumUserProducerCredits()
  53. {
  54. $sumUserProducersCredits = 0;
  55. $userProducersWithNegativeOrPositiveCreditArray = $this->findUserProducersWithNegativeOrPositiveCredit();
  56. foreach ($userProducersWithNegativeOrPositiveCreditArray as $userProducerWithNegativeOrPositiveCredit) {
  57. $sumUserProducersCredits += $userProducerWithNegativeOrPositiveCredit->credit;
  58. }
  59. return $sumUserProducersCredits;
  60. }
  61. }