This repository has been archived by the owner on Jan 16, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace App\Command; | ||
|
||
use App\Util\Notification; | ||
use FOS\UserBundle\Model\UserManagerInterface; | ||
use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
|
||
/** | ||
* Create a notification for a given user | ||
*/ | ||
class CreateNotificationCommand extends Command | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected static $defaultName = 'librecores:send-notification'; | ||
|
||
/** | ||
* @var ProducerInterface | ||
*/ | ||
private $producer; | ||
|
||
/** | ||
* @var UserManagerInterface | ||
*/ | ||
private $userManager; | ||
|
||
/** | ||
* CreateNotificationCommand constructor. | ||
* | ||
* @param ProducerInterface $notificationProducer | ||
* @param UserManagerInterface $userManager | ||
*/ | ||
public function __construct(ProducerInterface $notificationProducer, UserManagerInterface $userManager) | ||
{ | ||
parent::__construct(); | ||
$this->producer = $notificationProducer; | ||
$this->userManager = $userManager; | ||
} | ||
|
||
/** | ||
* Configuration for the Command | ||
*/ | ||
protected function configure() | ||
{ | ||
$this->setDescription('Send a notification to a user') | ||
->setHelp('This command allows you to send a notification to a user'); | ||
$this->addArgument('subject', InputArgument::REQUIRED, 'Add notification subject'); | ||
$this->addArgument('message', InputArgument::REQUIRED, 'Add notification message'); | ||
$this->addArgument('type', InputArgument::REQUIRED, 'Specify notification type'); | ||
$this->addArgument('user', InputArgument::REQUIRED, 'Specify user to whom this notification will be sent to'); | ||
} | ||
|
||
/** | ||
* Send notification to the user | ||
* | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$user = $this->userManager->findUserByUsername($input->getArgument('user')); | ||
|
||
$notification = new Notification(); | ||
$notification->setSubject($input->getArgument('subject')); | ||
$notification->setMessage($input->getArgument('message')); | ||
$notification->setType($input->getArgument('type')); | ||
$notification->setRecipient($user); | ||
|
||
$this->producer->publish(serialize($notification)); | ||
} | ||
} | ||
|
||
?> |