|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
-
- namespace domain\Communication\Email;
-
- use common\helpers\GlobalParam;
- use domain\_\AbstractResolver;
- use domain\Distribution\Distribution\Distribution;
- use domain\PointSale\PointSale\PointSale;
- use domain\Producer\Producer\Producer;
- use domain\User\User\UserRepository;
-
- class ContactListResolver extends AbstractResolver
- {
- protected UserRepository $userRepository;
-
- public function loadDependencies(): void
- {
- $this->userRepository = $this->loadService(UserRepository::class);
- }
-
- public function search(
- Producer $producer,
- string $newsletterType = null,
- Distribution $distribution = null,
- PointSale $pointSale = null,
- bool $usersPointSaleLink = false,
- bool $usersPointSaleHasOrder = false,
- bool $isSubscriber = false,
- bool $isInactive = false
- ): array
- {
- if ($pointSale && !$usersPointSaleLink && !$usersPointSaleHasOrder) {
- $usersPointSaleLink = 1;
- }
- if ($distribution && !$usersPointSaleLink && !$usersPointSaleHasOrder) {
- $usersPointSaleLink = 1;
- }
-
- if($distribution) {
- $users = [];
-
- foreach($distribution->pointSaleDistribution as $pointSaleDistribution) {
- if($pointSaleDistribution->delivery) {
- $usersPointSaleArray = $this->userRepository->queryUsersBy([
- 'id_producer' => $producer->id,
- 'id_point_sale' => $pointSaleDistribution->id_point_sale,
- 'users_point_sale_link' => $usersPointSaleLink,
- 'users_point_sale_has_order' => $usersPointSaleHasOrder,
- 'newsletter_type' => $newsletterType,
- 'newsletter' => true
- ])->all();
-
- foreach($usersPointSaleArray as $user) {
- $users[$user['id']] = $user;
- }
- }
- }
- }
- else {
- $users = $this->userRepository->queryUsersBy([
- 'id_producer' => $producer->id,
- 'id_point_sale' => $pointSale ? $pointSale->id : null,
- 'users_point_sale_link' => $usersPointSaleLink,
- 'users_point_sale_has_order' => $usersPointSaleHasOrder,
- 'subscribers' => $isSubscriber,
- 'inactive' => $isInactive,
- 'newsletter_type' => $newsletterType,
- 'newsletter' => true
- ])->all();
- }
-
- $usersArray = [];
- foreach ($users as $user) {
- if (isset($user['email']) && strlen($user['email']) > 0) {
- if($producer->isDemoAccount()) {
- $user['email'] = \Yii::$app->faker->email();
- }
- $usersArray[] = $user;
- }
- }
-
- return $usersArray;
- }
- }
|