Jafix

EventController.php

Mar 8th, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.80 KB | None | 0 0
  1. <?php
  2. namespace Jpg\Events\Controller;
  3.  
  4. /*                                                                        *
  5.  * This script belongs to the TYPO3 Flow package "Jpg.Events".           *
  6.  *                                                                        *
  7.  *                                                                        */
  8.  
  9. use TYPO3\Flow\Annotations as Flow;
  10.  
  11. /**
  12.  * Event controller for the Jpg.Events package
  13.  *
  14.  * @Flow\Scope("singleton")
  15.  */
  16. class EventController extends \TYPO3\Flow\Mvc\Controller\ActionController {
  17.  
  18.     /**
  19.     * @var Jpg\Events\Domain\Repository\EventRepository
  20.     * @Flow\Inject
  21.     */
  22.     protected $eventRepository;
  23.  
  24.     /**
  25.     * @var Jpg\Events\Domain\Repository\LocationRepository
  26.     * @Flow\Inject
  27.     */
  28.     protected $locationRepository;
  29.  
  30.     /**
  31.     * @var Jpg\Events\Domain\Repository\PersonRepository
  32.     * @Flow\Inject
  33.     */
  34.     protected $personRepository;
  35.  
  36.     /**
  37.      * @return void
  38.      */
  39.     public function listAction() {
  40.         $eventList = $this->eventRepository->findAll();
  41.         $this->view->assign('events', $eventList);
  42.  
  43.  
  44.     }
  45.  
  46.     /**
  47.      * Index action
  48.      *(at)log before (logger = MyLog, severity = WARNING, message = "Called my indexAction with $someArgument")
  49.      *
  50.      * @return void
  51.      * (at)log before (severity = JAFIX, message = "Called my indexAction")
  52.      */
  53.     public function indexAction() {
  54.         /*$event = new \Jpg\Events\Domain\Model\Event();
  55.         $event->setTitle('My Event Title 2');
  56.         $this->eventRepository->add($event);*/
  57.     }
  58.  
  59.     /**
  60.      * newAction
  61.      * this action will only load the template and display the
  62.      * form for adding a new event
  63.      *
  64.      * @return void
  65.      */
  66.     public function newAction() {
  67.         /*
  68.          * Hint for this: http://forge.typo3.org/projects/package-typo3-blog/repository/revisions/master/entry/Classes/TYPO3/Blog/Controller/PostController.php
  69.          * */
  70.  
  71.         $newEvent = new \Jpg\Events\Domain\Model\Event();
  72.         $this->view->assign('newEvent', $newEvent);
  73.         $this->view->assign('locations', $this->locationRepository->findAll());
  74.         $this->view->assign('persons', $this->personRepository->findAll());
  75.     }
  76.  
  77.     /**
  78.      * @param \Jpg\Events\Domain\Model\Event $events
  79.      * @return void
  80.      */
  81.     public function createAction(\Jpg\Events\Domain\Model\Event $event) {
  82.         $this->eventRepository->add($event);
  83.         $this->redirect('list');
  84.     }
  85.  
  86.     /**
  87.      * Shows a form for editing an existing location object
  88.      *
  89.      * @param \Jpg\Events\Domain\Model\Event $event The event to edit
  90.      * @return void
  91.      */
  92.     public function editAction(\Jpg\Events\Domain\Model\Event $event) {
  93.         $this->view->assign('event', $event);
  94.         $this->view->assign('locations', $this->locationRepository->findAll());
  95.         $this->view->assign('persons', $this->personRepository->findAll() );
  96.     }
  97.  
  98.     /**
  99.      * Updates the given location object
  100.      *
  101.      * @param \Jpg\Events\Domain\Model\Event $event The event to update
  102.      * @return void
  103.      */
  104.     public function updateAction(\Jpg\Events\Domain\Model\Event $event) {
  105.         $this->eventRepository->update($event);
  106.         $this->addFlashMessage('Updated the event.');
  107.         $this->redirect('list');
  108.     }
  109.  
  110.     /**
  111.      * Deletes an existing event
  112.      *
  113.      * @param \Jpg\Events\Domain\Model\Event $event The event to remove
  114.      * @return void
  115.      */
  116.     public function deleteAction(\Jpg\Events\Domain\Model\Event $event) {
  117.         $this->eventRepository->remove($event);
  118.         $this->addFlashMessage('The event has been deleted.');
  119.         $this->redirect('list');
  120.     }
  121.  
  122.  
  123.  
  124.     /*Hint from: http://www.derhansen.de/2012/10/override-flashmessages-in-typo3-flow.html.html*/
  125.     /**
  126.      * @return \TYPO3\Flow\Error\Message
  127.      */
  128.     protected function getErrorFlashMessage() {
  129.      switch ($this->actionMethodName) {
  130.       case 'createAction' :
  131.        return new \TYPO3\Flow\Error\Message('Could not save form, because some fields are not filled out correctly');
  132.       default:
  133.        return parent::getErrorFlashMessage();
  134.      }
  135.     }
  136.  
  137.  
  138.  
  139. }
  140.  
  141. ?>
Advertisement
Add Comment
Please, Sign In to add comment