@@ -0,0 +1,8 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Context ; | |||
interface NewsInterface | |||
{ | |||
} |
@@ -3,6 +3,7 @@ | |||
namespace Lc\ShopBundle\Controller\Admin; | |||
use App\Entity\MerchantConfig; | |||
use App\Repository\UserRepository; | |||
use Lc\ShopBundle\Context\AddressInterface; | |||
use Lc\ShopBundle\Repository\MerchantConfigRepository; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
@@ -19,7 +20,9 @@ use Lc\ShopBundle\Form\AbstractEditPositionType; | |||
use Lc\ShopBundle\Form\ChoiceProductCategoryType; | |||
use Lc\ShopBundle\Form\PriceType; | |||
use Lc\ShopBundle\Form\Widget\PriceWidgetType; | |||
use Lc\ShopBundle\Services\GlobalParam; | |||
use Lc\ShopBundle\Services\Utils; | |||
use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport; | |||
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | |||
use Symfony\Component\Form\Extension\Core\Type\CollectionType; | |||
use Symfony\Component\Form\FormEvent; | |||
@@ -32,17 +35,23 @@ class AdminController extends EasyAdminController | |||
protected $userManager; | |||
protected $em ; | |||
protected $utils ; | |||
protected $mailjetTransport ; | |||
protected $globalParam ; | |||
public function __construct( | |||
Security $security, | |||
UserManagerInterface $userManager, | |||
EntityManagerInterface $em, | |||
Utils $utils) | |||
Utils $utils, | |||
MailjetTransport $mailjetTransport, | |||
GlobalParam $globalParam) | |||
{ | |||
$this->security = $security; | |||
$this->userManager = $userManager; | |||
$this->em = $em ; | |||
$this->utils = $utils ; | |||
$this->mailjetTransport = $mailjetTransport ; | |||
$this->globalParam = $globalParam ; | |||
} | |||
public function showAction() |
@@ -0,0 +1,51 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Controller\Admin; | |||
use App\Repository\UserRepository; | |||
use Lc\ShopBundle\Context\NewsInterface; | |||
use Lc\ShopBundle\Context\UserInterface; | |||
use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport; | |||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | |||
class NewsController extends AdminController | |||
{ | |||
public function sendAction() | |||
{ | |||
$idNews = $this->request->get('id') ; | |||
$users = $this->em->getRepository($this->em->getClassMetadata(UserInterface::class)->getName())->findBy([ | |||
'isSubscribedNewsletter' => true | |||
]) ; | |||
$countUsers = count($users) ; | |||
$messages = []; | |||
$news = $this->em->getRepository($this->em->getClassMetadata(NewsInterface::class)->getName())->find($idNews) ; | |||
if($news) { | |||
foreach ($users as $user) { | |||
$message = new \Swift_Message('[Place du Local] '.$news->getTitle()); | |||
$message->addTo($user->getEmail()) | |||
->addFrom('no-reply@opendistrib.net', 'Place du Local') | |||
->setBody($this->renderView('mail/news.html.twig', [ | |||
'message' => $news->getDescription(), | |||
'image' => $news->getImage(), | |||
]), 'text/html'); | |||
array_push($messages, $message); | |||
} | |||
$result = $this->mailjetTransport->bulkSend($messages); | |||
if($countUsers > 0) { | |||
$this->addFlash('success', 'Actualité envoyée à '.count($users).' utilisateurs.'); | |||
} | |||
else { | |||
$this->addFlash('error', 'Aucun utilisateur inscrit à la newsletter.'); | |||
} | |||
} | |||
else { | |||
throw new NotFoundHttpException('Actualité introuvable') ; | |||
} | |||
return $this->redirectToRoute('easyadmin', ['entity' => 'News', 'action' => 'list']) ; | |||
} | |||
} |
@@ -39,10 +39,12 @@ class EasyAdminSubscriber implements EventSubscriberInterface | |||
$paginator->nbResultsOffline = $entityRepo->count(array('status'=>0,'merchant'=>$currentMerchant)); | |||
$paginator->nbResultsDeleted = $entityRepo->count(array('status'=>-1,'merchant'=>$currentMerchant)); | |||
}else{ | |||
$paginator->nbResultsOnline = $entityRepo->count(array('status'=>1)); | |||
/*$paginator->nbResultsOnline = $entityRepo->count(array('status'=>1)); | |||
$paginator->nbResultsOffline = $entityRepo->count(array('status'=>0)); | |||
$paginator->nbResultsDeleted = $entityRepo->count(array('status'=>-1)); | |||
$paginator->nbResultsDeleted = $entityRepo->count(array('status'=>-1));*/ | |||
$paginator->nbResultsOnline = $entityRepo->count([]); | |||
$paginator->nbResultsOffline = $entityRepo->count([]); | |||
$paginator->nbResultsDeleted = $entityRepo->count([]); | |||
} | |||
} | |||
@@ -0,0 +1,31 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Model; | |||
use Doctrine\ORM\Mapping as ORM; | |||
use Lc\ShopBundle\Model\AbstractDocumentEntity; | |||
use Gedmo\Mapping\Annotation as Gedmo; | |||
/** | |||
* @ORM\MappedSuperclass() | |||
*/ | |||
abstract class News extends AbstractDocumentEntity | |||
{ | |||
/** | |||
* @ORM\Column(type="datetime") | |||
* @Gedmo\Timestampable(on="create") | |||
*/ | |||
protected $date; | |||
public function getDate(): ?\DateTimeInterface | |||
{ | |||
return $this->date; | |||
} | |||
public function setDate(\DateTimeInterface $date): self | |||
{ | |||
$this->date = $date; | |||
return $this; | |||
} | |||
} |
@@ -49,6 +49,11 @@ abstract class User extends UserModelFOS | |||
*/ | |||
protected $carts; | |||
/** | |||
* @ORM\Column(type="boolean", nullable=true) | |||
*/ | |||
protected $isSubscribedNewsletter; | |||
public function __construct() | |||
{ | |||
parent::__construct(); | |||
@@ -217,4 +222,16 @@ abstract class User extends UserModelFOS | |||
return $this; | |||
} | |||
public function getIsSubscribedNewsletter(): ?bool | |||
{ | |||
return $this->isSubscribedNewsletter; | |||
} | |||
public function setIsSubscribedNewsletter(?bool $isSubscribedNewsletter): self | |||
{ | |||
$this->isSubscribedNewsletter = $isSubscribedNewsletter; | |||
return $this; | |||
} | |||
} |
@@ -0,0 +1,2 @@ | |||
<a class="btn btn-primary" href="{{ path('easyadmin', {entity: 'News', action: 'send', id: item.id}) }}"><i class="fa fa-paper-plane"></i> Envoyer</a> |