Kaynağa Gözat

Refactoring Repository & AdminController

reduction
Fab 4 yıl önce
ebeveyn
işleme
1737d7b3aa
6 değiştirilmiş dosya ile 126 ekleme ve 1 silme
  1. +8
    -0
      ShopBundle/Context/NewsInterface.php
  2. +51
    -0
      ShopBundle/Controller/Admin/NewsController.php
  3. +31
    -0
      ShopBundle/Model/News.php
  4. +17
    -1
      ShopBundle/Model/ProductFamily.php
  5. +17
    -0
      ShopBundle/Model/User.php
  6. +2
    -0
      ShopBundle/Resources/views/backend/news/action_send.html.twig

+ 8
- 0
ShopBundle/Context/NewsInterface.php Dosyayı Görüntüle

@@ -0,0 +1,8 @@
<?php

namespace Lc\ShopBundle\Context ;

interface NewsInterface
{

}

+ 51
- 0
ShopBundle/Controller/Admin/NewsController.php Dosyayı Görüntüle

@@ -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']) ;
}

}

+ 31
- 0
ShopBundle/Model/News.php Dosyayı Görüntüle

@@ -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;
}
}

+ 17
- 1
ShopBundle/Model/ProductFamily.php Dosyayı Görüntüle

@@ -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;

+ 17
- 0
ShopBundle/Model/User.php Dosyayı Görüntüle

@@ -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;
}
}

+ 2
- 0
ShopBundle/Resources/views/backend/news/action_send.html.twig Dosyayı Görüntüle

@@ -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>

Yükleniyor…
İptal
Kaydet