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; } }