public function saveAction() { if ($datas = $this->getRequest()->getParams()) { try { if (empty($datas['design_id'])) { throw new Exception($this->_('An error occurred while saving')); } $application = $this->getApplication(); $category = new Template_Model_Category(); $design = new Template_Model_Design(); $design->find($datas['design_id']); if (!$design->getId()) { throw new Exception($this->_('An error occurred while saving')); } else { if ($design->getCode() != "blank" && empty($datas['category_id'])) { throw new Exception($this->_('An error occurred while saving')); } } if (!empty($datas['category_id'])) { $category->find($datas['category_id']); if (!$category->getCode()) { throw new Exception($this->_('An error occurred while saving')); } } $this->getApplication()->setLayoutVisibility(Application_Model_Layout_Homepage::VISIBILITY_HOMEPAGE)->setDesign($design, $category)->save(); $html = array('success' => 1, 'overview_src' => $design->getOverview(), 'homepage_standard' => $application->getHomepageBackgroundImageUrl(), 'homepage_hd' => $application->getHomepageBackgroundImageUrl('hd'), 'homepage_tablet' => $application->getHomepageBackgroundImageUrl('tablet'), 'app_icon' => $application->getIcon(), "display_layout_options" => $application->getLayout()->getVisibility() == Application_Model_Layout_Homepage::VISIBILITY_ALWAYS); } catch (Exception $e) { $html = array('message' => $e->getMessage(), 'message_buttom' => 1, 'message_loader' => 1); } } $this->getLayout()->setHtml(Zend_Json::encode($html)); }
public function saveAction() { if ($categories = Zend_Json::decode($this->getRequest()->getRawBody())) { try { foreach ($categories as $data) { $category = new Template_Model_Category(); $category->find($data["category_id"]); $category->addData($data)->save(); } $data = array("success" => 1, "message" => $this->_("Info successfully saved")); } catch (Exception $e) { $data = array("error" => 1, "message" => $e->getMessage()); } $this->_sendHtml($data); } }
// Creating 'template_category' table $this->query("\n CREATE TABLE `template_category` (\n `category_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,\n `name` VARCHAR(50) NOT NULL,\n `code` VARCHAR(20) NOT NULL,\n PRIMARY KEY (`category_id`)\n )\n"); // Creating 'template_design_category table $this->query("\n CREATE TABLE `template_design_category` (\n `design_category_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,\n `design_id` INT(11) UNSIGNED NOT NULL,\n `category_id` INT(11) UNSIGNED NOT NULL,\n PRIMARY KEY (`design_category_id`),\n KEY (`design_id`),\n KEY (`category_id`),\n UNIQUE `UNIQUE_TEMPLATE_DESIGN_CATEGORY_DESIGN_ID_CATEGORY_ID` (`design_id`, `category_id`)\n )\n"); // Creating 'template_design_content' table $this->query("\n CREATE TABLE `template_design_content` (\n `content_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,\n `design_id` INT(11) UNSIGNED NOT NULL,\n `option_id` INT(11) UNSIGNED NOT NULL,\n `option_tabbar_name` VARCHAR(30) NULL DEFAULT NULL,\n `option_icon` VARCHAR(30) NULL DEFAULT NULL,\n `option_background_image` VARCHAR(255) NULL DEFAULT NULL,\n PRIMARY KEY (`content_id`),\n KEY (`design_id`),\n KEY (`option_id`)\n )\n"); $this->query("\n ALTER TABLE `template_design_content`\n ADD CONSTRAINT `FK_TEMPLATE_DESIGN_CONTENT_DESIGN_ID` FOREIGN KEY (`design_id`) REFERENCES `template_design` (`design_id`)\n ON DELETE CASCADE ON UPDATE CASCADE;\n"); $this->query("\n ALTER TABLE `template_design_content`\n ADD CONSTRAINT `FK_TEMPLATE_DESIGN_CONTENT_OPTION_ID` FOREIGN KEY (`option_id`) REFERENCES `application_option` (`option_id`)\n ON DELETE CASCADE ON UPDATE CASCADE;\n"); // Inserting categories in 'template_category' table $categories = array("Entertainment", "Local Business", "Music"); foreach ($categories as $category_name) { $category_data = array(); $category_data['name'] = $category_name; $category_data['code'] = preg_replace('/[&\\s]+/', "_", strtolower($category_name)); $category = new Template_Model_Category(); $category->find($category_data['code'], "code"); $category->setData($category_data)->save(); } // Listing all layouts $layouts = array(); $layout = new Application_Model_Layout_Homepage(); foreach ($layout->findAll() as $layout) { $layouts[$layout->getCode()] = $layout; } // Listings all block ids $block_ids = array(); $block = new Template_Model_Block(); foreach ($block->findAll() as $block) { $block_ids[$block->getCode()] = $block->getId(); } // Inserting designs with blocks