Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

61 lines
1.5KB

  1. <?php
  2. namespace domain\User\UserMessage;
  3. use domain\_\AbstractRepository;
  4. use domain\User\User\User;
  5. class UserMessageRepository extends AbstractRepository
  6. {
  7. protected UserMessageRepositoryQuery $query;
  8. public function loadDependencies(): void
  9. {
  10. $this->loadQuery(UserMessageRepositoryQuery::class);
  11. }
  12. public function getDefaultOptionsSearch(): array
  13. {
  14. return [
  15. self::WITH => [],
  16. self::JOIN_WITH => [],
  17. self::ORDER_BY => 'created_at DESC',
  18. self::ATTRIBUTE_ID_PRODUCER => ''
  19. ];
  20. }
  21. public function findOneUserMessageById(int $id): ?UserMessage
  22. {
  23. return $this->createQuery()
  24. ->filterById($id)
  25. ->findOne();
  26. }
  27. public function queryUserMessagesByUser(User $user)
  28. {
  29. return $this->createDefaultQuery()
  30. ->filterByUser($user);
  31. }
  32. public function findUserMessagesByUser(User $user): array
  33. {
  34. return $this->queryUserMessagesByUser($user)->find();
  35. }
  36. public function countUserMessagesByUser(User $user): int
  37. {
  38. return count($this->findUserMessagesByUser($user));
  39. }
  40. public function findUserMessagesUnreadByUser(User $user)
  41. {
  42. return $this->queryUserMessagesByUser($user)
  43. ->filterIsUnread()
  44. ->find();
  45. }
  46. public function countUserMessagesUnreadByUser(User $user): int
  47. {
  48. return count($this->findUserMessagesUnreadByUser($user));
  49. }
  50. }