Commit bf405e2a authored by Hermann Mayer's avatar Hermann Mayer

Extended DefaultController and Bundle Configuration to handle 'impress' and 'contact' pages

parent 25dab749
......@@ -40,7 +40,14 @@
<p class="navbar-text pull-right">
</p>
<ul class="nav">
{% block navigation %}{% endblock %}
{% if page is defined %}
{% set currentSlug = page.slug %}
{% else %}
{% set currentSlug = '' %}
{% endif%}
{% render 'JityHomepageBundle:Default:renderNavigation' with {'currentSlug': currentSlug, 'navigation': 'Default'} %}
</ul>
<form class="form-search navbar-search pull-right">
......
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: jity.yml }
framework:
#esi: ~
......@@ -58,12 +59,3 @@ swiftmailer:
jms_security_extra:
secure_all_services: false
services:
jity.twig.extension.debug:
class: Twig_Extension_Debug
tags:
- { name: 'twig.extension' }
jity_homepage:
admin_email: jack@hermann-mayer.net
jity_homepage:
admin:
email: jack@hermann-mayer.net
impress:
site_admin:
name: Herman Mayer
address: Friedrich-Bosse-Str. 39
zipcode: "04159"
city: Leipzig
content_manager:
name: Herman Mayer
address: Friedrich-Bosse-Str. 39
zipcode: "04159"
city: Leipzig
contact:
phone: "0341 5806 7458"
email: root@hermann-mayer.net
services:
jity.twig.extension.debug:
class: Twig_Extension_Debug
tags:
- { name: 'twig.extension' }
......@@ -11,6 +11,8 @@ use Jity\HomepageBundle\Entity\Sidebar;
use Jity\HomepageBundle\Entity\SidebarSection;
use Jity\HomepageBundle\JityHomepageBundle;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Jity\HomepageBundle\Entity\Contact;
use Jity\HomepageBundle\Form\ContactType;
/**
* DefaultController
......@@ -21,6 +23,63 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
*/
class DefaultController extends Controller
{
/**
* renderNavigationAction
*
* @param string $navigation
* @access public
* @return void
*/
public function renderNavigationAction($currentSlug, $navigation = 'Default')
{
// Get Entity Manager
$em = $this->getDoctrine()->getEntityManager();
// Try to get the requested navigation
$nav = $em->getRepository('Jity\HomepageBundle\Entity\Navigation')->findOneByName($navigation);
$pages = array();
// Only process further on found navigation
if ($nav) {
$pages = array_merge($pages, $nav->getPages()->toArray());
}
// Get bundle config from container
$config = (object) $this->container->getParameter('jity_homepage');
// If impress settings were set write links
if (array_key_exists('site_admin', $config->impress)) {
$impress = new Page();
$impress
->setSlug('impress')
->setTitle('Impressum')
->setIcon('icon-list')
;
$pages = array_merge($pages, array($impress));
}
// If impress settings were set write links
if (array_key_exists('site_admin', $config->impress)) {
$contact = new Page();
$contact
->setSlug('contact')
->setTitle('Kontakt')
->setIcon('icon-comment')
;
$pages = array_merge($pages, array($contact));
}
return $this->render('JityHomepageBundle:Default:navigation.html.twig', array(
'pages' => $pages,
'currentSlug' => $currentSlug
));
}
/**
* showPageAction
*
......@@ -72,5 +131,102 @@ class DefaultController extends Controller
// Return the rendered result
return $this->render($templateName);
}
/**
* showImpressAction
*
* @access public
* @return void
*/
public function showImpressAction()
{
// Get bundle config from container
$config = (object) $this->container->getParameter('jity_homepage');
// Emulate the page.slug for navigation handling
$page = new Page();
$page->setSlug('impress');
// Return the rendered result
return $this->render('JityHomepageBundle:Default:impress.html.twig', array(
'config' => $config->impress,
'page' => $page
));
}
/**
* showContactAction
*
* @access public
* @return void
*/
public function showContactAction()
{
// Emulate the page.slug for navigation handling
$page = new Page();
$page->setSlug('contact');
$entity = new Contact();
$form = $this->createForm(new ContactType(), $entity);
// Return the rendered result
return $this->render('JityHomepageBundle:Default:contact.html.twig', array(
'page' => $page,
'form' => $form->createView()
));
}
/**
* 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:Default: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('contact'));
}
// Emulate the page.slug for navigation handling
$page = new Page();
$page->setSlug('contact');
return $this->render('JityHomepageBundle:Default:contact.html.twig', array(
'page' => $page,
'form' => $form->createView()
));
}
}
......@@ -10,11 +10,8 @@ use Jity\HomepageBundle\Form\PageType;
* PageController
*
* @uses Controller
* @package
* @version $id$
* @copyright
* @author Hermann Mayer <hermann.mayer92@gmail.com>
* @license
*/
class PageController extends Controller
{
......
<?php
namespace Jity\HomepageBundle\DataFixtures\ORM;
use Jity\HomepageBundle\Entity\Sidebar;
use Jity\HomepageBundle\Entity\SidebarSection;
use Jity\HomepageBundle\Entity\Page;
use Jity\HomepageBundle\Entity\Category;
use Jity\HomepageBundle\Entity\Navigation;
use Jity\HomepageBundle\Entity\Group;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
class LoadDevData extends AbstractFixture implements OrderedFixtureInterface
{
public function load(ObjectManager $manager)
{
$page = new Page();
$page
->setSlug('home')
->setTitle('Über mich')
->setContent('<img src="{{ asset("bundles/jityhomepage/img/myself-cc3-300px.png") }}" alt="" class="img-polaroid pull-left" />
<p>
Mein Name ist Hermann Mayer, ich wurde am 02. August im Jahre 1992 in Berlin geboren und bin
in einem kleinen Örtchen Namens Augsdorf, dass im ehemaligen Mansfelder Land liegt, aufgewachsen.
</p>
<p>
Heute heißt dieser Landkreis, in Sachsen-Anhalt, Mansfeld-Südharz. Eine frohe und aufgeschlossene
Natur wurde mir in die Wiege gelegt und diese habe ich mir bis heute erhalten können, nicht
zuletzt auch durch die Art und Weise wie ich manche Dinge bewerte und durch die Fähigkeit mich
selbst nicht immer zu ernst zu nehmen.
</p>
<p>
Verschiedene Hobbys haben sich im Laufe meines Lebens heraus kristallisiert, dazu gehört das
leidenschaftliche Motorradfahren, das Programmieren und Verwirklichen von Projekten in meiner
Freizeit, sowie der Drang meine Kreativität durch Gedichte oder Digitale Kunst auszudrücken.
Ich habe die Angewohnheit meine Umwelt genau zu beobachten und zu analysieren, auch völlig
unbewusst. Dies ist oftmals auch eine Quelle für Inspirationen, jeglicher Art.
</p>
<p>
Des Weiteren bin ich ein Mensch der Musik liebt, und sie braucht. Ich habe fast immer Musik an,
egal ob Radio oder Alben meiner Lieblings Interpreten, sei es Unterwegs per N900 oder zu Hause mit
der dortigen Workstation. Musik trägt zu meiner Entspannung bei, fördert aber auch die
Konzentrationsfähigkeit in meinem Falle. Eine weitere Eigenheit von mir ist der unerschöpfliche
Wunsch nach Wissen, wenn mich etwas interessiert erkunde ich es tiefgründig. Ich verbringe
dadurch viele Stunden meines Tages mit dem Lesen von Büchern (digitaler oder gedruckter Art)
oder dem recherchieren im Internet.
</p>
<p>
Zudem liebe ich es zu Planen und zu Organisieren. Manchmal verbringe ich Tage mit der gedanklichen
Ausgestaltung eines Planes, der in Jahren, Jahrzehnten oder nie zum Einsatz kommen wird. Außerdem
bin ich kontaktfreudig, wortgewandt und tolerant in jedem Aspekt. Meine Art ist direkt und offen,
ich sage was ich denke, auch wenn es nicht immer das ist was andere gern hören wollen. Trotzdem
pflege ich meine sozialen Kontakte und Bindungen und versuche mich in die Probleme anderer
hineinzudenken um sie zu verstehen. Zudem bin ich hilfsbereit, selbst wenn dies für mich
zusätzliche Arbeit bedeutet.
</p>')
->setCategory($this->getReference('default-category'))
->setSidebar($this->getReference('default-sidebar'))
->setNavigation($this->getReference('default-navigation'))
->setAuthor($this->getReference('admin-user'))
->setIcon('icon-user')
;
$manager->persist($page);
$section = new SidebarSection();
$section
->setTitle('Teilen')
->setContent('<p>
Hat Ihnen diese Seite gefallen? Teilen Sie sie doch mit Ihren
Freunden und Bekannten über Googles Soziales Netzwerk oder über Facebook.
</p>
<p>
<a href="" class="btn btn-danger"><img src="{{ asset("bundles/jityhomepage/img/glyphicons_386_google_plus.png") }}" /> Google+</a>
<a href="" class="btn btn-primary"><img src="{{ asset("bundles/jityhomepage/img/glyphicons_390_facebook.png") }}" /> Facebook</a>
</p>')
->setSidebar($this->getReference('default-sidebar'))
;
$manager->persist($section);
// Flush to Database
$manager->flush();
}
public function getOrder()
{
return 4;
}
}
......@@ -36,6 +36,10 @@ class LoadPageData extends AbstractFixture implements OrderedFixtureInterface
// Flush to Database
$manager->flush();
$this->addReference('default-navigation', $navigation);
$this->addReference('default-category', $category);
$this->addReference('default-sidebar', $sidebar);
}
public function getOrder()
......
......@@ -23,14 +23,14 @@ class LoadUserData extends AbstractFixture implements OrderedFixtureInterface, C
$admin = new User();
// Get configured Email Address for the Admin User
$email = $this->container->getParameter('jity_homepage.admin_email');
$config = (object) $this->container->getParameter('jity_homepage');
// Generate Admin Password
$encoder = $this->container->get('security.encoder_factory')->getEncoder($admin);
$password = $encoder->encodePassword('admin', $admin->getSalt());
$admin
->setEmail($email)
->setEmail($config->admin['email'])
->setFirstName('Admin')
->setLastName('')
->setPassword($password)
......@@ -40,6 +40,8 @@ class LoadUserData extends AbstractFixture implements OrderedFixtureInterface, C
$manager->persist($admin);
$manager->flush();
$this->addReference('admin-user', $admin);
}
public function getOrder()
......
......@@ -6,30 +6,61 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
/**
* This is the class that validates and merges configuration from your app/config files
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
* Configuration
*
* @uses ConfigurationInterface
* @version $id$
* @author Hermann Mayer <hermann.mayer92@gmail.com>
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritDoc}
* getConfigTreeBuilder
*
* @access public
* @return void
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('jity_homepage');
// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
// more information on that topic.
$rootNode
->children()
->scalarNode('admin_email')->isRequired()->end()
->end()
$rootNode
->children()
->arrayNode('admin')
->children()
->scalarNode('email')->isRequired()->end()
->end()
->end()
->arrayNode('impress')
->children()
->arrayNode('site_admin')
->children()
->scalarNode('name')->end()
->scalarNode('address')->end()
->scalarNode('zipcode')->end()
->scalarNode('city')->end()
->end()
->end()
->arrayNode('content_manager')
->children()
->scalarNode('name')->end()
->scalarNode('address')->end()
->scalarNode('zipcode')->end()
->scalarNode('city')->end()
->end()
->end()
->arrayNode('contact')
->children()
->scalarNode('phone')->end()
->scalarNode('email')->end()
->end()
->end()
->end()
->end()
;
return $treeBuilder;
}
}
......@@ -22,7 +22,9 @@ class JityHomepageExtension extends Extension
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$container->setParameter('jity_homepage.admin_email', $config['admin_email']);
$container->setParameter('jity_homepage', $config);
// echo '<pre>';var_dump($config);exit;
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
......
<?php
namespace Jity\HomepageBundle\Entity;
namespace Jity\HomepageBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="hp_category")
*/
class Category
/**
* @ORM\Entity
* @ORM\Table(name="category")
*/
class Category
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=100, unique=true)
*/
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=100, unique=true)
*/
protected $name;
/**
* @ORM\OneToMany(targetEntity="Page", mappedBy="category")
**/
**/
protected $pages;
......@@ -51,6 +51,7 @@ class Category
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
......@@ -71,6 +72,7 @@ class Category
public function addPage(\Jity\HomepageBundle\Entity\Page $pages)
{
$this->pages[] = $pages;
return $this;
}
/**
......@@ -82,11 +84,11 @@ class Category
{
return $this->pages;
}
/**
* Replace this Category on all Pages which use this Category
*
* @return void
/**
* Replace this Category on all Pages which use this Category
*
* @return void
*/
public function replaceCategoryOnPages(\Jity\HomepageBundle\Entity\Category $category)
{
......
<?php
namespace Jity\HomepageBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="contact")
*/
class Contact
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string")
*/
protected $email;
/**
* @ORM\Column(type="string", length=100)
*/
protected $name;
/**
* @ORM\Column(type="text")
**/
protected $message;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set email
*
* @param string $email
* @return Contact
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set name
*
* @param string $name
* @return Contact
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set message
*
* @param string $message
* @return Contact
*/
public function setMessage($message)
{
$this->message = $message;
return $this;
}
/**
* Get message
*
* @return string
*/
public function getMessage()
{
return $this->message;
}
}
<?php
namespace Jity\HomepageBundle\Entity;
namespace Jity\HomepageBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\Role\RoleInterface;
/**
* @ORM\Entity
* @ORM\Table(name="hp_group")
*/
class Group implements RoleInterface, \Serializable
/**
* @ORM\Entity
* @ORM\Table(name="`group`")
*/
class Group implements RoleInterface, \Serializable
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="name", type="string", length=30)
*/
......@@ -112,35 +112,35 @@ class Group implements RoleInterface, \Serializable
return $this->users;
}
/**
/**
* Serializes the content of the current User object
*
* @return string
*/
public function serialize()
{
return \json_encode(
*