[*] BO #PSFV-94 : added class HelperForm
This commit is contained in:
@@ -31,7 +31,8 @@ class AdminControllerCore extends Controller
|
||||
|
||||
public static $currentIndex;
|
||||
public $content;
|
||||
public $warnings;
|
||||
public $warnings = array();
|
||||
public $informations = array();
|
||||
|
||||
public $content_only = false;
|
||||
public $layout = 'layout.tpl';
|
||||
@@ -715,6 +716,7 @@ class AdminControllerCore extends Controller
|
||||
|
||||
$this->context->smarty->assign('errors', $this->_errors);
|
||||
$this->context->smarty->assign('warnings', $this->warnings);
|
||||
$this->context->smarty->assign('informations', $this->informations);
|
||||
}
|
||||
|
||||
$this->context->smarty->assign('page', $page);
|
||||
@@ -731,6 +733,16 @@ class AdminControllerCore extends Controller
|
||||
$this->warnings[] = $msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* add a info message to display at the top of the page
|
||||
*
|
||||
* @param string $msg
|
||||
*/
|
||||
protected function displayInformation($msg)
|
||||
{
|
||||
$this->informations[] = $msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign smarty variables for the header
|
||||
*/
|
||||
@@ -889,7 +901,25 @@ class AdminControllerCore extends Controller
|
||||
{
|
||||
if ($this->display == 'edit')
|
||||
{
|
||||
$this->content .= $this->displayForm();
|
||||
|
||||
if (!($obj = $this->loadObject(true)))
|
||||
return;
|
||||
|
||||
if (isset($this->fields_form))
|
||||
{
|
||||
$helper = new HelperForm();
|
||||
$helper::$currentIndex = self::$currentIndex;
|
||||
$helper->token = $this->token;
|
||||
$helper->table = $this->table;
|
||||
$helper->table = $this->table;
|
||||
$helper->id = $obj->id;
|
||||
$helper->fields_value = $this->getFieldsValue($obj);
|
||||
$this->content .= $helper->generateForm($this->fields_form);
|
||||
}
|
||||
else
|
||||
//@TODO à supprimer
|
||||
$this->content .= $this->displayForm();
|
||||
|
||||
if ($this->tabAccess['view'])
|
||||
{
|
||||
if (Tools::getValue('back'))
|
||||
@@ -897,8 +927,6 @@ class AdminControllerCore extends Controller
|
||||
else
|
||||
$this->context->smarty->assign('back', Tools::safeOutput(Tools::getValue(self::$currentIndex.'&token='.$this->token)));
|
||||
}
|
||||
// move to form.tpl
|
||||
$this->content .= '<br /><br /><a href="'.((Tools::getValue('back')) ? Tools::getValue('back') : self::$currentIndex.'&token='.$this->token).'"><img src="../img/admin/arrow2.gif" /> '.((Tools::getValue('back')) ? $this->l('Back') : $this->l('Back to list')).'</a><br />';
|
||||
}
|
||||
else if ($this->display == 'list')
|
||||
{
|
||||
@@ -1288,6 +1316,14 @@ class AdminControllerCore extends Controller
|
||||
$this->_listTotal = Db::getInstance()->getValue('SELECT FOUND_ROWS() AS `'._DB_PREFIX_.$this->table.'`');
|
||||
}
|
||||
|
||||
public function getFieldsValue($obj)
|
||||
{
|
||||
foreach ($this->fields_form['input'] as $input)
|
||||
if (empty($this->fields_value[$input['name']]))
|
||||
$this->fields_value[$input['name']] = $this->getFieldValue($obj, $input['name']);
|
||||
return $this->fields_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return field value if possible (both classical and multilingual fields)
|
||||
*
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 9194 $
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class HelperFormCore extends Helper
|
||||
{
|
||||
|
||||
public $id;
|
||||
|
||||
public $first_call = true;
|
||||
|
||||
/**
|
||||
* @var array of forms fields
|
||||
* Usage :
|
||||
*
|
||||
*/
|
||||
protected $fields_form = array();
|
||||
|
||||
public $fields_value = array();
|
||||
|
||||
public $table;
|
||||
|
||||
public $token;
|
||||
|
||||
public static $currentIndex;
|
||||
|
||||
public function generateForm($fields_form)
|
||||
{
|
||||
$this->fields_form = $fields_form;
|
||||
|
||||
return $this->displayForm();
|
||||
}
|
||||
|
||||
public function displayForm()
|
||||
{
|
||||
$allowEmployeeFormLang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
|
||||
if ($allowEmployeeFormLang && !$this->context->cookie->employee_form_lang)
|
||||
$this->context->cookie->employee_form_lang = (int)(Configuration::get('PS_LANG_DEFAULT'));
|
||||
$useLangFromCookie = false;
|
||||
$languages = Language::getLanguages(false);
|
||||
if ($allowEmployeeFormLang)
|
||||
foreach ($languages as $lang)
|
||||
if ($this->context->cookie->employee_form_lang == $lang['id_lang'])
|
||||
$useLangFromCookie = true;
|
||||
if (!$useLangFromCookie)
|
||||
$defaultFormLanguage = (int)(Configuration::get('PS_LANG_DEFAULT'));
|
||||
else
|
||||
$defaultFormLanguage = (int)($this->context->cookie->employee_form_lang);
|
||||
|
||||
info($this->fields_value);
|
||||
$this->context->smarty->assign(array(
|
||||
'firstCall' => $this->first_call,
|
||||
'current' => self::$currentIndex,
|
||||
'token' => $this->token,
|
||||
'table' => $this->table,
|
||||
'defaultFormLanguage' => $defaultFormLanguage,
|
||||
'languages' => $languages,
|
||||
'allowEmployeeFormLang' => $allowEmployeeFormLang,
|
||||
'form_id' => $this->id,
|
||||
'back' => Tools::getValue('back'),
|
||||
'fields' => $this->fields_form,
|
||||
'fields_value' => $this->fields_value,
|
||||
'requiredFields' => $this->getFieldsRequired()
|
||||
));
|
||||
|
||||
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/form.tpl');
|
||||
}
|
||||
|
||||
public function getFieldsRequired()
|
||||
{
|
||||
foreach ($this->fields_form['input'] as $input)
|
||||
if (array_key_exists('required', $input) && $input['required'])
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user