[*] BO : Required fields improved (with a white list)
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11276 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -64,6 +64,8 @@ class AdminControllerCore extends Controller
|
||||
/** @var array noTabLink array of admintab names witch have no content */
|
||||
public $noTabLink = array('AdminCatalog', 'AdminTools', 'AdminStock', 'AdminAccounting');
|
||||
|
||||
public $required_database = false;
|
||||
|
||||
/** @var string Security token */
|
||||
public $token;
|
||||
|
||||
@@ -78,6 +80,7 @@ class AdminControllerCore extends Controller
|
||||
public $tpl_delete_link_vars = array();
|
||||
public $tpl_option_vars = array();
|
||||
public $tpl_view_vars = array();
|
||||
public $tpl_required_fields_vars = array();
|
||||
|
||||
public $base_tpl_view = null;
|
||||
public $base_tpl_form = null;
|
||||
@@ -158,6 +161,9 @@ class AdminControllerCore extends Controller
|
||||
/** @var array $cache_lang cache for traduction */
|
||||
public static $cache_lang = array();
|
||||
|
||||
/** @var array required_fields to display in the Required Fields form */
|
||||
public $required_fields = array();
|
||||
|
||||
/**
|
||||
* @var array actions to execute on multiple selections
|
||||
* Usage:
|
||||
@@ -1361,6 +1367,9 @@ class AdminControllerCore extends Controller
|
||||
$this->content .= $this->renderList();
|
||||
$this->content .= $this->renderOptions();
|
||||
}
|
||||
// if we have to display the required fields form
|
||||
if ($this->required_database)
|
||||
$this->content .= $this->displayRequiredFields();
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
'content' => $this->content,
|
||||
@@ -1853,7 +1862,7 @@ class AdminControllerCore extends Controller
|
||||
/* Submit options list */
|
||||
else if (Tools::getValue('submitOptions'.$this->table) || Tools::getValue('submitOptions'))
|
||||
$this->action = 'update_options';
|
||||
else if (Tools::isSubmit('submitFields') && $this->requiredDatabase && $this->tabAccess['add'] === '1' && $this->tabAccess['delete'] === '1')
|
||||
else if (Tools::isSubmit('submitFields') && $this->required_database && $this->tabAccess['add'] === '1' && $this->tabAccess['delete'] === '1')
|
||||
$this->action = 'update_fields';
|
||||
else if (is_array($this->bulk_actions))
|
||||
foreach ($this->bulk_actions as $bulk_action => $params)
|
||||
@@ -2512,5 +2521,19 @@ class AdminControllerCore extends Controller
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* prepare the view to display the required fields form
|
||||
*/
|
||||
public function displayRequiredFields()
|
||||
{
|
||||
if (!$this->tabAccess['add'] || !$this->tabAccess['delete'] === '1' || !$this->required_database)
|
||||
return;
|
||||
|
||||
$helper = new Helper();
|
||||
$helper->currentIndex = self::$currentIndex;
|
||||
$helper->token = $this->token;
|
||||
return $helper->renderRequiredFields($this->className, $this->identifier, $this->required_fields);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -321,17 +321,17 @@ class HelperCore
|
||||
$type = 'shop';
|
||||
|
||||
$assos = array();
|
||||
|
||||
|
||||
if ((int)$this->id)
|
||||
{
|
||||
$sql = 'SELECT id_'.$type.', `'.pSQL($this->identifier).'`
|
||||
FROM `'._DB_PREFIX_.pSQL($this->table).'_'.$type.'`
|
||||
WHERE `'.pSQL($this->identifier).'` = '.(int)$this->id;
|
||||
|
||||
|
||||
foreach (Db::getInstance()->executeS($sql) as $row)
|
||||
$assos[$row['id_'.$type]] = $row['id_'.$type];
|
||||
}
|
||||
|
||||
|
||||
$tpl = $this->createTemplate('helper/assoshop.tpl');
|
||||
$tpl->assign(array(
|
||||
'input' => array(
|
||||
@@ -347,5 +347,41 @@ class HelperCore
|
||||
return $tpl->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a form with potentials required fields
|
||||
*
|
||||
* @param string $class_name
|
||||
* @param string $identifier
|
||||
* @param array $table_fields
|
||||
* @return string
|
||||
*/
|
||||
public function renderRequiredFields($class_name, $identifier, $table_fields)
|
||||
{
|
||||
$rules = call_user_func_array(array($class_name, 'getValidationRules'), array($class_name));
|
||||
$required_class_fields = array($identifier);
|
||||
foreach ($rules['required'] as $required)
|
||||
$required_class_fields[] = $required;
|
||||
|
||||
$object = new $class_name();
|
||||
$res = $object->getFieldsRequiredDatabase();
|
||||
|
||||
$required_fields = array();
|
||||
foreach ($res as $row)
|
||||
$required_fields[(int)$row['id_required_field']] = $row['field_name'];
|
||||
|
||||
$this->tpl_vars = array(
|
||||
'table_fields' => $table_fields,
|
||||
'irow' => 0,
|
||||
'required_class_fields' => $required_class_fields,
|
||||
'required_fields' => $required_fields,
|
||||
'current' => $this->currentIndex,
|
||||
'token' => $this->token
|
||||
);
|
||||
|
||||
$tpl = $this->createTemplate('helper/required_fields.tpl');
|
||||
$tpl->assign($this->tpl_vars);
|
||||
|
||||
return $tpl->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user