您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

67 行
1.9KB

  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 => ['producer'],
  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 findUserProducersByUser(User $user, bool $active = true, bool $bookmark = true)
  28. {
  29. return $this->createQuery()
  30. ->filterByUser($user)
  31. ->filterByActive($active)
  32. ->filterByBookmark($bookmark)
  33. ->find();
  34. }
  35. public function isProducerBookmarked(User $user): bool
  36. {
  37. $userProducer = $this->findOneUserProducer($user);
  38. return $userProducer ? $userProducer->bookmark : false;
  39. }
  40. public function findUserProducersWithNegativeOrPositiveCredit()
  41. {
  42. return $this->createDefaultQuery()
  43. ->filterHasNegativeOrPositiveCredit()
  44. ->find();
  45. }
  46. public function sumUserProducerCredits()
  47. {
  48. $sumUserProducersCredits = 0;
  49. $userProducersWithNegativeOrPositiveCreditArray = $this->findUserProducersWithNegativeOrPositiveCredit();
  50. foreach ($userProducersWithNegativeOrPositiveCreditArray as $userProducerWithNegativeOrPositiveCredit) {
  51. $sumUserProducersCredits += $userProducerWithNegativeOrPositiveCredit->credit;
  52. }
  53. return $sumUserProducersCredits;
  54. }
  55. }