323 lines
11 KiB
PHP
323 lines
11 KiB
PHP
<?php
|
|
include_once dirname(__FILE__).'/../../classes/AdvMenuLink.php';
|
|
|
|
class AdminAdvMenuController extends ModuleAdminController {
|
|
|
|
private $current_link;
|
|
|
|
public function __construct() {
|
|
|
|
$this->table = 'advmenu';
|
|
$this->className = 'AdvMenuLink';
|
|
$this->identifier = 'id_link';
|
|
$this->lang = TRUE;
|
|
$this->deleted = FALSE;
|
|
$this->bootstrap = TRUE;
|
|
$this->position_identifier = 'id_link';
|
|
$this->_defaultOrderBy = 'position';
|
|
|
|
parent::__construct();
|
|
$this->actions = array('view', 'edit', 'delete');
|
|
$this->fields_list = array(
|
|
'id_link' => array(
|
|
'title' => 'ID',
|
|
'width' => 25
|
|
),
|
|
'title' => array(
|
|
'title' => $this->module->l('Titre'),
|
|
'width' => 45,
|
|
),
|
|
'url' => array(
|
|
'title' => $this->module->l('Url'),
|
|
'width' => 45,
|
|
),
|
|
'position' => array(
|
|
'title' => $this->l('Position'),
|
|
'align' => 'center',
|
|
'position' => 'position',
|
|
'filter_key' => 'a!position'
|
|
)
|
|
);
|
|
|
|
if (isset($_GET['deleteadvmenu'])) {
|
|
$this->current_link = new AdvMenuLink(
|
|
(int)(
|
|
Tools::getValue('id_link_parent', 0)
|
|
)
|
|
);
|
|
} else {
|
|
$this->current_link = new AdvMenuLink(
|
|
(int)(
|
|
Tools::getValue('id_link',
|
|
Tools::getValue('id_link_parent', 0))
|
|
)
|
|
);
|
|
}
|
|
|
|
|
|
|
|
$this->_where = ' AND a.`id_parent` =' . (int)$this->current_link->id;
|
|
|
|
if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL){
|
|
$this->_join .= 'JOIN `'._DB_PREFIX_.'advmenu_shop` as ashop ON a.`id_link` = ashop.`id_link` AND ashop.`id_shop` IN ('.implode(', ', Shop::getContextListShopID()).') ';
|
|
$this->_group .= 'GROUP BY ashop.`id_link`';
|
|
}
|
|
|
|
}
|
|
|
|
public function initPageHeaderToolbar()
|
|
{
|
|
parent::initPageHeaderToolbar();
|
|
|
|
if ($this->display != 'edit' && $this->display != 'add') {
|
|
$this->page_header_toolbar_btn['new_link'] = array(
|
|
'href' => self::$currentIndex.'&id_parent='.$this->current_link->id.'&addadvmenu&token='.$this->token,
|
|
'desc' => $this->l('Ajouter un nouveau lien', NULL, NULL, FALSE),
|
|
'icon' => 'process-icon-new'
|
|
);
|
|
}
|
|
}
|
|
|
|
public function renderList()
|
|
{
|
|
$menu_links = '<li><a href="'.self::$currentIndex.'&token='.$this->token.'"><i class="icon-home"></i></a></li>';
|
|
$links = AdvMenuLink::getPath($this->current_link->id, Context::getContext()->cookie->id_lang);
|
|
|
|
foreach($links as $link) {
|
|
$menu_links .= '<li><a href="'.self::$currentIndex.'&id_link='.$link['id_link'].'&viewadvmenu&token='.$this->token.'">'.$link['title'].'</a></li>';
|
|
}
|
|
|
|
$this->context->smarty->assign('menu_links', $menu_links);
|
|
self::$currentIndex .= "&id_link_parent=".$this->current_link->id;
|
|
|
|
return parent::renderList();
|
|
}
|
|
|
|
public function initContent()
|
|
{
|
|
if ($this->display == 'view') {
|
|
$this->display = 'list';
|
|
}
|
|
|
|
parent::initContent();
|
|
}
|
|
|
|
public function renderForm()
|
|
{
|
|
$dbLinks = array();
|
|
$id = Tools::getValue('id_link');
|
|
|
|
AdvMenuLink::getLinksTree($dbLinks, 0, Context::getContext()->cookie->id_lang, $id?$id:-1);
|
|
|
|
$links[] = array(
|
|
'id'=>'0',
|
|
'name' => $this->l('Aucun parent')
|
|
);
|
|
|
|
foreach ($dbLinks as $link) {
|
|
$links[] = array(
|
|
"id" => $link['id_link'],
|
|
"name" => str_repeat('--', $link['level']) . ' ' . $link['title']
|
|
);
|
|
}
|
|
|
|
$catAssociated = AdvMenuLink::getCategoryAssociates($id);
|
|
|
|
if(!empty($catAssociated)) {
|
|
$sel = $catAssociated[0]['tree_categories'];
|
|
$selected_categories = array($sel);
|
|
} else {
|
|
$selected_categories = array(2);
|
|
}
|
|
$categories_univers_list = 'std, doublecube, vrac, pochette_transparente, simplecube, sachetorganza, pochette, coffret, aurore_chocolats, pyramide';
|
|
$categories_univers = array();
|
|
|
|
foreach ( explode(',', $categories_univers_list) as $cat ) {
|
|
$categories_univers[] = array(
|
|
'id' => $cat,
|
|
'name' => $cat,
|
|
);
|
|
}
|
|
$this->fields_form = array(
|
|
'tinymce' => TRUE,
|
|
'legend' => array(
|
|
'title' => $this->className,
|
|
),
|
|
'submit' => array(
|
|
'name' => 'submitAdvMenu',
|
|
'title' => $this->l('Save'),
|
|
),
|
|
'input' => array(
|
|
array(
|
|
'type' => 'hidden',
|
|
'name' => 'id_link_parent'
|
|
),
|
|
array(
|
|
'type' => 'select',
|
|
'label' => $this->l('Lien parent'),
|
|
'name' => 'id_parent',
|
|
'required' => FALSE,
|
|
'options' => array(
|
|
'query' => $links,
|
|
'id' => 'id',
|
|
'name' => 'name'
|
|
)
|
|
),
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('Nom'),
|
|
'name' => 'title',
|
|
'required' => TRUE,
|
|
'lang' => TRUE,
|
|
'size' => 114
|
|
),
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('Lien'),
|
|
'name' => 'url',
|
|
'lang' => TRUE,
|
|
'required' => FALSE,
|
|
'size' => 114
|
|
),
|
|
array(
|
|
'type' => 'switch',
|
|
'label' => $this->l('External link'),
|
|
'name' => 'external',
|
|
'is_bool' => true,
|
|
'required' => false,
|
|
'values' => array(
|
|
array('id' => 'expo_on', 'value' => 1, 'label' => $this->l('Yes')),
|
|
array('id' => 'expo_off', 'value' => 0, 'label' => $this->l('No'))
|
|
)
|
|
),
|
|
array(
|
|
'type' => 'textarea',
|
|
'label' => $this->l('Call to action'),
|
|
'name' => 'cta',
|
|
'autoload_rte' => TRUE,
|
|
'cols' => 100,
|
|
'rows' => 6,
|
|
'lang' => TRUE,
|
|
),
|
|
array(
|
|
'type' => 'categories',
|
|
'label' => $this->l('Tree categories'),
|
|
'name' => 'tree_categories',
|
|
'tree' => array(
|
|
'id' => 'id_root_category',
|
|
'selected_categories' => $selected_categories
|
|
)
|
|
),
|
|
array(
|
|
'type' => 'select',
|
|
'label' => $this->l('Type d\'affichage'),
|
|
'name' => 'classbloc',
|
|
'required' => FALSE,
|
|
'options' => array(
|
|
'query' => array(
|
|
array('id' => '', 'name' => 'Aucune'),
|
|
array('id' => 'title', 'name' => 'Titre'),
|
|
array('id' => 'subtitle', 'name' => 'Sous-titre'),
|
|
),
|
|
'id' => 'id',
|
|
'name' => 'name'
|
|
)
|
|
),
|
|
array(
|
|
'type' => 'select',
|
|
'label' => $this->l('Icones'),
|
|
'name' => 'liste_icons_menu',
|
|
'required' => FALSE,
|
|
'options' => array(
|
|
'query' => $categories_univers,
|
|
'id' => 'id',
|
|
'name' => 'name'
|
|
)
|
|
),
|
|
array(
|
|
'type' => 'shop',
|
|
'label' => $this->l('Shop'),
|
|
'form_group_class' => 'fieldhide input_association',
|
|
'name' => 'checkBoxShopAsso_advmenu'
|
|
)
|
|
)
|
|
);
|
|
|
|
$this->fields_value = array(
|
|
'id_link_parent' => (int)Tools::getValue('id_link_parent')
|
|
);
|
|
|
|
self::$currentIndex .= '&id_link_parent='.Tools::getValue('id_parent', Tools::getValue('id_link_parent'));
|
|
return parent::renderForm();
|
|
}
|
|
|
|
public function processAdd()
|
|
{
|
|
$result = parent::processAdd();
|
|
$this->redirect_after = self::$currentIndex.'&conf=3&token='.$this->token.'&id_link='.Tools::getValue('id_parent');
|
|
return $result;
|
|
}
|
|
|
|
public function processUpdate()
|
|
{
|
|
$result = parent::processUpdate();
|
|
$this->redirect_after = self::$currentIndex.'&conf=4&token='.$this->token.'&id_link='.Tools::getValue('id_link_parent');
|
|
return $result;
|
|
}
|
|
|
|
public function processDelete()
|
|
{
|
|
// "current link" is already parent in this particular case (see constructor)
|
|
$id_parent = $this->current_link->id;
|
|
$object = parent::processDelete();
|
|
|
|
if ($object->hasError()) {
|
|
$this->errors = [Tools::displayError($this->l('This link can\'t be deleted : it contains at least one sub link.'))];
|
|
}
|
|
else {
|
|
$this->redirect_after = self::$currentIndex.'&conf=1&token='.$this->token.'&id_link='.$id_parent;
|
|
}
|
|
return $object;
|
|
}
|
|
|
|
protected function copyFromPost(&$object, $table)
|
|
{
|
|
parent::copyFromPost($object, $table);
|
|
|
|
if(Shop::isFeatureActive()) {
|
|
$object->id_shop_list = array();
|
|
foreach (Tools::getValue('checkBoxShopAsso_advmenu') as $id_shop => $value)
|
|
$object->id_shop_list[] = $id_shop;
|
|
}
|
|
}
|
|
|
|
public function ajaxProcessUpdatePositions()
|
|
{
|
|
$way = (int)(Tools::getValue('way'));
|
|
$id = (int)(Tools::getValue('id'));
|
|
$positions = Tools::getValue('link');
|
|
$obj = 'advmenu';
|
|
|
|
if (is_array($positions)) {
|
|
foreach ($positions as $position => $value) {
|
|
$pos = explode('_', $value);
|
|
if (isset($pos[2]) && (int)$pos[2] === $id) {
|
|
$menu_obj = new AdvMenuLink((int)$pos[2]);
|
|
|
|
if (Validate::isLoadedObject($menu_obj)) {
|
|
if (isset($position) && $menu_obj->updatePosition($way, $position)) {
|
|
echo 'ok position '.(int)$position.' for '.$obj.' '.(int)$pos[2]."\r\n";
|
|
} else {
|
|
echo '{"hasError" : true, "errors" : "Can not update '.$obj.' '.(int)$id.' to position '.(int)$position.' "}';
|
|
}
|
|
} else {
|
|
echo '{"hasError" : true, "errors" : "This '.$obj.' ('.(int)$id.') cannot be loaded"}';
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|