|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
-
- namespace domain\User\UserProducer;
-
- use domain\User\User\User;
- use domain\_\AbstractRepository;
-
- class UserProducerRepository extends AbstractRepository
- {
- protected UserProducerRepositoryQuery $query;
-
- public function loadDependencies(): void
- {
- $this->loadQuery(UserProducerRepositoryQuery::class);
- }
-
- public function getDefaultOptionsSearch(): array
- {
- return [
- self::WITH => [],
- self::JOIN_WITH => [],
- self::ORDER_BY => '',
- self::ATTRIBUTE_ID_PRODUCER => 'user_producer.id_producer'
- ];
- }
-
- public function findOneUserProducer(User $user)
- {
- return $this->createDefaultQuery()
- ->filterByUser($user)
- ->findOne();
- }
-
- public function findOneUserProducerById(int $id): ?UserProducer
- {
- return $this->createQuery()
- ->filterById($id)
- ->findOne();
- }
-
- public function findUserProducersByUser(User $user, bool $active = true, bool $bookmark = true)
- {
- return $this->createQuery()
- ->filterByUser($user)
- ->filterByActive($active)
- ->filterByBookmark($bookmark)
- ->find();
- }
-
- public function isProducerBookmarked(User $user): bool
- {
- $userProducer = $this->findOneUserProducer($user);
- return $userProducer ? $userProducer->bookmark : false;
- }
-
- public function findUserProducersWithNegativeOrPositiveCredit()
- {
- return $this->createDefaultQuery()
- ->filterHasNegativeOrPositiveCredit()
- ->find();
- }
-
- public function sumUserProducerCredits()
- {
- $sumUserProducersCredits = 0;
- $userProducersWithNegativeOrPositiveCreditArray = $this->findUserProducersWithNegativeOrPositiveCredit();
-
- foreach ($userProducersWithNegativeOrPositiveCreditArray as $userProducerWithNegativeOrPositiveCredit) {
- $sumUserProducersCredits += $userProducerWithNegativeOrPositiveCredit->credit;
- }
-
- return $sumUserProducersCredits;
- }
- }
|