-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from SpearDevs/rc/v1.1.0
Update translates, send push notification by enter user email
- Loading branch information
Showing
14 changed files
with
178 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SpearDevs\SyliusPushNotificationsPlugin\Form\Model; | ||
|
||
use SpearDevs\SyliusPushNotificationsPlugin\Validator\Constraints\PushNotificationUserSubscriptionExists; | ||
use Sylius\Component\Core\Model\ChannelInterface; | ||
use Sylius\Component\Customer\Model\CustomerGroupInterface; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
/** @PushNotificationUserSubscriptionExists() */ | ||
class SendPushNotificationFormModel | ||
{ | ||
/** @Assert\NotBlank() */ | ||
public string $title; | ||
|
||
/** @Assert\NotBlank() */ | ||
public string $body; | ||
|
||
/** @Assert\NotBlank() */ | ||
public ChannelInterface $channel; | ||
|
||
public string $receiver; | ||
|
||
public ?CustomerGroupInterface $group = null; | ||
|
||
/** @Assert\Email() */ | ||
public string $userEmail; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/Validator/Constraints/PushNotificationUserSubscriptionExists.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SpearDevs\SyliusPushNotificationsPlugin\Validator\Constraints; | ||
|
||
use Symfony\Component\Validator\Constraint; | ||
|
||
/** | ||
* @Annotation | ||
*/ | ||
class PushNotificationUserSubscriptionExists extends Constraint | ||
{ | ||
public string $message = 'push_notifications.send.user_subscription_not_exist'; | ||
|
||
public function getTargets(): string | ||
{ | ||
return self::CLASS_CONSTRAINT; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/Validator/Constraints/PushNotificationUserSubscriptionExistsValidator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SpearDevs\SyliusPushNotificationsPlugin\Validator\Constraints; | ||
|
||
use SpearDevs\SyliusPushNotificationsPlugin\Form\Model\SendPushNotificationFormModel; | ||
use SpearDevs\SyliusPushNotificationsPlugin\Repository\UserSubscriptionRepositoryInterface; | ||
use SpearDevs\SyliusPushNotificationsPlugin\WebPushSender\WebPushSender; | ||
use Symfony\Component\Form\Exception\UnexpectedTypeException; | ||
use Symfony\Component\Validator\Constraint; | ||
use Symfony\Component\Validator\ConstraintValidator; | ||
use Traversable; | ||
|
||
final class PushNotificationUserSubscriptionExistsValidator extends ConstraintValidator | ||
{ | ||
public function __construct( | ||
private UserSubscriptionRepositoryInterface $userSubscriptionRepository, | ||
) { | ||
} | ||
|
||
/** | ||
* @param SendPushNotificationFormModel $value | ||
*/ | ||
public function validate($value, Constraint $constraint): void | ||
{ | ||
if (!$constraint instanceof PushNotificationUserSubscriptionExists) { | ||
throw new UnexpectedTypeException($constraint, PushNotificationUser::class); | ||
} | ||
|
||
if ($value === null || $value === '' || $value->receiver === WebPushSender::GROUP_RECEIVER) { | ||
return; | ||
} | ||
|
||
$subscriptions = $this->userSubscriptionRepository->getSubscriptionsForUserByEmail( | ||
$value->userEmail, | ||
$value->channel, | ||
); | ||
|
||
/** @var Traversable $subscriptions * */ | ||
$subscriptionCount = iterator_count($subscriptions); | ||
|
||
if ($subscriptionCount > 0) { | ||
return; | ||
} | ||
|
||
$this->context | ||
->buildViolation($constraint->message) | ||
->atPath('userEmail') | ||
->addViolation(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.