// AdminController refactoring

This commit is contained in:
tDidierjean
2011-11-03 11:12:18 +00:00
parent f0b150df71
commit 4d6975727c
11 changed files with 68 additions and 66 deletions
+18 -18
View File
@@ -65,8 +65,6 @@ class AdminControllerCore extends Controller
/** @var string Security token */
public $token;
protected $_object;
/** @var string shop | group_shop */
public $shopLinkType;
@@ -756,21 +754,22 @@ class AdminControllerCore extends Controller
$id = (int)Tools::getValue($this->identifier);
if ($id && Validate::isUnsignedId($id))
{
if (!$this->_object)
$this->_object = new $this->className($id);
if (Validate::isLoadedObject($this->_object))
return $this->_object;
if (!$this->object)
$this->object = new $this->className($id);
if (Validate::isLoadedObject($this->object))
return $this->object;
$this->_errors[] = Tools::displayError('Object cannot be loaded (not found)');
}
else if ($opt)
{
$this->_object = new $this->className();
return $this->_object;
$this->object = new $this->className();
return $this->object;
}
else
$this->_errors[] = Tools::displayError('Object cannot be loaded (identifier missing or invalid)');
$this->content = $this->displayErrors();
return $this->object;
}
/**
@@ -1084,14 +1083,15 @@ class AdminControllerCore extends Controller
$this->initToolbar();
if ($this->display == 'edit' || $this->display == 'add')
{
if (!($this->object = $this->loadObject(true)))
if (!$this->loadObject(true))
return;
$this->content .= $this->initForm();
}
elseif ($this->display == 'view')
{
if (!($this->object = $this->loadObject(true)))
return;
// Some controllers use the view action without an object
if ($this->className)
$this->loadObject(true);
$this->content .= $this->initView();
}
elseif (!$this->ajax)
@@ -1104,7 +1104,7 @@ class AdminControllerCore extends Controller
'content' => $this->content,
'url_post' => self::$currentIndex.'&token='.$this->token,
));
}
}
/**
* initialize the invalid doom page of death
@@ -1210,7 +1210,7 @@ class AdminControllerCore extends Controller
// For each action, try to add the corresponding skip elements list
$helper->list_skip_actions = $this->list_skip_actions;
}
/**
@@ -2025,7 +2025,7 @@ class AdminControllerCore extends Controller
*/
protected function displayAssoShop($type = 'shop')
{
if (!Shop::isFeatureActive() || (!$this->_object && $this->context->shop->getContextType() != Shop::CONTEXT_ALL))
if (!Shop::isFeatureActive() || (!$this->object && $this->context->shop->getContextType() != Shop::CONTEXT_ALL))
return;
if ($type != 'shop' && $type != 'group_shop')
@@ -2101,9 +2101,9 @@ EOF;
$html .= '<tr'.(($type == 'group_shop') ? ' class="alt_row"' : '').'><td><label class="t"><input class="input_all_shop" type="checkbox" /> '.$this->l('All shops').'</label></td></tr>';
foreach (Shop::getTree() as $groupID => $groupData)
{
$groupChecked = ($type == 'group_shop' && ((isset($assos[$groupID]) && in_array($this->_object->id, $assos[$groupID])) || !$this->_object->id));
$groupChecked = ($type == 'group_shop' && ((isset($assos[$groupID]) && in_array($this->object->id, $assos[$groupID])) || !$this->object->id));
$html .= '<tr'.(($type == 'shop') ? ' class="alt_row"' : '').'>';
$html .= '<td><img style="vertical-align: middle;" alt="" src="../img/admin/lv2_b.gif" /><label class="t"><input class="input_group_shop" type="checkbox" name="checkBoxGroupShopAsso_'.$this->table.'_'.$this->_object->id.'_'.$groupID.'" value="'.$groupID.'" '.($groupChecked ? 'checked="checked"' : '').' /> '.$groupData['name'].'</label></td>';
$html .= '<td><img style="vertical-align: middle;" alt="" src="../img/admin/lv2_b.gif" /><label class="t"><input class="input_group_shop" type="checkbox" name="checkBoxGroupShopAsso_'.$this->table.'_'.$this->object->id.'_'.$groupID.'" value="'.$groupID.'" '.($groupChecked ? 'checked="checked"' : '').' /> '.$groupData['name'].'</label></td>';
$html .= '</tr>';
if ($type == 'shop')
@@ -2112,10 +2112,10 @@ EOF;
$j = 0;
foreach ($groupData['shops'] as $shopID => $shopData)
{
$checked = ((isset($assos[$shopID]) && in_array($this->_object->id, $assos[$shopID])) || !$this->_object->id);
$checked = ((isset($assos[$shopID]) && in_array($this->object->id, $assos[$shopID])) || !$this->object->id);
$html .= '<tr>';
$html .= '<td><img style="vertical-align: middle;" alt="" src="../img/admin/lv3_'.(($j < $total - 1) ? 'b' : 'f').'.png" /><label class="child">';
$html .= '<input class="input_shop" type="checkbox" value="'.$groupID.'" name="checkBoxShopAsso_'.$this->table.'_'.$this->_object->id.'_'.$shopID.'" id="checkedBox_'.$shopID.'" '.($checked ? 'checked="checked"' : '').' /> ';
$html .= '<input class="input_shop" type="checkbox" value="'.$groupID.'" name="checkBoxShopAsso_'.$this->table.'_'.$this->object->id.'_'.$shopID.'" id="checkedBox_'.$shopID.'" '.($checked ? 'checked="checked"' : '').' /> ';
$html .= $shopData['name'].'</label></td>';
$html .= '</tr>';
$j++;
+13 -12
View File
@@ -154,21 +154,23 @@ class HelperListCore extends Helper
}
/**
* @TODO refactor
* Fetch the template for action enable
*
* @param unknown_type $token
* @param unknown_type $id
* @param unknown_type $value
* @param string $token
* @param int $id
* @param int $value state enabled or not
* @param unknown_type $active
* @param unknown_type $id_category
* @param unknown_type $id_product
*/
protected function displayEnableLink($token, $id, $value, $active, $id_category = null, $id_product = null)
{
return '<a href="'.$this->currentIndex.'&'.$this->identifier.'='.$id.'&'.$active.$this->table.
((int)$id_category && (int)$id_product ? '&id_category='.$id_category : '').'&token='.($token != null ? $token : $this->token).'">
<img src="../img/admin/'.($value ? 'enabled.gif' : 'disabled.gif').'"
alt="'.($value ? $this->l('Enabled') : $this->l('Disabled')).'" title="'.($value ? $this->l('Enabled') : $this->l('Disabled')).'" /></a>';
$this->context->smarty->assign(array(
'enabled' => (bool)$value,
'url_enable' => $this->currentIndex.'&'.$this->identifier.'='.$id.'&'.$active.$this->table.
((int)$id_category && (int)$id_product ? '&id_category='.$id_category : '').'&token='.($token != null ? $token : $this->token)
));
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/helper/list/list_action_enable.tpl');
}
public function displayListContent($token = null)
@@ -406,7 +408,7 @@ class HelperListCore extends Helper
$tpl = $this->context->smarty->template_dir[0].'/helper/list/list_action_edit.tpl';
return $this->context->smarty->fetch($tpl);
}
/**
@@ -426,8 +428,7 @@ class HelperListCore extends Helper
'action' => self::$cache_lang['Delete'],
));
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/helper/list/list_action_delete.tpl');
return $this->context->smarty->fetch('helper/list/list_action_delete.tpl');
}
/**
@@ -512,7 +513,7 @@ class HelperListCore extends Helper
$this->context->controller->addJqueryUI('ui.datepicker');
break;
case 'select':
foreach ($params['select'] as $option_value => $option_display)
foreach ($params['list'] as $option_value => $option_display)
{
if (isset($_POST[$this->table.'Filter_'.$params['filter_key']])
&& Tools::getValue($this->table.'Filter_'.$params['filter_key']) == $option_value