Ejemplo n.º 1
0
 /**
  * Nowa wersja juz istniejacej templatki
  *
  * @return void
  */
 public function addversionAction()
 {
     $request = $this->getRequest();
     $id = $this->_helper->IdConvert->hexToStr($request->getParam('id'));
     $form = new Logic_Ws_Template_Form_NewVersion();
     if ($request->isPost()) {
         if ($form->isCancelled($this->getRequest()->getPost())) {
             $this->_helper->redirector('index', null, null);
             return;
         } elseif ($form->isValid($request->getPost())) {
             try {
                 $values = $form->getValues();
                 $newest = $this->_model->getTemplateNewest($values['template_name']);
                 if ($newest->template_content_hash == md5($values['template_content'])) {
                     $this->_helper->messenger->error('Zawartość templatki nie zmieniła się');
                     return;
                 }
                 $values['ws_client_id'] = $newest->ws_client_id;
                 $values['template_content_hash'] = md5($values['template_content']);
                 $values['version_num'] = $newest->version_num + 1;
                 $this->_model->addTemplate($values);
                 $this->_helper->messenger->success();
                 $this->_helper->redirector('index');
                 return;
             } catch (Logic_Ws_Exception $e) {
                 $this->_helper->messenger->error();
             }
         }
     } else {
         $data = array();
         try {
             $data = $this->_model->getTemplateWithOwner($id);
             $newest = $this->_model->getTemplateNewest($data->template_name);
             if ($data->version_num < $newest->version_num) {
                 $this->_helper->messenger->error('Ta templatka ma już nowszą wersję');
                 $this->_helper->redirector('index');
                 return;
             }
         } catch (Zend_Db_Exception $e) {
             $this->_helper->messenger->error();
             $this->_helper->redirector('index');
             return;
         }
         $form->setDefaults($data->toArray());
     }
     $this->view->form = $form;
 }