|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?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 => ['producer'],
- 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 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;
- }
- }
|