@@ -0,0 +1,8 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Context ; | |||
interface NewsInterface | |||
{ | |||
} |
@@ -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']) ; | |||
} | |||
} |
@@ -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; | |||
} | |||
} |
@@ -276,6 +276,23 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr | |||
return $this->isNovelty; | |||
} | |||
public function isNoveltyOnline(): ?bool | |||
{ | |||
if($this->isNovelty) { | |||
if($this->getNoveltyExpirationDate()) { | |||
$now = new \DateTime() ; | |||
if($now <= $this->getNoveltyExpirationDate()) { | |||
return true ; | |||
} | |||
} | |||
else { | |||
return true ; | |||
} | |||
} | |||
return false ; | |||
} | |||
public function setIsNovelty(?bool $isNovelty): self | |||
{ | |||
$this->isNovelty = $isNovelty; | |||
@@ -295,7 +312,6 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr | |||
return $this; | |||
} | |||
public function getIsOrganic(): ?bool | |||
{ | |||
return $this->isOrganic; |
@@ -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> |