1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Application\Api\Field\Mutation; |
6
|
|
|
|
7
|
|
|
use Application\Model\User; |
8
|
|
|
use Application\Repository\UserRepository; |
9
|
|
|
use Application\Service\MessageQueuer; |
10
|
|
|
use Ecodev\Felix\Api\Field\FieldInterface; |
11
|
|
|
use Ecodev\Felix\Api\Scalar\EmailType; |
12
|
|
|
use Ecodev\Felix\Service\Mailer; |
13
|
|
|
use GraphQL\Type\Definition\Type; |
14
|
|
|
use Mezzio\Session\SessionInterface; |
15
|
|
|
|
16
|
|
|
abstract class SubscribeNewsletter implements FieldInterface |
17
|
|
|
{ |
18
|
1 |
|
public static function build(): array |
19
|
|
|
{ |
20
|
|
|
return [ |
21
|
1 |
|
'name' => 'subscribeNewsletter', |
22
|
1 |
|
'type' => Type::nonNull(Type::boolean()), |
23
|
1 |
|
'description' => 'Subscribe to newsletter.', |
24
|
|
|
'args' => [ |
25
|
1 |
|
'email' => Type::nonNull(_types()->get(EmailType::class)), |
26
|
|
|
], |
27
|
1 |
|
'resolve' => function ($root, array $args, SessionInterface $session): bool { |
28
|
1 |
|
$email = $args['email']; |
29
|
|
|
global $container; |
30
|
|
|
/** @var Mailer $mailer */ |
31
|
1 |
|
$mailer = $container->get(Mailer::class); |
32
|
|
|
|
33
|
|
|
/** @var MessageQueuer $messageQueuer */ |
34
|
1 |
|
$messageQueuer = $container->get(MessageQueuer::class); |
35
|
|
|
|
36
|
|
|
/** @var UserRepository $repository */ |
37
|
1 |
|
$repository = _em()->getRepository(User::class); |
|
|
|
|
38
|
1 |
|
foreach ($messageQueuer->getAllEmailsToNotify() as $adminEmail) { |
39
|
|
|
$message = $messageQueuer->queueNewsletterSubscription($adminEmail, $email); |
40
|
|
|
$mailer->sendMessageAsync($message); |
41
|
|
|
} |
42
|
|
|
|
43
|
1 |
|
return true; |
44
|
1 |
|
}, |
45
|
|
|
]; |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|