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 findallAction() { if ($value_id = $this->getRequest()->getParam('value_id')) { try { $category_id = $this->getRequest()->getParam('category_id'); $current_category = new Folder_Model_Category(); if ($category_id) { $current_category->find($category_id, 'category_id'); } $object = $this->getCurrentOptionValue()->getObject(); if (!$object->getId() or $current_category->getId() and $current_category->getRootCategoryId() != $object->getRootCategoryId()) { throw new Exception($this->_('An error occurred during process. Please try again later.')); } if (!$current_category->getId()) { $current_category = $object->getRootCategory(); } $data = array("folders" => array()); $subcategories = $current_category->getChildren(); foreach ($subcategories as $subcategory) { $data["folders"][] = array("title" => $subcategory->getTitle(), "subtitle" => $subcategory->getSubtitle(), "picture" => $subcategory->getPictureUrl(), "url" => $this->getPath("folder/mobile_list", array("value_id" => $value_id, "category_id" => $subcategory->getId()))); } $pages = $current_category->getPages(); $color = $this->getApplication()->getBlock('background')->getImageColor(); foreach ($pages as $page) { $data["folders"][] = array("title" => $page->getTabbarName(), "subtitle" => "", "picture" => $this->_getColorizedImage($page->getIconId(), $color), 'is_link' => !$page->getIsAjax(), "url" => $page->getPath(null, array('value_id' => $page->getId()), false), "code" => $page->getCode(), "is_locked" => $page->isLocked()); } $data["cover"] = array("title" => $current_category->getTitle(), "subtitle" => $current_category->getSubtitle(), "picture" => $current_category->getPictureUrl()); $data["page_title"] = $current_category->getTitle(); } catch (Exception $e) { $data = array('error' => 1, 'message' => $e->getMessage()); } $this->_sendHtml($data); } }
public function findchildrenAction() { if ($category_id = $this->getRequest()->getParam('category_id')) { try { $current_category = new Folder_Model_Category(); $current_category->find($category_id, 'category_id'); $object = $this->getCurrentOptionValue()->getObject(); if (!$current_category->getId() or !$object->getId() or $current_category->getRootCategoryId() != $object->getRootCategoryId()) { throw new Exception($this->_('An error occurred during process. Please try again later.')); } $html = $this->getLayout()->addPartial('category_' . $current_category->getCategoryId(), 'core_view_mobile_default', 'folder/l1/view/category.phtml')->setCurrentOptionValue($this->getCurrentOptionValue())->setCurrentCategory($current_category)->setId($current_category->getId() == $object->getRootCategoryId() ? $object->getValueId() : 'subcategory_' . $current_category->getId())->toHtml(); $html = array('html' => mb_convert_encoding($html, 'UTF-8', 'UTF-8'), 'title' => $current_category->getTitle()); if ($this->getCurrentOptionValue()->getCode() == 'm_commerce') { $html = array_merge($html, array('next_button_title' => $this->_('Cart'), 'next_button_arrow_is_visible' => 1)); } if ($url = $this->getCurrentOptionValue()->getBackgroundImageUrl()) { $html['background_image_url'] = $url; } } catch (Exception $e) { $html = array('error' => 1, 'message' => $e->getMessage()); } $this->_sendHtml($html); } }
public function createDummyContents($option_value, $design, $category) { $dummy_content_xml = $this->_getDummyXml($design, $category); foreach ($dummy_content_xml->folders->folder as $folder) { $root_category = new Folder_Model_Category(); $root_category->addData((array) $folder->category->main->content)->save(); if ($folder->category->main->features) { $i = 1; foreach ($folder->category->main->features->feature as $feature) { $option = new Application_Model_Option(); $option->find((string) $feature->code, "code")->getObject(); $option_value_obj = new Application_Model_Option_Value(); $icon_id = NULL; if ((string) $feature->icon) { $icon = new Media_Model_Library_Image(); $icon->find((string) $feature->icon, "link"); if (!$icon->getData()) { $icon->setLibraryId($option->getLibraryId())->setLink((string) $feature->icon)->setOptionId($option->getId())->setCanBeColorized($feature->colorizable ? (string) $feature->colorizable : 1)->setPosition(0)->save(); } $icon_id = $icon->getId(); } $datas = array("tabbar_name" => (string) $feature->name ? (string) $feature->name : NULL, "icon_id" => $icon_id, "app_id" => $this->getApplication()->getId(), "option_id" => $option->getId(), "layout_id" => $this->getApplication()->getLayout()->getId(), "folder_id" => $option_value->getId(), "folder_category_id" => $root_category->getId(), "folder_category_position" => $i++); $option_value_obj->addData($datas)->save(); } } $this->unsData(); $this->setValueId($option_value->getId())->setRootCategoryId($root_category->getId())->save(); foreach ($folder->category->subcategory as $subcategory) { $sub_root_category = new Folder_Model_Category(); $sub_root_category->addData((array) $subcategory->content)->setParentId($root_category->getId())->save(); if ($folder->category->subcategory->features) { $i = 1; foreach ($folder->category->subcategory->features->children() as $feature) { $option = new Application_Model_Option(); $option->find((string) $feature->code, "code")->getObject(); $option_value_obj = new Application_Model_Option_Value(); $icon_id = NULL; if ((string) $feature->icon) { $icon = new Media_Model_Library_Image(); $icon->find((string) $feature->icon, "link"); if (!$icon->getData()) { $icon->setLibraryId($option->getLibraryId())->setLink((string) $feature->icon)->setOptionId($option->getId())->setCanBeColorized(1)->setPosition(0)->save(); } $icon_id = $icon->getId(); } $datas = array("tabbar_name" => (string) $feature->name ? (string) $feature->name : NULL, "icon_id" => $icon_id, "app_id" => $this->getApplication()->getId(), "option_id" => $option->getId(), "layout_id" => $this->getApplication()->getLayout()->getId(), "folder_id" => $option_value->getId(), "folder_category_id" => $sub_root_category->getId(), "folder_category_position" => $i++); $option_value_obj->addData($datas)->save(); } } } } }