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.

48 lines
1.3KB

  1. <?php
  2. namespace common\logic\User\UserProducer\Repository;
  3. use common\logic\AbstractRepository;
  4. use common\logic\Producer\Producer\Model\Producer;
  5. use common\logic\User\User\Model\User;
  6. use common\logic\User\UserProducer\Model\UserProducer;
  7. class UserProducerRepository extends AbstractRepository
  8. {
  9. protected UserProducerRepositoryQuery $query;
  10. public function loadDependencies(): void
  11. {
  12. $this->query = $this->loadService(UserProducerRepositoryQuery::class);
  13. }
  14. public function getDefaultOptionsSearch(): array
  15. {
  16. return [
  17. 'with' => [],
  18. 'join_with' => [],
  19. 'orderby' => '',
  20. 'attribute_id_producer' => 'user_producer.id_producer'
  21. ];
  22. }
  23. public function findOneUserProducer(User $user, Producer $producer)
  24. {
  25. return UserProducer::searchOne([
  26. 'id_user' => $user->id,
  27. 'user_producer.id_producer' => $producer->id
  28. ]);
  29. }
  30. public function findUserProducersByUser(User $user, bool $active = true, bool $bookmark = true)
  31. {
  32. return UserProducer::find()
  33. ->with(['producer'])
  34. ->where([
  35. 'id_user' => $user->id,
  36. 'active' => $active,
  37. 'bookmark' => $bookmark
  38. ])
  39. ->all();
  40. }
  41. }