public function editpostAction() { if ($datas = $this->getRequest()->getPost()) { try { $application = $this->getApplication(); // Test s'il y a un value_id if (empty($datas['value_id'])) { throw new Exception($this->_('An error occurred while saving')); } if (empty($datas['title'])) { throw new Exception($this->_('Folder title is required')); } // Récupère l'option_value en cours $option_value = new Application_Model_Option_Value(); $option_value->find($datas['value_id']); $folder = new Folder_Model_Folder(); $category = new Folder_Model_Category(); if (!empty($datas['category_id'])) { $category->find($datas['category_id'], 'category_id'); } if ($datas['parent_id'] == 'null') { unset($datas['parent_id']); //Assigne le nom de catégorie root à la feature $option_value->setTabbarName($datas['title'])->save(); } else { $datas['pos'] = $category->getNextCategoryPosition($datas['parent_id']); } if (!empty($datas['file'])) { $relative_path = '/folder/'; $path = Application_Model_Application::getBaseImagePath() . $relative_path; $file = Core_Model_Directory::getTmpDirectory(true) . '/' . $datas['file']; if (!is_dir($path)) { mkdir($path, 0777, true); } if (!copy($file, $path . $datas['file'])) { throw new exception($this->_('An error occurred while saving. Please try again later.')); } else { $datas['picture'] = $relative_path . $datas['file']; } } else { if (!empty($datas['remove_picture'])) { $datas['picture'] = null; } } $category->addData($datas)->save(); //Change root category if (!isset($datas['parent_id'])) { $folder->find($option_value->getId(), 'value_id'); $folder->setValueId($datas['value_id'])->setRootCategoryId($category->getId())->save(); $parent_id = 'null'; } else { $parent_id = $datas['parent_id']; } $html = array('success' => '1', 'success_message' => $this->_('Infos successfully saved'), 'category_id' => $category->getId(), 'parent_id' => $parent_id, 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0); } catch (Exception $e) { $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }
public function settabbarnameAction() { if ($datas = $this->getRequest()->getPost()) { try { // Test les données if (empty($datas['option_value_id']) or empty($datas['tabbar_name'])) { throw new Exception($this->_('An error occurred while saving your page name.')); } // Charge l'option_value $option_value = new Application_Model_Option_Value(); $option_value->setApplication($this->getApplication()); $option_value->find($datas['option_value_id']); // Test s'il n'y a pas embrouille entre l'id de l'application dans l'option_value et l'id de l'application en session if (!$option_value->getId()) { throw new Exception($this->_('An error occurred while saving your page name.')); } $option_folder = new Application_Model_Option(); $option_folder->find(array('code' => 'folder')); $option_folder_id = $option_folder->getOptionId(); if ($option_value->getOptionId() == $option_folder_id) { $folder = new Folder_Model_Folder(); $folder->find($datas['option_value_id'], 'value_id'); $category = new Folder_Model_Category(); $category->find($folder->getRootCategoryId(), 'category_id'); $category->setTitle($datas['tabbar_name'])->save(); } if (in_array($option_value->getId(), array('customer_account', 'more_items'))) { $code = $option_value->getId() == 'customer_account' ? 'tabbar_account_name' : 'tabbar_more_name'; $this->getApplication()->setData($code, $datas['tabbar_name'])->save(); } else { $option_value->setTabbarName($datas['tabbar_name'])->save(); } // Renvoie OK $html = array('success' => 1); } catch (Exception $e) { $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }