-
Notifications
You must be signed in to change notification settings - Fork 0
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
32 changed files
with
1,426 additions
and
774 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,72 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright (C) BadPixxel <www.badpixxel.com> | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace BadPixxel\BrevoBridge\Controller\Templates; | ||
|
||
use BadPixxel\BrevoBridge\Dictionary\TemplatesRoutes; | ||
use BadPixxel\BrevoBridge\Interfaces\HtmlTemplateAwareInterface; | ||
use BadPixxel\BrevoBridge\Services\RawHtmlRenderer; | ||
use BadPixxel\BrevoBridge\Services\TemplateManager; | ||
use Exception; | ||
use Sonata\AdminBundle\Controller\CRUDController; | ||
use Sonata\UserBundle\Model\UserInterface as User; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpFoundation\Session\Session; | ||
|
||
/** | ||
* Render a Demo Email using Brevo Account Template by ID | ||
*/ | ||
class Preview extends CRUDController | ||
{ | ||
public function __construct( | ||
private TemplateManager $tmplManager, | ||
private RawHtmlRenderer $rawHtmlRenderer | ||
) { | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function __invoke(Request $request, string $emailCode): Response | ||
{ | ||
/** @var Session $session */ | ||
$session = $request->getSession(); | ||
/** @var User $user */ | ||
$user = $this->getUser(); | ||
//============================================================================== | ||
// Identify Email Class | ||
$emailClass = $this->tmplManager->getEmailByCode($emailCode); | ||
if (is_null($emailClass) || !class_exists($emailClass)) { | ||
return $this->redirectToRoute(TemplatesRoutes::LIST); | ||
} | ||
if (!is_subclass_of($emailClass, HtmlTemplateAwareInterface::class)) { | ||
return $this->redirectToRoute(TemplatesRoutes::LIST); | ||
} | ||
//============================================================================== | ||
// Fetch Email Template from API | ||
$smtpTemplate = $this->tmplManager->get($emailClass, $user); | ||
if (!$smtpTemplate) { | ||
$session->getFlashBag()->add('sonata_flash_error', $this->tmplManager->getLastError()); | ||
|
||
return $this->redirectToRoute(TemplatesRoutes::LIST); | ||
} | ||
|
||
//============================================================================== | ||
// Render Raw Html Template | ||
return $this->rawHtmlRenderer->render( | ||
$smtpTemplate->getHtmlContent(), | ||
$this->tmplManager->getTmplParameters($emailClass, $user) | ||
); | ||
} | ||
} |
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,80 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright (C) BadPixxel <www.badpixxel.com> | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace BadPixxel\BrevoBridge\Controller\Templates; | ||
|
||
use BadPixxel\BrevoBridge\Dictionary\TemplatesRoutes; | ||
use BadPixxel\BrevoBridge\Models\AbstractEmail; | ||
use BadPixxel\BrevoBridge\Services\SmtpManager; | ||
use Exception; | ||
use Sonata\AdminBundle\Controller\CRUDController; | ||
use Sonata\UserBundle\Model\UserInterface as User; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpFoundation\Session\Session; | ||
|
||
/** | ||
* Render a Brevo Email using Local Template Sources | ||
*/ | ||
class Send extends CRUDController | ||
{ | ||
public function __construct( | ||
private SmtpManager $smtpManager, | ||
) { | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function __invoke(Request $request, string $emailCode): Response | ||
{ | ||
/** @var Session $session */ | ||
$session = $request->getSession(); | ||
/** @var User $user */ | ||
$user = $this->getUser(); | ||
//============================================================================== | ||
// Identify Email Class | ||
$emailClass = $this->smtpManager->getEmailByCode($emailCode); | ||
if (is_null($emailClass)) { | ||
$session->getFlashBag()->add('sonata_flash_error', 'Unable to identify Email'); | ||
|
||
return $this->redirectToRoute(TemplatesRoutes::LIST); | ||
} | ||
//============================================================================== | ||
// Verify Email Class | ||
if (!class_exists($emailClass)) { | ||
$session->getFlashBag()->add('sonata_flash_error', 'Email Class: '.$emailClass.' was not found'); | ||
|
||
return $this->redirectToRoute(TemplatesRoutes::LIST); | ||
} | ||
if (!is_subclass_of($emailClass, AbstractEmail::class)) { | ||
$session->getFlashBag()->add( | ||
'sonata_flash_error', | ||
'Email Class: '.$emailClass.' is not an '.AbstractEmail::class | ||
); | ||
|
||
return $this->redirectToRoute(TemplatesRoutes::LIST); | ||
} | ||
//============================================================================== | ||
// Send Test Email | ||
$email = $emailClass::sendDemo($user); | ||
if (is_null($email)) { | ||
$session->getFlashBag()->add('sonata_flash_error', $emailClass::getLastError()); | ||
|
||
return $this->redirectToRoute(TemplatesRoutes::LIST); | ||
} | ||
$session->getFlashBag()->add('sonata_flash_success', 'Test Email send to '.$user->getEmail()); | ||
|
||
return $this->redirectToRoute(TemplatesRoutes::LIST); | ||
} | ||
} |
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,71 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright (C) BadPixxel <www.badpixxel.com> | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace BadPixxel\BrevoBridge\Controller\Templates; | ||
|
||
use BadPixxel\BrevoBridge\Dictionary\TemplatesRoutes; | ||
use BadPixxel\BrevoBridge\Services\RawHtmlRenderer; | ||
use BadPixxel\BrevoBridge\Services\TemplateManager; | ||
use Exception; | ||
use Sonata\AdminBundle\Controller\CRUDController; | ||
use Sonata\UserBundle\Model\UserInterface as User; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpFoundation\Session\Session; | ||
|
||
/** | ||
* Render a Brevo Email using Local Template Sources | ||
*/ | ||
class View extends CRUDController | ||
{ | ||
public function __construct( | ||
private TemplateManager $tmplManager, | ||
private RawHtmlRenderer $rawHtmlRenderer | ||
) { | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function __invoke(Request $request, string $emailCode): Response | ||
{ | ||
/** @var Session $session */ | ||
$session = $request->getSession(); | ||
/** @var User $user */ | ||
$user = $this->getUser(); | ||
//============================================================================== | ||
// Identify Email Class | ||
$emailClass = $this->tmplManager->getEmailByCode($emailCode); | ||
if (is_null($emailClass)) { | ||
return $this->redirectToRoute(TemplatesRoutes::LIST); | ||
} | ||
if (!class_exists($emailClass) || !$this->tmplManager->isTemplateAware($emailClass)) { | ||
return $this->redirectToRoute(TemplatesRoutes::LIST); | ||
} | ||
//============================================================================== | ||
// Compile Email Template | ||
$rawHtml = (string) $this->tmplManager->compile($emailClass); | ||
if (!$rawHtml) { | ||
$session->getFlashBag()->add('sonata_flash_error', $this->tmplManager->getLastError()); | ||
|
||
return $this->redirectToRoute(TemplatesRoutes::LIST); | ||
} | ||
|
||
//============================================================================== | ||
// Render Raw Html Template | ||
return $this->rawHtmlRenderer->render( | ||
$rawHtml, | ||
$this->tmplManager->getTmplParameters($emailClass, $user) | ||
); | ||
} | ||
} |
Oops, something went wrong.