public function findallAction()
 {
     $preview = new Preview_Model_Preview();
     $previews = $preview->findAll(null, array("group_by" => "aop.preview_id"));
     $data = array();
     foreach ($previews as $preview) {
         $option = new Application_Model_Option();
         $option->find($preview->getOptionId());
         $data[] = array("id" => $preview->getId(), "title" => $preview->getTitle(), "feature" => $preview->getOptionId(), "feature_name" => $option->getName());
     }
     $this->_sendHtml($data);
 }
 public function findAction()
 {
     $previews = new Preview_Model_Preview();
     $data = array();
     if ($this->getRequest()->getParam("preview_id")) {
         $previews = $previews->findAll(array("aop.preview_id" => $this->getRequest()->getParam("preview_id")));
         $data_tmp = array();
         foreach ($previews as $preview) {
             if ($preview->getlibraryId()) {
                 $images = $preview->findImages();
                 $images_data = array();
                 foreach ($images as $image) {
                     $images_data[] = array("id" => $image->getImageId(), "link" => $image->getlink(), "new" => 0, "to_delete" => 0);
                 }
             }
             if ($preview->getPreviewId()) {
                 $data_tmp[$preview->getLanguageCode()] = array("title" => $preview->getTitle(), "description" => $preview->getDescription(), "language_code" => $preview->getLanguageCode(), "from_database" => 1, "images" => $images_data);
             }
         }
         if (!empty($data_tmp)) {
             $data["previews"] = $data_tmp;
         }
         $data["section_title_one"] = $this->_("Edit the preview");
     } else {
         $data["section_title_one"] = $this->_("Create a new preview");
         $option = new Application_Model_Option();
         $option_list = array();
         $options = $option->findAll(array(), 'position ASC');
         foreach ($options as $option) {
             $option_list[$option->getId()] = $option->getName();
         }
         $data["options"] = $option_list;
     }
     $data["section_title_two"] = $this->_("Preview images");
     $languages = Core_Model_Language::getLanguages();
     $language_list = array();
     foreach ($languages as $language) {
         $language_list[$language->getCode()] = $language->getName();
     }
     $data["languages"] = $language_list;
     $data["current_language"] = Core_Model_Language::getCurrentLanguage();
     $this->_sendHtml($data);
 }
 public function deleteAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             if (empty($datas['value_id'])) {
                 throw new Exception($this->_('An error occurred while deleting the option'));
             }
             // Récupère les données de l'application pour cette option
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['value_id']);
             // Option folder
             if (isset($datas['category_id'])) {
                 // Récupère l'option_value en cours
                 $category_option_value = new Application_Model_Option_Value();
                 $category_option_value->find($datas['value_id']);
                 $category_option_value->setFolderCategoryId(null)->setFolderCategoryPosition(null)->save();
                 foreach (Core_View_Default::getBlocks() as $block) {
                     if ($block->getCode() == 'area') {
                         $colorized_block = $block;
                     }
                 }
                 $icon_url = $category_option_value->getImage()->getCanBeColorized() ? Siberian_View::getColorizedImage($category_option_value->getIconId(), $colorized_block->getColor()) : $category_option_value->getIconUrl();
                 $html['folder'] = array('id' => $category_option_value->getId(), 'name' => $category_option_value->getShortTabbarName(), 'icon_url' => $icon_url, 'value_id' => $datas['value_id'], 'category_id' => $datas['category_id']);
             } else {
                 // Récupère l'id
                 $id = $option_value->getId();
                 // Récupère l'option
                 $option = new Application_Model_Option();
                 $option->find($option_value->getOptionId());
                 $option_folder = new Application_Model_Option();
                 $option_folder->find(array('code' => 'folder'));
                 $was_folder = 0;
                 //Folder, supprime les cat id des options
                 if ($option_value->getOptionId() == $option_folder->getOptionId()) {
                     $folder = new Folder_Model_Folder();
                     $folder->find($id, 'value_id');
                     $root_category = new Folder_Model_Category();
                     $root_category->find($folder->getRootCategoryId());
                     $categories_options = $root_category->deleteChildren($folder->getRootCategoryId());
                     $category_option = new Application_Model_Option_Value();
                     $option_values = $category_option->findAll(array('folder_category_id' => $folder->getRootCategoryId()));
                     $categories_options[$folder->getRootCategoryId()] = array();
                     foreach ($option_values as $ov) {
                         $ov->setFolderCategoryId(null)->setFolderCategoryPosition(null)->save();
                         $categories_options[$folder->getRootCategoryId()][] = $ov->getValueId();
                     }
                     $folder->delete();
                     $was_folder = 1;
                 }
                 // Supprime l'option de l'application
                 $option_value->delete();
                 // Renvoi le nouveau code HTML
                 $this->getLayout()->setBaseRender('content', 'application/customization/page/list.phtml', 'admin_view_default');
                 $html = array('success' => 1, 'option_id' => $id, 'use_user_account' => $this->getApplication()->usesUserAccount());
                 if ($option->onlyOnce()) {
                     $html['page'] = array('id' => $option->getId(), 'name' => $option->getName(), 'icon_url' => $option->getIconUrl());
                 }
                 if ($was_folder == 1) {
                     $html['was_folder'] = 1;
                     $html['categories_options'] = $categories_options;
                 }
             }
         } catch (Exception $e) {
             $html = array('message' => $this->_('An error occurred while deleting the option'), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
 public function deleteAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             if (empty($datas['value_id'])) {
                 throw new Exception($this->_('An error occurred while deleting the option'));
             }
             // Récupère les données de l'application pour cette option
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['value_id']);
             $app_id = $this->getApplication()->getId();
             if (!$option_value->getId() or $option_value->getAppId() != $app_id) {
                 throw new Exception($this->_('An error occurred while deleting the option'));
             }
             $html = array('success' => 1, 'value_id' => $datas['value_id'], 'path' => $option_value->getPath(null, array(), "mobile"), 'was_folder' => false, 'was_category' => false, 'was_feature' => false);
             // Option folder
             if (isset($datas['category_id'])) {
                 $option_value->setFolderId(null)->setFolderCategoryId(null)->setFolderCategoryPosition(null)->save();
                 $html['was_category'] = true;
                 $html['category'] = array('id' => $datas['category_id']);
             } else {
                 // Récupère l'option
                 $option = new Application_Model_Option();
                 $option->find($option_value->getOptionId());
                 $html['was_feature'] = true;
                 $html['use_user_account'] = $this->getApplication()->usesUserAccount();
                 if ($option_value->getCode() == "folder") {
                     $html['was_folder'] = true;
                 }
                 // Supprime l'option de l'application
                 $option_value->delete();
                 if ($option->onlyOnce()) {
                     $html['page'] = array('id' => $option->getId(), 'name' => $option->getName(), 'icon_url' => $option->getIconUrl(), 'category_id' => $option->getCategoryId());
                 }
                 // Renvoi le nouveau code HTML
                 //                    $this->getLayout()->setBaseRender('content', 'application/customization/page/list.phtml', 'admin_view_default');
             }
         } catch (Exception $e) {
             $html = array('message' => $this->_('An error occurred while deleting the option'), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->_sendHtml($html);
     }
 }