Exemple #1
0
 public function editAction()
 {
     header('Content-type: application/json');
     $this->_helper->viewRenderer->setNoRender();
     $this->_helper->getHelper('layout')->disableLayout();
     $request = $this->getRequest();
     $id = $this->_getParam('id', 0);
     $activeTab = $request->getCookie('tab', null);
     $categoryDb = new Admin_Model_DbTable_Category();
     $category = $categoryDb->getCategory($id);
     if ($this->isLocked($category['locked'], $category['lockedtime'])) {
         if ($request->isPost()) {
             header('Content-type: application/json');
             $this->_helper->viewRenderer->setNoRender();
             $this->_helper->getHelper('layout')->disableLayout();
             echo Zend_Json::encode(array('message' => $this->view->translate('MESSAGES_LOCKED')));
         } else {
             $this->_flashMessenger->addMessage('MESSAGES_LOCKED');
             $this->_helper->redirector('index');
         }
     } else {
         $categoryDb->lock($id, $this->_user['id'], $this->_date);
         $form = new Admin_Form_Category();
         $options = $this->_helper->Options->getOptions($form);
         $params = $this->_helper->Params->getParams($form, $options);
         $categories = $this->_helper->Categories->getCategories($form, $params['clientid'], $params['type']);
         if ($request->isPost()) {
             $data = $request->getPost();
             $element = key($data);
             if (isset($form->{$element}) && $form->isValidPartial($data)) {
                 $data['modified'] = $this->_date;
                 $data['modifiedby'] = $this->_user['id'];
                 $categoryDb = new Admin_Model_DbTable_Category();
                 $categoryDb->updateCategory($id, $data);
                 echo Zend_Json::encode($categoryDb->getCategory($id));
             } else {
                 echo Zend_Json::encode(array('message' => $this->view->translate('MESSAGES_FORM_IS_INVALID')));
             }
         }
     }
     $this->view->messages = $this->_flashMessenger->getMessages();
 }