Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

UserProducerRepository.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. }