From 94a0895d3946f40288c61d23b7a1ae59766c23cc Mon Sep 17 00:00:00 2001
From: Simon Vieille
Date: Mon, 21 Dec 2020 17:44:08 +0100
Subject: [PATCH 1/2] add public feed
---
src/Command/MailingListCommand.php | 17 ++++++-
src/Command/MailingNewCommand.php | 5 ++-
src/Command/MailingPublishCommand.php | 60 +++++++++++++++++++++++++
src/Command/MailingUnpublishCommand.php | 60 +++++++++++++++++++++++++
src/Controller/AppController.php | 16 ++++++-
src/Entity/Mailing.php | 17 +++++++
6 files changed, 170 insertions(+), 5 deletions(-)
create mode 100644 src/Command/MailingPublishCommand.php
create mode 100644 src/Command/MailingUnpublishCommand.php
diff --git a/src/Command/MailingListCommand.php b/src/Command/MailingListCommand.php
index 29dab9d..dc05cf8 100644
--- a/src/Command/MailingListCommand.php
+++ b/src/Command/MailingListCommand.php
@@ -32,20 +32,22 @@ class MailingListCommand extends Command
{
$this
->setDescription('List mailings')
+ ->addOption('feed', null, InputOption::VALUE_NONE, 'Show URLs of feeds')
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
+ $showFeed = $input->getOption('feed');
- $headers = ['Label', 'ID', 'Feed', 'Created at', 'Updated at'];
+ $headers = ['Label', 'ID', 'Feed', 'Public', 'Created at', 'Updated at'];
$rows = [];
$entities = $this->repo->findAll([], ['createdAt' => 'DEC']);
foreach ($entities as $entity) {
- $rows[] = [
+ $row = [
$entity->getLabel(),
$entity->getId(),
$this->router->generate(
@@ -53,9 +55,20 @@ class MailingListCommand extends Command
['mailing' => $entity->getId()],
UrlGeneratorInterface::ABSOLUTE_URL
),
+ $entity->getIsPublic() ? 'y' : 'n',
$entity->getCreatedAt()->format('Y-m-d H:i:s'),
$entity->getUpdatedAt()->format('Y-m-d H:i:s'),
];
+
+ if (!$showFeed) {
+ unset($row[2]);
+ }
+
+ $rows[] = $row;
+ }
+
+ if (!$showFeed) {
+ unset($headers[2]);
}
$io->table($headers, $rows);
diff --git a/src/Command/MailingNewCommand.php b/src/Command/MailingNewCommand.php
index 57593bf..d3da02e 100644
--- a/src/Command/MailingNewCommand.php
+++ b/src/Command/MailingNewCommand.php
@@ -29,6 +29,7 @@ class MailingNewCommand extends Command
$this
->setDescription('Create a new mailing')
->addArgument('label', InputArgument::REQUIRED, 'Label of the mailing')
+ ->addOption('public', 'p', InputOption::VALUE_NONE, 'Make the mailing public')
;
}
@@ -38,7 +39,9 @@ class MailingNewCommand extends Command
$label = $input->getArgument('label');
$entity = new Mailing();
- $entity->setLabel($label);
+ $entity
+ ->setLabel($label)
+ ->setIsPublic($input->getOption('public'));
$this->em->persist($entity);
$this->em->flush();
diff --git a/src/Command/MailingPublishCommand.php b/src/Command/MailingPublishCommand.php
new file mode 100644
index 0000000..612093d
--- /dev/null
+++ b/src/Command/MailingPublishCommand.php
@@ -0,0 +1,60 @@
+em = $em;
+ $this->repo = $repo;
+ }
+
+ protected function configure()
+ {
+ $this
+ ->setDescription('Publish a mailing')
+ ->addArgument('id', InputArgument::OPTIONAL, 'ID of the mailing')
+ ;
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output): int
+ {
+ $io = new SymfonyStyle($input, $output);
+ $id = $input->getArgument('id');
+
+ $entity = $this->repo->find(['id' => $id]);
+
+ if (null === $entity) {
+ $io->error(sprintf('"%s" is not found!', $id));
+
+ return Command::FAILURE;
+ }
+
+ $entity->setIsPublic(true);
+
+ $this->em->persist($entity);
+ $this->em->flush();
+
+ $io->success(sprintf('"%s" is now public', $entity->getId()));
+
+ return Command::SUCCESS;
+ }
+}
diff --git a/src/Command/MailingUnpublishCommand.php b/src/Command/MailingUnpublishCommand.php
new file mode 100644
index 0000000..41f183e
--- /dev/null
+++ b/src/Command/MailingUnpublishCommand.php
@@ -0,0 +1,60 @@
+em = $em;
+ $this->repo = $repo;
+ }
+
+ protected function configure()
+ {
+ $this
+ ->setDescription('Unpublish a mailing')
+ ->addArgument('id', InputArgument::OPTIONAL, 'ID of the mailing')
+ ;
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output): int
+ {
+ $io = new SymfonyStyle($input, $output);
+ $id = $input->getArgument('id');
+
+ $entity = $this->repo->find(['id' => $id]);
+
+ if (null === $entity) {
+ $io->error(sprintf('"%s" is not found!', $id));
+
+ return Command::FAILURE;
+ }
+
+ $entity->setIsPublic(false);
+
+ $this->em->persist($entity);
+ $this->em->flush();
+
+ $io->success(sprintf('"%s" is now private', $entity->getId()));
+
+ return Command::SUCCESS;
+ }
+}
diff --git a/src/Controller/AppController.php b/src/Controller/AppController.php
index c2cb858..ba93b1f 100644
--- a/src/Controller/AppController.php
+++ b/src/Controller/AppController.php
@@ -5,14 +5,26 @@ namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
+use App\Repository\MailingRepository;
class AppController extends AbstractController
{
/**
* @Route("/", name="home")
*/
- public function home(): Response
+ public function home(MailingRepository $mailingRepo): Response
{
- return $this->render('app/home.html.twig');
+ $mailings = $mailingRepo->findBy(
+ [
+ 'isPublic' => true,
+ ],
+ [
+ 'label' => 'ASC',
+ ]
+ );
+
+ return $this->render('app/home.html.twig', [
+ 'mailings' => $mailings,
+ ]);
}
}
diff --git a/src/Entity/Mailing.php b/src/Entity/Mailing.php
index e1e0526..f7469a9 100644
--- a/src/Entity/Mailing.php
+++ b/src/Entity/Mailing.php
@@ -36,6 +36,11 @@ class Mailing
*/
private $mails;
+ /**
+ * @ORM\Column(type="boolean", options={"default": 0})
+ */
+ private $isPublic = false;
+
public function __construct()
{
$this->mails = new ArrayCollection();
@@ -87,4 +92,16 @@ class Mailing
return $this;
}
+
+ public function getIsPublic(): ?bool
+ {
+ return $this->isPublic;
+ }
+
+ public function setIsPublic(bool $isPublic): self
+ {
+ $this->isPublic = $isPublic;
+
+ return $this;
+ }
}
From 1da95ba1de157ff194984a61f341cde5f9b04aad Mon Sep 17 00:00:00 2001
From: Simon Vieille
Date: Mon, 21 Dec 2020 17:44:24 +0100
Subject: [PATCH 2/2] add public feed
---
templates/app/home.html.twig | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/templates/app/home.html.twig b/templates/app/home.html.twig
index 2baa523..975757c 100644
--- a/templates/app/home.html.twig
+++ b/templates/app/home.html.twig
@@ -25,6 +25,20 @@
développé par Simon Vieille
+
+ {% if mailings|length %}
+
+ {% endif %}
{% endblock %}