You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UserMessageRepository.php 1.5KB

5 maanden geleden
5 maanden geleden
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. }