public static function getAllCMSStructure($id_shop = false)
 {
     $categories = OvicBlockCMSModel::getCMSCategories();
     $id_shop = $id_shop !== false ? $id_shop : Context::getContext()->shop->id;
     foreach ($categories as $key => $value) {
         $categories[$key]['cms_pages'] = OvicBlockCMSModel::getCMSPages($value['id_cms_category'], $id_shop);
     }
     return $categories;
 }
Exemple #2
0
 protected function displayAddForm()
 {
     $token = Tools::getAdminTokenLite('AdminModules');
     $back = Tools::safeOutput(Tools::getValue('back', ''));
     $current_index = AdminController::$currentIndex;
     if (!isset($back) || empty($back)) {
         $back = $current_index . '&configure=' . $this->name . '&token=' . $token;
     }
     if (Tools::isSubmit('editBlockCMS') && Tools::getValue('id_cms_block')) {
         $this->_display = 'edit';
         $id_cms_block = (int) Tools::getValue('id_cms_block');
         $cmsBlock = OvicBlockCMSModel::getBlockCMS($id_cms_block);
         $cmsBlockCategories = OvicBlockCMSModel::getCMSBlockPagesCategories($id_cms_block);
         $cmsBlockPages = OvicBlockCMSModel::getCMSBlockPages(Tools::getValue('id_cms_block'));
     } else {
         $this->_display = 'add';
     }
     $this->fields_form[0]['form'] = array('tinymce' => true, 'legend' => array('title' => isset($cmsBlock) ? $this->l('Edit the CMS block.') : $this->l('New CMS block'), 'icon' => isset($cmsBlock) ? 'icon-edit' : 'icon-plus-square'), 'input' => array(array('type' => 'text', 'label' => $this->l('Name of the CMS block'), 'name' => 'block_name', 'lang' => true, 'desc' => $this->l('If you leave this field empty, the block name will use the category name by default.')), array('type' => 'select_category', 'label' => $this->l('CMS category'), 'name' => 'id_category', 'options' => array('query' => OvicBlockCMSModel::getCMSCategories(true), 'id' => 'id_cms_category', 'name' => 'name')), array('type' => 'select', 'label' => $this->l('Location'), 'name' => 'block_location', 'options' => array('query' => array(array('id' => OvicBlockCMSModel::LEFT_COLUMN, 'name' => $this->l('Left column')), array('id' => OvicBlockCMSModel::RIGHT_COLUMN, 'name' => $this->l('Right column')), array('id' => OvicBlockCMSModel::CMS_POS, 'name' => $this->l('CMS Position'))), 'id' => 'id', 'name' => 'name')), array('type' => 'switch', 'label' => $this->l('Add link to Store Locator'), 'name' => 'display_stores', 'is_bool' => true, 'values' => array(array('id' => 'display_stores_on', 'value' => 1, 'label' => $this->l('Yes')), array('id' => 'display_stores_off', 'value' => 0, 'label' => $this->l('No'))), 'desc' => $this->l('Adds the "Our stores" link at the end of the block.')), array('type' => 'cms_pages', 'label' => $this->l('CMS content'), 'name' => 'cmsBox[]', 'values' => OvicBlockCMSModel::getAllCMSStructure(), 'desc' => $this->l('Please mark every page that you want to display in this block.'))), 'buttons' => array('cancelBlock' => array('title' => $this->l('Cancel'), 'href' => $back, 'icon' => 'process-icon-cancel')), 'submit' => array('name' => 'submitBlockCMS', 'title' => $this->l('Save')));
     $this->context->controller->getLanguages();
     foreach ($this->context->controller->_languages as $language) {
         if (Tools::getValue('block_name_' . $language['id_lang'])) {
             $this->fields_value['block_name'][$language['id_lang']] = Tools::getValue('block_name_' . $language['id_lang']);
         } else {
             if (isset($cmsBlock) && isset($cmsBlock[$language['id_lang']]['name'])) {
                 $this->fields_value['block_name'][$language['id_lang']] = $cmsBlock[$language['id_lang']]['name'];
             } else {
                 $this->fields_value['block_name'][$language['id_lang']] = '';
             }
         }
     }
     if (Tools::getValue('display_stores')) {
         $this->fields_value['display_stores'] = Tools::getValue('display_stores');
     } else {
         if (isset($cmsBlock) && isset($cmsBlock[1]['display_store'])) {
             $this->fields_value['display_stores'] = $cmsBlock[1]['display_store'];
         } else {
             $this->fields_value['display_stores'] = '';
         }
     }
     if (Tools::getValue('id_category')) {
         $this->fields_value['id_category'] = (int) Tools::getValue('id_category');
     } else {
         if (isset($cmsBlock) && isset($cmsBlock[1]['id_cms_category'])) {
             $this->fields_value['id_category'] = $cmsBlock[1]['id_cms_category'];
         }
     }
     if (Tools::getValue('block_location')) {
         $this->fields_value['block_location'] = Tools::getValue('block_location');
     } else {
         if (isset($cmsBlock) && isset($cmsBlock[1]['location'])) {
             $this->fields_value['block_location'] = $cmsBlock[1]['location'];
         } else {
             $this->fields_value['block_location'] = 0;
         }
     }
     if ($cmsBoxes = Tools::getValue('cmsBox')) {
         foreach ($cmsBoxes as $key => $value) {
             $this->fields_value[$value] = true;
         }
     } else {
         if (isset($cmsBlockPages) && is_array($cmsBlockPages) && count($cmsBlockPages) > 0) {
             foreach ($cmsBlockPages as $item) {
                 $this->fields_value['0_' . $item['id_cms']] = true;
             }
         }
         if (isset($cmsBlockCategories) && is_array($cmsBlockCategories) && count($cmsBlockCategories) > 0) {
             foreach ($cmsBlockCategories as $item) {
                 $this->fields_value['1_' . $item['id_cms']] = true;
             }
         }
     }
     $helper = $this->initForm();
     if (isset($id_cms_block)) {
         $helper->currentIndex = AdminController::$currentIndex . '&configure=' . $this->name . '&id_cms_block=' . $id_cms_block;
         $helper->submit_action = 'editBlockCMS';
     } else {
         $helper->submit_action = 'addBlockCMS';
     }
     $helper->fields_value = isset($this->fields_value) ? $this->fields_value : array();
     $this->_html .= $helper->generateForm($this->fields_form);
     return;
 }