Commit 862a6cb2 authored by Hermann Mayer's avatar Hermann Mayer

Refined Service Structure. Rewritten the DefaultController showPageAction to…

Refined Service Structure. Rewritten the DefaultController showPageAction to handle the new services much better.
parent 164e89e6
......@@ -35,7 +35,6 @@ class DefaultController extends Controller
// Only process further on found navigation
if ($nav) {
$pages = array_merge($pages, $nav->getPages()->toArray());
}
......@@ -43,7 +42,7 @@ class DefaultController extends Controller
$config = (object) $this->container->getParameter('jity_homepage');
return $this->render('JityHomepageBundle:Default:navigation.html.twig', array(
'pages' => $pages,
'pages' => $pages,
'currentSlug' => $currentSlug
));
}
......@@ -105,104 +104,99 @@ class DefaultController extends Controller
* @access public
* @return void
*/
public function showPageAction($slug = '', $service = '', $renderService = true, Response $serviceReponse = null)
public function showPageAction($slug = '', $service = '')
{
// Get Entity Manager
$em = $this->getDoctrine()->getEntityManager();
// Try to get the requested Page
if (!empty($slug)) {
$page = $em->getRepository('JityHomepageBundle:Page')->findOneBySlug($slug);
} elseif (!empty($service)) {
$curService = $em->getRepository('JityHomepageBundle:Service')->findOneByName($service);
$page = $curService->getPages()->first();
// We dont want to render a infinite loop here
$renderService = false;
// Validate the request
if ((true === empty($slug)) && (true === empty($service))) {
$service = 'homepage';
}
// Page was not found
if (!$page) {
return $this->forward('JityHomepageBundle:Default:showInfo', array('template' => 'homepage_notfound'));
}
// Fixtures
$isServiceRequest = false;
$isPageRequest = false;
$servOutput = null;
$twigTemplate = 'JityHomepageBundle:Default:index.html.twig';
$em = $this->getDoctrine()->getEntityManager();
$servHandler = $this->get('jity_service.handler');
// On service relation jump into
if (($service = $page->getService()) &&
(true === $renderService) &&
('homepage' != $page->getService()->getName())
) {
// This is a service page request
if (false === empty($service)) {
if ($servHandler->hasController($service)) {
$serviceReponse = $this->get('jity_service.handler')
->getController($page->getService()->getName())
->process()
;
// Get service controller
$servController = $servHandler->getController($service);
$isServiceRequest = true;
}
}
// Return the rendered result
return $this->render('JityHomepageBundle:Default:index.html.twig', array(
'page' => $page,
'service' => (isset($serviceReponse)) ? $serviceReponse : ''
));
// This is simple page request by slug
if ((false === empty($slug))) {
// Try to get the requested Page
$page = $em
->getRepository('JityHomepageBundle:Page')
->findOneBySlug($slug)
;
if (null !== $page) {
$isPageRequest = true;
}
}
// // Get Entity Manager
// $em = $this->getDoctrine()->getEntityManager();
// // Try to get the requested Page
// if (!empty($slug)) {
// Combination is valid, otherwise return page not found
if (($isPageRequest && $isServiceRequest) ||
(!$isPageRequest && $isServiceRequest) ||
($isPageRequest && $page && !$isServiceRequest)
) {
// $page = $em->getRepository('JityHomepageBundle:Page')->findOneBySlug($slug);
// Both was specified, render page with given service
if ($isPageRequest && $isServiceRequest) {
$servOutput = $servController->process();
}
// } elseif (!empty($service)) {
// Pure service request, try to find a assoc page and rende them
if (!$isPageRequest && $isServiceRequest) {
$page = $em
->getRepository('JityHomepageBundle:Service')
->findOneByName($service)
->getPages()
->first()
;
$servOutput = $servController->process();
}
// $curService = $em->getRepository('JityHomepageBundle:Service')->findOneByName($service);
// $page = $curService->getPages()->first();
// Pure page request, try to find a assoc service and render them
if ($isPageRequest && !$isServiceRequest) {
// // We dont want to render a infinite loop here
// $renderService = false;
// }
if (null !== $page->getService()) {
$service = $page->getService()->getName();
// // Page was not found
// if (!$page) {
// return $this->forward('JityHomepageBundle:Default:showInfo', array('template' => 'homepage_notfound'));
// }
if ($servHandler->hasController($service)) {
// // On service relation jump into
// if (($service = $page->getService()) &&
// (true === $renderService) &&
// ('homepage' != $page->getService()->getName())
// ) {
// Get service controller
$servOutput = $servHandler
->getController($service)
->process()
;
}
}
}
// $serviceReponse = $this->forward('JityHomepageBundle:Service:show', array(
// 'page' => $page
// ));
// }
// Just render the current setting
return $this->render($twigTemplate, array(
'page' => $page,
'service' => $servOutput
));
}
// // Return the rendered result
// return $this->render('JityHomepageBundle:Default:index.html.twig', array(
// 'page' => $page,
// 'service' => (isset($serviceReponse)) ? $serviceReponse->getContent() : ''
// ));
// Request is unidentified
return $this->forward('JityHomepageBundle:Default:showInfo', array(
'template' => 'page_notfound'
));
}
/**
......
......@@ -151,7 +151,9 @@ class SecurityController extends Controller
}
}
return $this->redirect($this->generateUrl('page'));
return $this->redirect($this->generateUrl('page', array(
'service' => 'homepage'
)));
}
/**
......
<?php
namespace Jity\HomepageBundle\Controller;
use Jity\HomepageBundle\JityHomepageBundle;
use Jity\HomepageBundle\Entity\Contact;
use Jity\HomepageBundle\Entity\Page;
use Jity\HomepageBundle\Form\ContactType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
/**
* ServiceController
*
* @uses Controller
* @version $id$
* @author Hermann Mayer <hermann.mayer92@gmail.com>
*/
class ServiceController extends Controller
{
/**
* showAction
*
* @param Service $service
* @access public
* @return void
*/
public function showAction(Page $page)
{
// Get bundle config from container
$config = (object) $this->container->getParameter('jity_homepage');
$section = '';
$form = '';
$name = $page->getService()->getName();
if (isset($config->$name)) {
$section = $config->$name;
}
if ($name == 'contact') {
$entity = new Contact();
$form = $this
->createForm(new ContactType(), $entity)
->createView()
;
}
// Return the rendered result
return $this->render('JityHomepageBundle:Service:' . $name . '.html.twig', array(
'config' => $section,
'form' => $form
));
}
/**
* sendContactMessageAction
*
* @access public
* @return void
*/
public function sendContactMessageAction()
{
$entity = new Contact();
$request = $this->getRequest();
$form = $this->createForm(new ContactType(), $entity);
$form->bind($request);
if ($form->isValid()) {
// Get bundle config from container
$config = (object) $this->container->getParameter('jity_homepage');
// Prepare and Send a Contact Email
$message = \Swift_Message::newInstance()
->setSubject('[Jity] Neue Kontakt Mitteilung wurde verfasst')
->setFrom('info@jity.de')
->setTo($config->impress['contact']['email'])
->setBody($this->renderView('JityHomepageBundle:Service:contact_email.html.twig', array(
'contact' => $entity,
'config' => $config->impress
)), 'text/html')
;
$this->get('mailer')->send($message);
// Write entitiy
$em = $this->getDoctrine()->getEntityManager();
$em->persist($entity);
$em->flush();
// Write flash message and redirect back
$this->get('session')->getFlashBag()->add('success', 'Ihre Mitteilung wurde erfolgreich übermittelt.');
return $this->redirect($this->generateUrl('page', array(
'slug' => 'kontakt'
)));
}
// Render the form with the given errors
$partial = $this->render('JityHomepageBundle:Service:contact.html.twig', array(
'form' => $form->createView()
));
// Respond the filled form over the Default Controller
return $this->forward('JityHomepageBundle:Default:showPage', array(
'slug' => 'kontakt',
'renderService' => false,
'serviceReponse' => new Response($partial->getContent())
));
}
}
......@@ -22,15 +22,6 @@ abstract class AbstractService
* @return void
*/
abstract public function getName();
/**
* getDescription
*
* @abstract
* @access public
* @return void
*/
abstract public function getDescription();
/**
* process
......
......@@ -31,17 +31,6 @@ class BlogController extends AbstractService
return 'blog';
}
/**
* getDescription
*
* @access public
* @return void
*/
public function getDescription()
{
return 'Fügt die Startseite eines Blogs hinzu.';
}
/**
* process
*
......
......@@ -7,7 +7,6 @@ use Jity\HomepageBundle\DependencyInjection\Service\AbstractService,
JMS\DiExtraBundle\Annotation as DI;
use Jity\HomepageBundle\Entity\Contact,
Jity\HomepageBundle\Entity\Page,
Jity\HomepageBundle\Form\ContactType;
/**
......@@ -33,17 +32,6 @@ class ContactController extends AbstractService
return 'contact';
}
/**
* getDescription
*
* @access public
* @return void
*/
public function getDescription()
{
return 'Fügt ein simples Kontakt-Formular hinzu.';
}
/**
* process
*
......@@ -52,75 +40,61 @@ class ContactController extends AbstractService
*/
public function process()
{
$entity = new Contact();
$form = $this->container->get('form.factory')
$entity = new Contact();
$request = $this->container->get('request');
$form = $this->container->get('form.factory')
->create(new ContactType(), $entity)
->createView()
;
if ('POST' == $request->getMethod()) {
$form->bind($request);
if ($form->isValid()) {
$this->sendContactMessageAction($entity);
}
}
return $this->container->get('templating')->render('JityHomepageBundle:Service:Contact/new.html.twig', array(
'config' => $this->getSectionFromConfig(),
'form' => $form
'form' => $form->createView()
));
}
/**
* sendContactMessageAction
*
* @access public
* @return void
*/
public function sendContactMessageAction()
public function sendContactMessageAction(Contact $entity)
{
// $entity = new Contact();
// $request = $this->getRequest();
// $form = $this->createForm(new ContactType(), $entity);
// $form->bind($request);
// if ($form->isValid()) {
// // Get bundle config from container
// $config = (object) $this->container->getParameter('jity_homepage');
// // Prepare and Send a Contact Email
// $message = \Swift_Message::newInstance()
// ->setSubject('[Jity] Neue Kontakt Mitteilung wurde verfasst')
// ->setFrom('info@jity.de')
// ->setTo($config->impress['contact']['email'])
// ->setBody($this->renderView('JityHomepageBundle:Service:contact_email.html.twig', array(
// 'contact' => $entity,
// 'config' => $config->impress
// )), 'text/html')
// ;
// $this->get('mailer')->send($message);
// // Write entitiy
// $em = $this->getDoctrine()->getEntityManager();
// $em->persist($entity);
// $em->flush();
// // Write flash message and redirect back
// $this->get('session')->getFlashBag()->add('success', 'Ihre Mitteilung wurde erfolgreich übermittelt.');
// return $this->redirect($this->generateUrl('page', array(
// 'slug' => 'kontakt'
// )));
// }
// Get bundle config from container
$config = (object) $this->container->getParameter('jity_homepage');
// Prepare and Send a Contact Email
$message = \Swift_Message::newInstance()
->setSubject('[Jity] Neue Kontakt Mitteilung wurde verfasst')
->setFrom('info@jity.de')
->setTo($config->impress['contact']['email'])
->setBody(
$this->container
->get('templating')
->render('JityHomepageBundle:Service:Contact/email.html.twig', array(
'contact' => $entity,
'config' => $config->impress
)
), 'text/html')
;
// // Render the form with the given errors
// $partial = $this->render('JityHomepageBundle:Service:contact.html.twig', array(
// 'form' => $form->createView()
// ));
$this->container->get('mailer')->send($message);
// // Respond the filled form over the Default Controller
// return $this->forward('JityHomepageBundle:Default:showPage', array(
// 'slug' => 'kontakt',
// 'renderService' => false,
// 'serviceReponse' => new Response($partial->getContent())
// ));
// Write flash message and redirect back
$this->container
->get('session')
->getFlashBag()
->add('success', 'Ihre Mitteilung wurde erfolgreich übermittelt.')
;
}
}
<?php
namespace Jity\HomepageBundle\DependencyInjection\Service\Controller;
use Jity\HomepageBundle\DependencyInjection\Service\AbstractService,
Symfony\Bundle\FrameworkBundle\Controller\Controller,
JMS\DiExtraBundle\Annotation as DI;
use Symfony\Component\HttpFoundation\Response;
/**
* HomepageController
*
* @DI\Service("jity_service.controller.homepage", scope="request")
* @DI\Tag("jity_service.controller")
*
* @uses Controller
* @version $id$
* @author Hermann Mayer <hermann.mayer92@gmail.com>
*/
class HomepageController extends AbstractService
{
/**
* getName
*
* @access public
* @return void
*/
public function getName()
{
return 'homepage';
}
/**
* process
*
* @access public
* @return void
*/
public function process()
{
return;
}
}
......@@ -31,17 +31,6 @@ class ImpressController extends AbstractService
return 'impress';
}
/**
* getDescription
*
* @access public
* @return void
*/
public function getDescription()
{
return 'Fügt ein Impressum hinzu.';
}
/**
* process
*
......
......@@ -32,36 +32,33 @@ class Handler
}
/**
* getController
* hasController
*
* @param string $name
* @param mixed $name
* @access public
* @return void
*/
public function getController($name)
public function hasController($name)
{
if (array_key_exists((string)$name, $this->controller)) {
return $this->controller[(string)$name];
return true;
}
return false;
}
/**
* getMetaMapping
* getController
*
* @param string $name
* @access public
* @return void
*/
public function getMetaMapping()
public function getController($name)
{
$map = array();
foreach ($this->controller as $controller) {
$map[$controller->getName()]['description'] = $controller->getDescription();
if (array_key_exists((string)$name, $this->controller)) {
return $this->controller[(string)$name];
}
return $map;
}
}
......@@ -32,7 +32,7 @@ class ContactType extends AbstractType
->add('email', null, array(
'label' => 'Ihre Email Adresse'
))
->add('message', null, array(
->add('message', 'textarea', array(
'attr' => array(
'rows' => '6',
'class' => 'span4',
......
......@@ -4,5 +4,9 @@ info:
page:
pattern: /{slug}
defaults: { _controller: JityHomepageBundle:Default:showPage, slug: ~, service: homepage }
defaults: { _controller: JityHomepageBundle:Default:showPage, slug: ~, service: ~ }
# page:
# pattern: /{slug}
# defaults: { _controller: JityHomepageBundle:Default:showPage, slug: ~, service: homepage }
service_contact_send:
pattern: /kontakt/send
defaults: { _controller: JityHomepageBundle:Service:sendContactMessage }
requirements: { _method: post }
# service_contact_send:
# pattern: /kontakt/send
# defaults: { _controller: JityHomepageBundle:Service:sendContactMessage }
# requirements: { _method: post }
#
......@@ -6,12 +6,12 @@
<legend>Administrationsbereich</legend>
<a href="{{ path('page') }}" class="btn btn-danger">
<a href="{{ path('page', {service: "homepage"}) }}" class="btn btn-danger">
<i class="icon-user icon-white"></i>
Benutzer
</a>
<a href="{{ path('page') }}" class="btn btn-danger">
<a href="{{ path('page', {service: "homepage"}) }}" class="btn btn-danger">
<i class="icon-list-alt icon-white"></i>
Gruppen
</a>
......
......@@ -41,7 +41,7 @@
<td>
<a href="
{% if is_granted('ROLE_ADMIN') %}
{{ path('page') }}
{{ path('page', {service: "homepage"}) }}
{% else %}
#
{% endif %}
......
......@@ -21,7 +21,7 @@
Kategorien
</a>
<a href="{{ path('page') }}" class="btn btn-danger">
<a href="{{ path('page', {service: "homepage"}) }}" class="btn btn-danger">
<i class="icon-globe icon-white"></i>
Navigationen
</a>
......
......@@ -14,13 +14,14 @@
<pubDate>{{ article.createdAt|date('r') }}</pubDate>
<image>
<url>{{ host ~ asset('apple-touch-icon.png') }}</url>
<title>{{ host|capitalize }}</title>
<title>{{ article.title }} - Aktivitäten</title>
<link>{{ host }}</link>
</image>