Commit 14c55f7b authored by Hermann Mayer's avatar Hermann Mayer

Just reworked the whole project to fit the Symfony2 Coding Standard. (So all files were touched :)

parent 0efc1abc
<?php
/*
* This file is part of the Jity package.
*
* (c) Hermann Mayer <hermann.mayer92@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Jity\HomepageBundle\Controller;
use Jity\HomepageBundle\JityHomepageBundle;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Jity\HomepageBundle\JityHomepageBundle,
Symfony\Bundle\FrameworkBundle\Controller\Controller;
/**
* AdminController
*
* @uses Controller
* @version $id$
* @author Hermann Mayer <hermann.mayer92@gmail.com>
* AdminController
*
* The Admin Controller allows you to administrate the application.
*
* @uses Controller
* @author Hermann Mayer <hermann.mayer92@gmail.com>
*/
class AdminController extends Controller
{
/**
* showDashboardAction
*
* showDashboardAction
*
* Show the dashboard of the admin area.
*
* @access public
* @return void
* @return Response
*/
public function showDashboardAction()
{
......
<?php
namespace Jity\HomepageBundle\Controller;
/*
* This file is part of the Jity package.
*
* (c) Hermann Mayer <hermann.mayer92@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
namespace Jity\HomepageBundle\Controller;
use Jity\HomepageBundle\Entity\Article;
use Jity\HomepageBundle\Form\ArticleType;
use Symfony\Component\HttpFoundation\Request,
Symfony\Bundle\FrameworkBundle\Controller\Controller,
Jity\HomepageBundle\Entity\Article,
Jity\HomepageBundle\Form\ArticleType;
/**
* Article controller.
* ArticleController
*
* The Article Controller allows you to CRUD articles.
*
* @uses Controller
* @author Hermann Mayer <hermann.mayer92@gmail.com>
*/
class ArticleController extends Controller
{
/**
* Lists all Article entities.
* indexAction
*
* Show a overview of all articles.
*
* @access public
* @return Response
*/
public function indexAction()
{
......@@ -30,8 +46,14 @@ class ArticleController extends Controller
}
/**
* showAction
*
* Finds and displays a Article entity.
*
* @param int $id Id of the article to show
*
* @access public
* @return Response
*/
public function showAction($id)
{
......@@ -47,12 +69,17 @@ class ArticleController extends Controller
return $this->render('JityHomepageBundle:Article:show.html.twig', array(
'entity' => $entity,
'delete_form' => $deleteForm->createView(), ));
'delete_form' => $deleteForm->createView()
));
}
/**
* newAction
*
* Displays a form to create a new Article entity.
*
* @access public
* @return Response
*/
public function newAction()
{
......@@ -61,13 +88,19 @@ class ArticleController extends Controller
return $this->render('JityHomepageBundle:Article:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
'form' => $form->createView()
));
}
/**
* createAction
*
* Creates a new Article entity.
*
* @param Request $request Request Object
*
* @access public
* @return Response
*/
public function createAction(Request $request)
{
......@@ -78,7 +111,11 @@ class ArticleController extends Controller
if ($form->isValid()) {
// Set current User as Author
$user = $this->container->get('security.context')->getToken()->getUser();
$user = $this->container
->get('security.context')
->getToken()
->getUser();
$entity->setAuthor($user);
$em = $this->getDoctrine()->getManager();
......@@ -88,18 +125,28 @@ class ArticleController extends Controller
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('author_article_show', array('id' => $entity->getId())));
return $this->redirect(
$this->generateUrl('author_article_show', array(
'id' => $entity->getId()
))
);
}
return $this->render('JityHomepageBundle:Article:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
'form' => $form->createView()
));
}
/**
* editAction
*
* Displays a form to edit an existing Article entity.
*
* @param mixed $id Id of the article to edit
*
* @access public
* @return Response
*/
public function editAction($id)
{
......@@ -117,13 +164,20 @@ class ArticleController extends Controller
return $this->render('JityHomepageBundle:Article:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
'delete_form' => $deleteForm->createView()
));
}
/**
* updateAction
*
* Edits an existing Article entity.
*
* @param Request $request Request Object
* @param int $id Id of the article to update
*
* @access public
* @return Response
*/
public function updateAction(Request $request, $id)
{
......@@ -147,7 +201,11 @@ class ArticleController extends Controller
if ($editForm->isValid()) {
// Set current User as Author
$user = $this->container->get('security.context')->getToken()->getUser();
$user = $this->container
->get('security.context')
->getToken()
->getUser();
$entity->setAuthor($user);
$entity = $this->mergeEntity($request, $em, $editForm, $entity);
......@@ -155,10 +213,15 @@ class ArticleController extends Controller
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('author_article_edit', array('id' => $id)));
return $this->redirect(
$this->generateUrl('author_article_edit', array(
'id' => $id
))
);
}
return $this->render('JityHomepageBundle:Article:edit.html.twig', array(
return $this->render(
'JityHomepageBundle:Article:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
......@@ -172,12 +235,13 @@ class ArticleController extends Controller
* will be connected instead of new inserted and
* changes to the connected entites will be merged.
*
* @param Request $request
* @param mixed $em
* @param mixed $form
* @param mixed $entity
* @param Request $request Request Object
* @param mixed $em Doctrine Entity Manager
* @param mixed $form Form Instance
* @param mixed $entity Entity to work on
*
* @access private
* @return void
* @return Article
*/
private function mergeEntity(Request $request, $em, $form, $entity)
{
......@@ -188,7 +252,6 @@ class ArticleController extends Controller
if (null !== $tag->getId()) {
$entity->removeTag($tag);
// $tag = $em->getRepository('JityHomepageBundle:Tag')->find($tag->getId());
$tag = $em->merge($tag);
array_walk($postData['tags'], function($item, $key) use($tag)
......@@ -206,8 +269,15 @@ class ArticleController extends Controller
}
/**
* deleteAction
*
* Deletes a Article entity.
*
* @param Request $request Request Object
* @param int $id Id of the article to remove
*
* @access public
* @return Response
*/
public function deleteAction(Request $request, $id)
{
......@@ -232,15 +302,18 @@ class ArticleController extends Controller
/**
* createDeleteForm
*
* @param mixed $id
* Create a form for deletion.
*
* @param mixed $id Id to embed as a hidden field in the form
*
* @access private
* @return void
* @return Form
*/
private function createDeleteForm($id)
{
return $this->createFormBuilder(array('id' => $id))
->add('id', 'hidden')
->getForm()
;
->getForm();
}
}
<?php
/*
* This file is part of the Jity package.
*
* (c) Hermann Mayer <hermann.mayer92@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Jity\HomepageBundle\Controller;
use Jity\HomepageBundle\JityHomepageBundle;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Jity\HomepageBundle\JityHomepageBundle,
Symfony\Bundle\FrameworkBundle\Controller\Controller;
/**
* AuthorController
*
* @uses Controller
* @version $id$
* @author Hermann Mayer <hermann.mayer92@gmail.com>
* AuthorController
*
* The Author Controller allows you to write content for the application.
*
* @uses Controller
* @author Hermann Mayer <hermann.mayer92@gmail.com>
*/
class AuthorController extends Controller
{
/**
* showDashboardAction
*
* showDashboardAction
*
* Show the dashboard of the author area.
*
* @access public
* @return void
* @return Response
*/
public function showDashboardAction()
{
......
<?php
/*
* This file is part of the Jity package.
*
* (c) Hermann Mayer <hermann.mayer92@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Jity\HomepageBundle\Controller;
use Jity\HomepageBundle\Entity\Article,
......@@ -10,47 +19,61 @@ use Jity\HomepageBundle\Entity\Article,
Symfony\Bundle\FrameworkBundle\Controller\Controller;
/**
* BlogController
*
* @uses Controller
* @version $id$
* @author Hermann Mayer <hermann.mayer92@gmail.com>
* BlogController
*
* The Blog Controller allows you to CRUD comments of an article.
*
* @uses Controller
* @author Hermann Mayer <hermann.mayer92@gmail.com>
*/
class BlogController extends Controller
{
/**
* showAction
*
* @param mixed $slug
* showAction
*
* Show an article.
*
* @param string $slug Slug of the article to show
* @param string $_format Response Format
*
* @access public
* @return void
* @return Response
*/
public function showAction($slug, $_format)
{
// Get Entity Manager
$em = $this->getDoctrine()->getEntityManager();
// Try to get the requested Page
if (!empty($slug)) {
$article = $em->getRepository('JityHomepageBundle:Article')->findOneBySlug($slug);
$article = $em->getRepository('JityHomepageBundle:Article')
->findOneBySlug($slug);
}
// Article was not found
if (!$article) {
return $this->forward('JityHomepageBundle:Default:showInfo', array('template' => 'homepage_notfound'));
return $this->forward('JityHomepageBundle:Default:showInfo', array(
'template' => 'homepage_notfound')
);
}
// Return the rendered result
return $this->render('JityHomepageBundle:Blog:show_article.' . $_format . '.twig', array(
'article' => $article
));
return $this->render(
'JityHomepageBundle:Blog:show_article.' . $_format . '.twig', array(
'article' => $article
));
}
/**
* sectionArchivAction
*
* sectionArchivAction
*
* Build an archiv-map of all articles for
* printing this as a Sidebar Section.
*
* @access public
* @return void
* @return Response
*/
public function sectionArchivAction()
{
......@@ -60,8 +83,7 @@ class BlogController extends Controller
$q = $em->createQueryBuilder()
->select('a.createdAt')
->from('JityHomepageBundle:Article', 'a')
->getQuery()
;
->getQuery();
$archivMap = array();
......@@ -72,8 +94,9 @@ class BlogController extends Controller
$year = $date->format('Y');
$month = $date->format('F');
if (array_key_exists($year, $archivMap) && array_key_exists($month, $archivMap[$year])) {
if (array_key_exists($year, $archivMap) &&
array_key_exists($month, $archivMap[$year])) {
// We found a existing year/month combo -> increase counter
$archivMap[$year][$month]++;
......@@ -84,29 +107,41 @@ class BlogController extends Controller
}
}
return $this->render('JityHomepageBundle:Blog:archiv_section.html.twig', array(
'map' => $archivMap,
));
return $this->render(
'JityHomepageBundle:Blog:archiv_section.html.twig', array(
'map' => $archivMap,
));
}
/**
* createCommentFormAction
*
* @param mixed $comment
* @param mixed $form
* @param mixed $action
* @param mixed $renderFormTag
* @param mixed $visible
* createCommentFormAction
*
* Create a form for creating a comment.
*
* @param mixed $comment Prebuild Comment which fill the form
* @param mixed $form Prebuild Form which will be used
* @param mixed $action Action URI for the form
* @param boolean $renderFormTag Render the HTML form tags
* @param boolean $visible Should the form be visible by default
*
* @access public
* @return void
* @return Response
*/
public function createCommentFormAction($comment = null, $form = null, $action = null, $renderFormTag = true, $visible = true)
public function createCommentFormAction(
$comment = null,
$form = null,
$action = null,
$renderFormTag = true,
$visible = true)
{
if (!$form) {
$form = $this
->createForm(new CommentType(), (!$comment) ? new Comment() : $comment)
->createView()
;
->createForm(
new CommentType(),
(!$comment) ? new Comment() : $comment
)
->createView();
}
return $this->render('JityHomepageBundle:Form:render.html.twig', array(
......@@ -118,11 +153,15 @@ class BlogController extends Controller
}
/**
* createCommentAction
*
* @param Request $request
* createCommentAction
*
* Creates a new Comment entity.
*
* @param Request $request Request Object
* @param mixed $id Id of the article to connect the comment to
*
* @access public
* @return void
* @return Response
*/
public function createCommentAction(Request $request, $id)
{
......@@ -172,12 +211,15 @@ class BlogController extends Controller
}
/**
* deleteCommentAction
*
* @param Request $request
* @param mixed $id
* deleteCommentAction
*
* Deletes a Comment entity from a Article entity.
*
* @param Request $request Request Object
* @param mixed $id Id of the comment to remove from the article
*
* @access public
* @return void
* @return Response
*/
public function deleteCommentAction(Request $request, $id)
{
......@@ -208,34 +250,40 @@ class BlogController extends Controller
}
/**
* deleteCommentFormAction
*
* @param mixed $id
* @param mixed $renderForm
* @param mixed $action
* deleteCommentFormAction
*
* Create a form for comment deletion.
*
* @param int $id Id to embed as a hidden field in the form
* @param boolean $renderForm Render the form to a view, or leave it raw
* @param string $action Action URI for the form
*
* @access public
* @return void
* @return Response
*/
public function deleteCommentFormAction($id, $renderForm = false, $action = null)
{
$form = $this->createFormBuilder(array('id' => $id))
->add('id', 'hidden')
->getForm()
;
->getForm();
return (!$renderForm) ? $form : $this->render('JityHomepageBundle:Form:render.html.twig', array(
'form' => $form->createView(),
'action' => $action
));
return (!$renderForm) ? $form : $this->render(
'JityHomepageBundle:Form:render.html.twig', array(
'form' => $form->createView(),
'action' => $action
));
}
/**
* updateCommentAction
*
* @param Request $request
* @param mixed $id
* updateCommentAction
*
* Edits an existing Comment entity.
*
* @param Request $request Request Object
* @param mixed $id Id of the comment to update
*
* @access public
* @return void
* @return Response
*/
public function updateCommentAction(Request $request, $id)
{
......
<?php
/*
* This file is part of the Jity package.
*
* (c) Hermann Mayer <hermann.mayer92@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Jity\HomepageBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Jity\HomepageBundle\Entity\Category;
use Jity\HomepageBundle\Form\CategoryType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller,
Jity\HomepageBundle\Entity\Category,
Jity\HomepageBundle\Form\CategoryType;
/**
* CategoryController
*
* @uses Controller
* @version $id$
* @author Hermann Mayer <hermann.mayer92@gmail.com>
* CategoryController
*
* The Category Controller allows you to CRUD categories.
*
* @uses Controller
* @author Hermann Mayer <hermann.mayer92@gmail.com>
*/
class CategoryController extends Controller
{
/**
* indexAction
*
* indexAction
*
* Show a overview of all articles.
*
* @access public
* @return void
* @return Response
*/
public function indexAction()
{
......@@ -33,11 +45,14 @@ class CategoryController extends Controller
}
/**
* showAction
*
* @param mixed $id
* showAction
*
* Finds and displays a Category entity.
*
* @param int $id Id of the category to show
*
* @access public
* @return void
* @return Response