2017-07-06 17:41:10 +02:00

202 lines
5.1 KiB
PHP

<?php
include_once dirname(__FILE__).'/../../classes/AdvPictoClass.php';
include_once dirname(__FILE__).'/../../classes/AdvPictoProductClass.php';
class AdminAdvPictoProductController extends ModuleAdminController
{
public function __construct()
{
$this->table = 'advpicto_product';
$this->className = 'AdvPictoProductClass';
$this->identifier = 'id_advpicto_product';
$this->lang = false;
$this->deleted = false;
$this->bootstrap = true;
$this->explicitSelect = true;
$this->context = Context::getContext();
$this->_defaultOrderBy = 'id_advpicto';
$this->fieldImageSettings = array(
'name' => 'image',
'dir' => 'picto'
);
parent::__construct();
$this->fields_list = array(
'id_advpicto_product' => array(
'title' => $this->l('ID'),
'align' => 'center',
'width' => 25,
'filter_key' => 'a!id_advpicto_product'
),
'id_advpicto' => array(
'title' => $this->l('Picto'),
'filter_key' => 'a!id_advpicto',
'callback' => 'getPictoName'
),
'id_product' => array(
'title' => $this->l('Produit'),
'filter_key' => 'a!id_product',
'callback' => 'getProductName',
),
'highlight' => array(
'title' => $this->l('En avant'),
'active' => 'status',
'filter_key' => 'a!highlight',
'align' => 'text-center',
'type' => 'bool',
'class' => 'fixed-width-sm',
'orderby' => false
),
);
$this->actions = array('edit','delete');
$this->bulk_actions = array(
'delete' => array(
'text' => $this->l('Supprimer la liste'),
'icon' => 'icon-trash',
'confirm' => $this->l('Supprimer les blocs selectionné?')
)
);
$this->specificConfirmDelete = false;
}
public function init()
{
parent::init();
if(Tools::getValue('loadProductName') == 1)
{
$this->loadProductData();
}
}
public function initPageHeaderToolbar()
{
parent::initPageHeaderToolbar();
$this->page_header_toolbar_btn['back_to_list'] = array(
'href' => $this->context->link->getAdminLink('AdminAdvPicto'),
'desc' => $this->l('Liste des pictogrammes', null, null, false),
'icon' => 'process-icon-back'
);
if ($this->display == 'edit' || $this->display == 'add') {
$this->page_header_toolbar_btn['new_product'] = array(
'href' => $this->context->link->getAdminLink('AdminAdvPictoProduct'),
'desc' => $this->l('Liste des associations', null, null, false),
'icon' => 'process-icon-back'
);
}
if ($this->display != 'edit' && $this->display != 'add') {
$this->page_header_toolbar_btn['new_constructor'] = array(
'href' => self::$currentIndex.'&addadvpicto_product&token='.$this->token,
'desc' => $this->l('Ajouter une association produit', null, null, false),
'icon' => 'process-icon-new'
);
}
}
public static function getProductName($id_product, $obj) {
return Product::getProductName($id_product, null, Context::getContext()->language->id);
}
public static function getPictoName($id_advpicto) {
return AdvPictoClass::getPictoName($id_advpicto, Context::getContext()->language->id);
}
public function loadProductData()
{
$id_product = Tools::getValue('id_product');
$identifier = Tools::getValue('identifier');
$data['identifier'] = $identifier;
$data['nameProduct'] = self::getProductName($id_product, null, Context::getContext()->language->id);
die(Tools::jsonEncode($data));
}
public function renderForm()
{
if (!($obj = $this->loadObject(true))) {
return;
}
$this->addJqueryUI(array('ui.core','ui.widget'));
$this->addJqueryPlugin(array('autocomplete'));
$context = Context::getContext();
$pictos = AdvPictoClass::getAllPictos();
$this->tpl_form_vars['product_id'] = $this->object->id_product;
$this->fields_form = array(
'multilang' => true,
'tinymce' => true,
'legend' => array(
'title' => $this->l('Picto'),
),
'submit' => array(
'name' => 'submitAdd'.$this->table,
'title' => $this->l('Enregistrer')
),
'input' => array(
array(
'type' => 'select',
'label' => $this->l('Pictogramme'),
'name' => 'id_advpicto',
'options' => array(
'query' => $pictos,
'id' => 'id',
'name' => 'title'
),
'required' => true,
),
array(
'type' => 'product',
'label' => $this->l('Produit'),
'name' => 'id_product',
'id' => 'id_product',
'required' => true
),
array(
'type' => 'switch',
'label' => $this->l('Mise en avant'),
'name' => 'highlight',
'required' => false,
'class' => 't',
'is_bool' => true,
'values' => array(
array(
'id' => 'highlight_on',
'value' => 1
),
array(
'id' => 'highlight_off',
'value' => 0
)
)
)
)
);
if (Shop::isFeatureActive()) {
$this->fields_form['input'][] = array(
'type' => 'shop',
'label' => $this->l('Boutique'),
'name' => 'checkBoxShopAsso',
'form_group_class' => 'fieldhide input_association'
);
}
return parent::renderForm();
}
public function beforeAdd($object)
{
parent::beforeAdd($object);
}
}