161 lines
5.9 KiB
PHP
161 lines
5.9 KiB
PHP
<?php
|
|
|
|
namespace Trinity\Bundle\NewsletterBundle\Controller;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Trinity\Bundle\NewsletterBundle\Configuration\ModelCrudConfiguration as CrudConfiguration;
|
|
use Trinity\Bundle\AdminBundle\Controller\BaseAdminController;
|
|
use Trinity\Bundle\UserBundle\Flash\FlashError;
|
|
use Trinity\Bundle\UserBundle\Flash\FlashSuccess;
|
|
use Trinity\Bundle\UserBundle\Flash\FlashWarning;
|
|
|
|
/**
|
|
* @Route("/admin/newsletter/model")
|
|
*/
|
|
class ModelAdminController extends BaseAdminController
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->configuration = new CrudConfiguration();
|
|
}
|
|
|
|
/**
|
|
* @Route("/list/{page}", name="TrinityNewsletterBundleModelAdmin_index", defaults={"page" = "1"}, requirements={"page" = "\d+"})
|
|
* @Template()
|
|
*/
|
|
public function indexAction($page, Request $request)
|
|
{
|
|
$options = $this->container->getParameter('trinity_newsletter.newsletter');
|
|
|
|
$templates = array();
|
|
|
|
foreach($options['models'] as $key => $model)
|
|
{
|
|
$templates[$key] = array();
|
|
foreach($model['templates'] as $template){
|
|
$templates[$key][$template['template']] = $template['title'];
|
|
}
|
|
}
|
|
|
|
return array_merge(
|
|
parent::indexAction($page, $request),
|
|
array(
|
|
'models' => $options['models'],
|
|
'templates' => $templates
|
|
)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @Route("/new", name="TrinityNewsletterBundleModelAdmin_new")
|
|
* @Template()
|
|
*/
|
|
public function newAction(Request $request)
|
|
{
|
|
$options = $this->container->getParameter('trinity_newsletter.newsletter');
|
|
|
|
$model = $this->getConfiguration()->getModel();
|
|
$object = new $model();
|
|
$form = $this->getConfiguration()->getFormNew();
|
|
$form = $this->createForm(new $form($options), $object);
|
|
|
|
if ('POST' === $request->getMethod()) {
|
|
if (false !== $processForm = $this->processForm($form, $object, $request)) {
|
|
$this->getSessionUser()->setFlash('message', new FlashSuccess('crud.flash.updated.singular'), false, $this->getConfiguration()->getStorageNamespace());
|
|
|
|
return $processForm;
|
|
}
|
|
|
|
$this->getSessionUser()->setFlash('message', new FlashError('crud.flash.fail.new'), false, $this->getConfiguration()->getStorageNamespace());
|
|
}
|
|
|
|
return array(
|
|
'form' => $form->createView(),
|
|
'fieldsets' => $this->getConfiguration()->getFieldsets(),
|
|
'fieldsnames' => $this->getConfiguration()->getFieldsnames(),
|
|
'fields_helpers' => $this->getConfiguration()->getFieldsHelpers(),
|
|
'title' => $this->getConfiguration()->getNewTitle(),
|
|
'i18n' => $this->getConfiguration()->getI18n(),
|
|
'i18n_cultures' => $this->getConfiguration()->getI18nCultures(),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @Route("/edit/{id}", name="TrinityNewsletterBundleModelAdmin_edit")
|
|
* @Template()
|
|
* @ParamConverter("object", class="Trinity\Bundle\NewsletterBundle\Model\Model")
|
|
*/
|
|
public function editAction($object, Request $request)
|
|
{
|
|
if (!$object) {
|
|
$this->getSessionUser()->setFlash('message', new FlashWarning('crud.flash.unknown'), false, $this->getConfiguration()->getStorageNamespace());
|
|
|
|
return $this->redirect($this->generateUrl(sprintf('%s_index',$this->getConfiguration()->getRoutePrefix())));
|
|
}
|
|
|
|
$options = $this->container->getParameter('trinity_newsletter.newsletter');
|
|
|
|
$form = $this->getConfiguration()->getFormEdit();
|
|
$form = $this->createForm(new $form($options), $object);
|
|
|
|
if ('POST' === $request->getMethod()) {
|
|
if (false !== $processForm = $this->processForm($form, $object, $request)) {
|
|
$this->getSessionUser()->setFlash('message', new FlashSuccess('crud.flash.updated.singular'), false, $this->getConfiguration()->getStorageNamespace());
|
|
|
|
return $processForm;
|
|
}
|
|
|
|
$this->getSessionUser()->setFlash('message', new FlashError('crud.flash.fail.update'), false, $this->getConfiguration()->getStorageNamespace());
|
|
}
|
|
|
|
return array(
|
|
'object' => $object,
|
|
'form' => $form->createView(),
|
|
'fieldsets' => $this->getConfiguration()->getFieldsets(),
|
|
'fieldsnames' => $this->getConfiguration()->getFieldsnames(),
|
|
'fields_helpers' => $this->getConfiguration()->getFieldsHelpers(),
|
|
'remove_token' => $this->getRemoveToken(true),
|
|
'title' => $this->getConfiguration()->getEditTitle($object),
|
|
'i18n' => $this->getConfiguration()->getI18n(),
|
|
'i18n_cultures' => $this->getConfiguration()->getI18nCultures(),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @Route("/remove/{id}/{token}", name="TrinityNewsletterBundleModelAdmin_remove")
|
|
* @Template()
|
|
* @ParamConverter("object", class="Trinity\Bundle\NewsletterBundle\Model\Model")
|
|
*/
|
|
public function removeAction($object, $token, Request $request)
|
|
{
|
|
return parent::removeAction($object, $token, $request);
|
|
}
|
|
|
|
/**
|
|
* @Route("/batch", name="TrinityNewsletterBundleModelAdmin_batch")
|
|
* @Template()
|
|
* @Method({"POST"})
|
|
*/
|
|
public function batchAction(Request $request)
|
|
{
|
|
return parent::batchAction($request);
|
|
}
|
|
|
|
/**
|
|
* @Route("/filter/clear", name="TrinityNewsletterBundleModelAdmin_filter_clear")
|
|
* @Template()
|
|
*/
|
|
public function clearFilterAction(Request $request)
|
|
{
|
|
return parent::clearFilterAction($request);
|
|
}
|
|
|
|
}
|