예제 #1
0
파일: Module.php 프로젝트: odegroot/ers
 public function getServiceConfig()
 {
     return array('factories' => array('doctrine.entitymanager' => new \DoctrineORMModule\Service\EntityManagerFactory('orm_default'), 'Admin\\Form\\Product' => function ($sm) {
         $form = new Form\Product();
         $em = $sm->get('doctrine.entitymanager');
         $taxes = $em->getRepository("ErsBase\\Entity\\Tax")->findAll();
         $options = array();
         foreach ($taxes as $tax) {
             $options[$tax->getId()] = $tax->getName() . ' - ' . $tax->getPercentage() . '%';
         }
         $form->get('tax_id')->setValueOptions($options);
         return $form;
     }, 'Admin\\Form\\Role' => function ($sm) {
         $form = new Form\Role();
         $em = $sm->get('doctrine.entitymanager');
         $roles = $em->getRepository("ErsBase\\Entity\\UserRole")->findBy(array(), array('roleId' => 'ASC'));
         $options = array();
         $options[null] = 'no parent';
         foreach ($roles as $role) {
             $options[$role->getId()] = $role->getRoleId();
         }
         $form->get('Parent_id')->setValueOptions($options);
         return $form;
     }, 'Admin\\Form\\ProductVariant' => function ($sm) {
         $form = new Form\ProductVariant();
         $options = array();
         $options['text'] = 'Text';
         $options['date'] = 'Date';
         $options['select'] = 'Select';
         $form->get('type')->setValueOptions($options);
         return $form;
     }, 'Admin\\InputFilter\\User' => function ($sm) {
         $inputFilter = new InputFilter\User();
         $inputFilter->setServiceLocator($sm);
         return $inputFilter;
     }, 'Admin\\InputFilter\\AcceptBuyerChange' => function ($sm) {
         $inputFilter = new InputFilter\AcceptBuyerChange();
         $inputFilter->setServiceLocator($sm);
         return $inputFilter;
     }, 'Admin\\InputFilter\\AcceptParticipantChangeItem' => function ($sm) {
         $inputFilter = new InputFilter\AcceptParticipantChangeItem();
         $inputFilter->setServiceLocator($sm);
         return $inputFilter;
     }, 'Admin\\InputFilter\\AcceptParticipantChangePackage' => function ($sm) {
         $inputFilter = new InputFilter\AcceptParticipantChangePackage();
         $inputFilter->setServiceLocator($sm);
         return $inputFilter;
     }, 'Admin\\InputFilter\\AcceptMovePackage' => function ($sm) {
         $inputFilter = new InputFilter\AcceptMovePackage();
         $inputFilter->setServiceLocator($sm);
         return $inputFilter;
     }));
 }
예제 #2
0
 public function addAction()
 {
     $product_id = (int) $this->params()->fromRoute('id', 0);
     if (!$product_id) {
         return $this->redirect()->toRoute('admin/product');
     }
     $forrest = new Service\BreadcrumbService();
     if (!$forrest->exists('product-variant')) {
         $forrest->set('product-variant', 'admin/product-variant');
     }
     $form = new Form\ProductVariant();
     $form->get('submit')->setValue('Add');
     $form->get('Product_id')->setValue($product_id);
     $options['text'] = 'Text';
     $options['select'] = 'Select';
     $options['date'] = 'Date';
     $options['datetime'] = 'Datetime';
     $form->get('type')->setAttribute('options', $options);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $productvariant = new Entity\ProductVariant();
         #$form->setInputFilter($productvariant->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
             $productvariant->populate($form->getData());
             $product = $em->getRepository("ErsBase\\Entity\\Product")->findOneBy(array('id' => $productvariant->getProductId()));
             $productvariant->setProduct($product);
             $em->persist($productvariant);
             $em->flush();
             $breadcrumb = $forrest->get('product-variant');
             return $this->redirect()->toRoute($breadcrumb->route, $breadcrumb->params, $breadcrumb->options);
         } else {
             $logger = $this->getServiceLocator()->get('Logger');
             $logger->warn($form->getMessages());
         }
     }
     $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $product = $em->getRepository("ErsBase\\Entity\\Product")->findOneBy(array('id' => $product_id));
     $breadcrumb = $forrest->get('product-variant');
     return new ViewModel(array('breadcrumb' => $breadcrumb, 'product' => $product, 'form' => $form));
 }