2017-08-03 10:02:18 +02:00

122 lines
3.7 KiB
PHP

<?php
class AdminAntadisSimulatorThemeController extends ModuleAdminController
{
protected $id_simulator;
public function __construct()
{
// Table simulator - helperList
// id, name, code, theme
// Un simulateur = dossier de stockage
// Un theme de simulateur = un sous dossier
$this->table = 'simulator_theme';
$this->className = 'SimulatorTheme';
$this->identifier = 'id_simulator_theme';
$this->lang = false;
// Set fields list
$this->fields_list = array(
'name' => array(
'title' => $this->l('Nom'),
),
);
// Enable bootstrap
$this->bootstrap = true;
// Call of the parent constructor method
parent::__construct();
}
public function init()
{
parent::init();
$this->id_simulator = Tools::getValue('id_simulator');
}
public function postProcess()
{
$path = _PS_ROOT_DIR_.'/themes/simulation';
if (Tools::isSubmit('submitAddsimulatortheme')) {
$simulator = new Simulator($this->id_simulator);
$name = Tools::getValue('name');
$isCreated = mkdir($path.'/'.$simulator->name.'/'.$name);
if (!$isCreated) {
$this->errors[] = Tools::displayError("Can't create directory");
}
}
}
public function initToolbar()
{
$this->toolbar_btn['new'] = array(
'href' => self::$currentIndex.'&addsimulator_theme&id_simulator='.(int)$this->id_simulator.'&token='.Tools::getAdminTokenLite('AdminAntadisSimulatorTheme'),
'desc' => $this->l('Add New Theme', null, null, false)
);
}
public function displayConfigLink($token = null, $id, $name = null)
{
$tpl = $this->createTemplate('helpers/list/list_action_details.tpl');
if (!array_key_exists('Config', self::$cache_lang)) {
self::$cache_lang['Config'] = $this->l('Configuration', 'Helper');
}
$id_simulator = Tools::getValue('id_simulator');
$link = $this->context->link->getAdminLink('AdminAntadisSimulatorDetail', true);
$tpl->assign(array(
'href' => $link.'&id_simulator='.$id_simulator.'&id_simulator_theme='.$id,
'action' => self::$cache_lang['Config'],
'id' => $id
));
return $tpl->fetch();
}
public function renderList()
{
$this->addRowAction('config');
$this->_where = " AND `id_simulator` = ".(int)$this->id_simulator;
return parent::renderList();
}
public function renderForm()
{
$this->table = 'simulator_theme';
$this->identifier = 'id_simulator_theme';
$this->show_form_cancel_button = true;
$this->fields_form = array(
'legend' => array('title' => $this->l('Add / Edit')),
'input' => array(
array(
'type' => 'hidden',
'name' => 'id_simulator',
'required' => true,
),
array(
'type' => 'text',
'label' => $this->l('Name'),
'desc' => $this->l("Nom du theme."),
'name' => 'name',
'empty_message' => $this->l('Le champs nom ne peut pas être vide.'),
'required' => true,
),
),
'submit' => array('title' => $this->l('Save'))
);
$this->fields_value['id_simulator'] = $this->id_simulator;
return parent::renderForm();
}
}