예제 #1
0
 public function addAction()
 {
     $form = new MenuForm();
     $resultSet = $this->getEntityManager()->getRepository('Cms\\Entity\\Category')->findAll();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter(new MenuFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $form->getData();
             unset($data['submit']);
             $this->getMenusTable()->insert($data);
             return $this->redirect()->toRoute('cms/default', array('controller' => 'menu', 'action' => 'index'));
         }
     }
     return new ViewModel(array('form' => $form, 'categories' => $resultSet));
 }
예제 #2
0
 public function saveAction()
 {
     $jsonModel = new JsonModel();
     $form = new MenuForm();
     if ($this->getRequest()->isPost()) {
         $data = $this->params()->fromPost();
         $em = $this->getEntityManager();
         if ($id = $data['id']) {
             $menuRes = $em->getRepository('Base\\Entity\\Menu')->find($id);
         } else {
             $menuRes = new \Base\Entity\Menu();
         }
         $form->bind($menuRes);
         $form->setData($data);
         if ($form->isValid()) {
             $params['max_records'] = $data['max_records'];
             $params['order_kind'] = $data['order_kind'];
             $params['term'] = $data['term'];
             if (isset($data['parent_id'])) {
                 $parentRes = $em->getRepository('base\\Entity\\Menu')->find($data['parent_id']);
                 if (!($orderId = (int) $data['order_id'])) {
                     $orderId = count($parentRes->getMenus()) + 1;
                 }
                 $menuRes->setMenu($parentRes);
                 $menuRes->setOrderId($orderId);
             }
             $menuRes->setParams(serialize($params));
             $menuRes->setUpdateTime(new \DateTime());
             $menuRes->setUser($em->getReference('Base\\Entity\\user', $this->UserIdentity()->getId()));
             $em->persist($menuRes);
             $em->flush();
             $jsonModel->setVariable('success', true);
         } else {
             $jsonModel->setVariable('success', false);
             $jsonModel->setVariable('message', $form->getMessages());
         }
     }
     return $jsonModel;
 }
예제 #3
0
 /**
  * Edit menu
  * 
  * 
  * @access public
  * @uses MenuForm
  * 
  * @return ViewModel
  */
 public function editAction()
 {
     $variables = array();
     $id = $this->params('id');
     $query = $this->getServiceLocator()->get('wrapperQuery');
     $menuObj = $query->find('CMS\\Entity\\Menu', $id);
     $form = new MenuForm();
     $form->bind($menuObj);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $data = $request->getPost()->toArray();
         $form->setInputFilter($menuObj->getInputFilter($query));
         $form->setData($data);
         if ($form->isValid()) {
             $query->save($menuObj);
             $url = $this->getEvent()->getRouter()->assemble(array('action' => 'index'), array('name' => 'cmsMenu'));
             $this->redirect()->toUrl($url);
         }
     }
     $variables['menuForm'] = $this->getFormView($form);
     return new ViewModel($variables);
 }