From 290d04464c50a466de0c8f73b436043e9d31323e Mon Sep 17 00:00:00 2001 From: kokspflanze Date: Sat, 2 May 2015 03:06:21 +0200 Subject: [PATCH] added options in forms --- src/ZfcTicketSystem/Form/TicketSystem.php | 120 +++++++++--------- .../Form/TicketSystemFilter.php | 13 +- src/ZfcTicketSystem/Module.php | 2 +- 3 files changed, 70 insertions(+), 65 deletions(-) diff --git a/src/ZfcTicketSystem/Form/TicketSystem.php b/src/ZfcTicketSystem/Form/TicketSystem.php index 2de8a35..fe574bd 100644 --- a/src/ZfcTicketSystem/Form/TicketSystem.php +++ b/src/ZfcTicketSystem/Form/TicketSystem.php @@ -2,73 +2,75 @@ namespace ZfcTicketSystem\Form; +use Zend\ServiceManager\ServiceManager; use Zend\Form\Form; use Zend\Form\Element; use ZfcBase\Form\ProvidesEventsForm; -use Doctrine\ORM\EntityManager; class TicketSystem extends ProvidesEventsForm { - - public function __construct( EntityManager $entityManager ) + /** + * @param ServiceManager $serviceLocator + */ + public function __construct( ServiceManager $serviceLocator ) { - parent::__construct(); - $this->add(array( - 'type' => 'Zend\Form\Element\Csrf', - 'name' => 'fdh456eh56ujzum45zkuik45zhrh' - )); + parent::__construct(); + $this->add(array( + 'type' => 'Zend\Form\Element\Csrf', + 'name' => 'fdh456eh56ujzum45zkuik45zhrh' + )); - $this->add(array( - 'name' => 'subject', - 'options' => array( - 'label' => 'Subject', - ), - 'attributes' => array( - 'placeholder' => 'Subject', - 'class' => 'form-control', - 'type' => 'text' - ), - )); - $this->add(array( - 'name' => 'categoryId', - 'type' => 'DoctrineModule\Form\Element\ObjectSelect', - 'options' => array( - 'object_manager'=> $entityManager, - 'target_class' => 'ZfcTicketSystem\Entity\TicketCategory', - 'property' => 'subject', - 'label' => 'Category', - 'empty_option' => '-- select --', - 'is_method' => true, - 'find_method' => array( - 'name' => 'getActiveCategory', - ), - ), - 'attributes' => array( - 'class' => 'form-control', - ), - )); - $this->add(array( - 'name' => 'memo', - 'type' => 'Zend\Form\Element\Textarea', - 'options' => array( - 'label' => 'Memo', - ), - 'attributes' => array( - 'placeholder' => 'Memo', - 'class' => 'form-control', - ), - )); + $this->add(array( + 'name' => 'subject', + 'options' => array( + 'label' => 'Subject', + ), + 'attributes' => array( + 'placeholder' => 'Subject', + 'class' => 'form-control', + 'type' => 'text' + ), + )); + $this->add(array( + 'name' => 'categoryId', + 'type' => 'DoctrineModule\Form\Element\ObjectSelect', + 'options' => array( + 'object_manager'=> $serviceLocator->get( 'Doctrine\ORM\EntityManager' ), + 'target_class' => $serviceLocator->get( 'zfcticketsystem_entry_options' )->getTicketCategory(), + 'property' => 'subject', + 'label' => 'Category', + 'empty_option' => '-- select --', + 'is_method' => true, + 'find_method' => array( + 'name' => 'getActiveCategory', + ), + ), + 'attributes' => array( + 'class' => 'form-control', + ), + )); + $this->add(array( + 'name' => 'memo', + 'type' => 'Zend\Form\Element\Textarea', + 'options' => array( + 'label' => 'Memo', + ), + 'attributes' => array( + 'placeholder' => 'Memo', + 'class' => 'form-control', + ), + )); - $submitElement = new Element\Button('submit'); - $submitElement - ->setLabel('Submit') - ->setAttributes(array( - 'class' => 'btn btn-primary', - 'type' => 'submit', - )); + $submitElement = new Element\Button('submit'); + $submitElement + ->setLabel('Submit') + ->setAttributes(array( + 'class' => 'btn btn-primary', + 'type' => 'submit', + )); - $this->add($submitElement, array( - 'priority' => -100, - )); - } + $this->add($submitElement, array( + 'priority' => -100, + )); + } } \ No newline at end of file diff --git a/src/ZfcTicketSystem/Form/TicketSystemFilter.php b/src/ZfcTicketSystem/Form/TicketSystemFilter.php index eed983c..cd8c313 100644 --- a/src/ZfcTicketSystem/Form/TicketSystemFilter.php +++ b/src/ZfcTicketSystem/Form/TicketSystemFilter.php @@ -64,13 +64,13 @@ public function __construct( ServiceManager $serviceManager ) } /** - * @param ServiceManager $oServiceManager - * + * @param ServiceManager $serviceManager + * @return $this */ - public function setServiceManager( ServiceManager $oServiceManager ) + public function setServiceManager( ServiceManager $serviceManager ) { - $this->serviceManager = $oServiceManager; + $this->serviceManager = $serviceManager; return $this; } @@ -81,7 +81,10 @@ public function setServiceManager( ServiceManager $oServiceManager ) protected function getTicketCategory() { /** @var \ZfcTicketSystem\Entity\Repository\TicketCategory $ticketCategory */ - $ticketCategory = $this->getEntityManager()->getRepository('ZfcTicketSystem\Entity\TicketCategory'); + $ticketCategory = $this->getEntityManager()->getRepository( + $this->getServiceManager()->get( 'zfcticketsystem_entry_options' )->getTicketCategory() + ); + $category = $ticketCategory->getActiveCategory(); $result = array(); diff --git a/src/ZfcTicketSystem/Module.php b/src/ZfcTicketSystem/Module.php index 70063d2..87038c0 100644 --- a/src/ZfcTicketSystem/Module.php +++ b/src/ZfcTicketSystem/Module.php @@ -48,7 +48,7 @@ public function getServiceConfig() 'factories' => array( 'zfcticketsystem_ticketsystem_new_form' => function ( $sm ) { /** @var $sm \Zend\ServiceManager\ServiceLocatorInterface */ - $form = new Form\TicketSystem( $sm->get( 'Doctrine\ORM\EntityManager' ) ); + $form = new Form\TicketSystem( $sm ); $form->setInputFilter( new Form\TicketSystemFilter( $sm ) ); return $form; },