Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Jpg\Events\Controller;
- /* *
- * This script belongs to the TYPO3 Flow package "Jpg.Events". *
- * *
- * */
- use TYPO3\Flow\Annotations as Flow;
- /**
- * Event controller for the Jpg.Events package
- *
- * @Flow\Scope("singleton")
- */
- class EventController extends \TYPO3\Flow\Mvc\Controller\ActionController {
- /**
- * @var Jpg\Events\Domain\Repository\EventRepository
- * @Flow\Inject
- */
- protected $eventRepository;
- /**
- * @var Jpg\Events\Domain\Repository\LocationRepository
- * @Flow\Inject
- */
- protected $locationRepository;
- /**
- * @var Jpg\Events\Domain\Repository\PersonRepository
- * @Flow\Inject
- */
- protected $personRepository;
- /**
- * @return void
- */
- public function listAction() {
- $eventList = $this->eventRepository->findAll();
- $this->view->assign('events', $eventList);
- }
- /**
- * Index action
- *(at)log before (logger = MyLog, severity = WARNING, message = "Called my indexAction with $someArgument")
- *
- * @return void
- * (at)log before (severity = JAFIX, message = "Called my indexAction")
- */
- public function indexAction() {
- /*$event = new \Jpg\Events\Domain\Model\Event();
- $event->setTitle('My Event Title 2');
- $this->eventRepository->add($event);*/
- }
- /**
- * newAction
- * this action will only load the template and display the
- * form for adding a new event
- *
- * @return void
- */
- public function newAction() {
- /*
- * Hint for this: http://forge.typo3.org/projects/package-typo3-blog/repository/revisions/master/entry/Classes/TYPO3/Blog/Controller/PostController.php
- * */
- $newEvent = new \Jpg\Events\Domain\Model\Event();
- $this->view->assign('newEvent', $newEvent);
- $this->view->assign('locations', $this->locationRepository->findAll());
- $this->view->assign('persons', $this->personRepository->findAll());
- }
- /**
- * @param \Jpg\Events\Domain\Model\Event $events
- * @return void
- */
- public function createAction(\Jpg\Events\Domain\Model\Event $event) {
- $this->eventRepository->add($event);
- $this->redirect('list');
- }
- /**
- * Shows a form for editing an existing location object
- *
- * @param \Jpg\Events\Domain\Model\Event $event The event to edit
- * @return void
- */
- public function editAction(\Jpg\Events\Domain\Model\Event $event) {
- $this->view->assign('event', $event);
- $this->view->assign('locations', $this->locationRepository->findAll());
- $this->view->assign('persons', $this->personRepository->findAll() );
- }
- /**
- * Updates the given location object
- *
- * @param \Jpg\Events\Domain\Model\Event $event The event to update
- * @return void
- */
- public function updateAction(\Jpg\Events\Domain\Model\Event $event) {
- $this->eventRepository->update($event);
- $this->addFlashMessage('Updated the event.');
- $this->redirect('list');
- }
- /**
- * Deletes an existing event
- *
- * @param \Jpg\Events\Domain\Model\Event $event The event to remove
- * @return void
- */
- public function deleteAction(\Jpg\Events\Domain\Model\Event $event) {
- $this->eventRepository->remove($event);
- $this->addFlashMessage('The event has been deleted.');
- $this->redirect('list');
- }
- /*Hint from: http://www.derhansen.de/2012/10/override-flashmessages-in-typo3-flow.html.html*/
- /**
- * @return \TYPO3\Flow\Error\Message
- */
- protected function getErrorFlashMessage() {
- switch ($this->actionMethodName) {
- case 'createAction' :
- return new \TYPO3\Flow\Error\Message('Could not save form, because some fields are not filled out correctly');
- default:
- return parent::getErrorFlashMessage();
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment