// 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
+17 -17
View File
@@ -65,8 +65,6 @@ class AdminControllerCore extends Controller
/** @var string Security token */ /** @var string Security token */
public $token; public $token;
protected $_object;
/** @var string shop | group_shop */ /** @var string shop | group_shop */
public $shopLinkType; public $shopLinkType;
@@ -756,21 +754,22 @@ class AdminControllerCore extends Controller
$id = (int)Tools::getValue($this->identifier); $id = (int)Tools::getValue($this->identifier);
if ($id && Validate::isUnsignedId($id)) if ($id && Validate::isUnsignedId($id))
{ {
if (!$this->_object) if (!$this->object)
$this->_object = new $this->className($id); $this->object = new $this->className($id);
if (Validate::isLoadedObject($this->_object)) if (Validate::isLoadedObject($this->object))
return $this->_object; return $this->object;
$this->_errors[] = Tools::displayError('Object cannot be loaded (not found)'); $this->_errors[] = Tools::displayError('Object cannot be loaded (not found)');
} }
else if ($opt) else if ($opt)
{ {
$this->_object = new $this->className(); $this->object = new $this->className();
return $this->_object; return $this->object;
} }
else else
$this->_errors[] = Tools::displayError('Object cannot be loaded (identifier missing or invalid)'); $this->_errors[] = Tools::displayError('Object cannot be loaded (identifier missing or invalid)');
$this->content = $this->displayErrors(); $this->content = $this->displayErrors();
return $this->object;
} }
/** /**
@@ -1084,14 +1083,15 @@ class AdminControllerCore extends Controller
$this->initToolbar(); $this->initToolbar();
if ($this->display == 'edit' || $this->display == 'add') if ($this->display == 'edit' || $this->display == 'add')
{ {
if (!($this->object = $this->loadObject(true))) if (!$this->loadObject(true))
return; return;
$this->content .= $this->initForm(); $this->content .= $this->initForm();
} }
elseif ($this->display == 'view') elseif ($this->display == 'view')
{ {
if (!($this->object = $this->loadObject(true))) // Some controllers use the view action without an object
return; if ($this->className)
$this->loadObject(true);
$this->content .= $this->initView(); $this->content .= $this->initView();
} }
elseif (!$this->ajax) elseif (!$this->ajax)
@@ -1104,7 +1104,7 @@ class AdminControllerCore extends Controller
'content' => $this->content, 'content' => $this->content,
'url_post' => self::$currentIndex.'&token='.$this->token, 'url_post' => self::$currentIndex.'&token='.$this->token,
)); ));
} }
/** /**
* initialize the invalid doom page of death * initialize the invalid doom page of death
@@ -2025,7 +2025,7 @@ class AdminControllerCore extends Controller
*/ */
protected function displayAssoShop($type = 'shop') 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; return;
if ($type != 'shop' && $type != 'group_shop') 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>'; $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) 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 .= '<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>'; $html .= '</tr>';
if ($type == 'shop') if ($type == 'shop')
@@ -2112,10 +2112,10 @@ EOF;
$j = 0; $j = 0;
foreach ($groupData['shops'] as $shopID => $shopData) 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 .= '<tr>';
$html .= '<td><img style="vertical-align: middle;" alt="" src="../img/admin/lv3_'.(($j < $total - 1) ? 'b' : 'f').'.png" /><label class="child">'; $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 .= $shopData['name'].'</label></td>';
$html .= '</tr>'; $html .= '</tr>';
$j++; $j++;
+12 -11
View File
@@ -154,21 +154,23 @@ class HelperListCore extends Helper
} }
/** /**
* @TODO refactor * Fetch the template for action enable
* *
* @param unknown_type $token * @param string $token
* @param unknown_type $id * @param int $id
* @param unknown_type $value * @param int $value state enabled or not
* @param unknown_type $active * @param unknown_type $active
* @param unknown_type $id_category * @param unknown_type $id_category
* @param unknown_type $id_product * @param unknown_type $id_product
*/ */
protected function displayEnableLink($token, $id, $value, $active, $id_category = null, $id_product = null) protected function displayEnableLink($token, $id, $value, $active, $id_category = null, $id_product = null)
{ {
return '<a href="'.$this->currentIndex.'&'.$this->identifier.'='.$id.'&'.$active.$this->table. $this->context->smarty->assign(array(
((int)$id_category && (int)$id_product ? '&id_category='.$id_category : '').'&token='.($token != null ? $token : $this->token).'"> 'enabled' => (bool)$value,
<img src="../img/admin/'.($value ? 'enabled.gif' : 'disabled.gif').'" 'url_enable' => $this->currentIndex.'&'.$this->identifier.'='.$id.'&'.$active.$this->table.
alt="'.($value ? $this->l('Enabled') : $this->l('Disabled')).'" title="'.($value ? $this->l('Enabled') : $this->l('Disabled')).'" /></a>'; ((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) public function displayListContent($token = null)
@@ -426,8 +428,7 @@ class HelperListCore extends Helper
'action' => self::$cache_lang['Delete'], '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'); $this->context->controller->addJqueryUI('ui.datepicker');
break; break;
case 'select': 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']]) if (isset($_POST[$this->table.'Filter_'.$params['filter_key']])
&& Tools::getValue($this->table.'Filter_'.$params['filter_key']) == $option_value && Tools::getValue($this->table.'Filter_'.$params['filter_key']) == $option_value
@@ -56,7 +56,7 @@ class AdminAddressesControllerCore extends AdminController
'address1' => array('title' => $this->l('Address'), 'width' => 200), 'address1' => array('title' => $this->l('Address'), 'width' => 200),
'postcode' => array('title' => $this->l('Postcode/ Zip Code'), 'align' => 'right', 'width' => 50), 'postcode' => array('title' => $this->l('Postcode/ Zip Code'), 'align' => 'right', 'width' => 50),
'city' => array('title' => $this->l('City'), 'width' => 150), 'city' => array('title' => $this->l('City'), 'width' => 150),
'country' => array('title' => $this->l('Country'), 'width' => 100, 'type' => 'select', 'select' => $this->countriesArray, 'filter_key' => 'cl!id_country')); 'country' => array('title' => $this->l('Country'), 'width' => 100, 'type' => 'select', 'list' => $this->countriesArray, 'filter_key' => 'cl!id_country'));
parent::__construct(); parent::__construct();
} }
@@ -67,7 +67,7 @@ class AdminCustomersControllerCore extends AdminController
'icon' => $genders_icon, 'icon' => $genders_icon,
'orderby' => false, 'orderby' => false,
'type' => 'select', 'type' => 'select',
'select' => $genders, 'list' => $genders,
'filter_key' => 'a!id_gender', 'filter_key' => 'a!id_gender',
), ),
'lastname' => array( 'lastname' => array(
@@ -60,7 +60,7 @@ class AdminEmployeesControllerCore extends AdminController
'lastname' => array('title' => $this->l('Last name'), 'width' => 130), 'lastname' => array('title' => $this->l('Last name'), 'width' => 130),
'firstname' => array('title' => $this->l('First name'), 'width' => 130), 'firstname' => array('title' => $this->l('First name'), 'width' => 130),
'email' => array('title' => $this->l('E-mail address'), 'width' => 180), 'email' => array('title' => $this->l('E-mail address'), 'width' => 180),
'profile' => array('title' => $this->l('Profile'), 'width' => 90, 'type' => 'select', 'select' => $this->profiles_array, 'filter_key' => 'pl!name'), 'profile' => array('title' => $this->l('Profile'), 'width' => 90, 'type' => 'select', 'list' => $this->profiles_array, 'filter_key' => 'pl!name'),
'active' => array('title' => $this->l('Can log in'), 'align' => 'center', 'active' => 'status', 'type' => 'bool'), 'active' => array('title' => $this->l('Can log in'), 'align' => 'center', 'active' => 'status', 'type' => 'bool'),
); );
+1 -1
View File
@@ -68,7 +68,7 @@ class AdminGendersController extends AdminController
'width' => 100, 'width' => 100,
'orderby' => false, 'orderby' => false,
'type' => 'select', 'type' => 'select',
'select' => array( 'list' => array(
0 => $this->l('Male'), 0 => $this->l('Male'),
1 => $this->l('Female'), 1 => $this->l('Female'),
2 => $this->l('Neutral') 2 => $this->l('Neutral')
@@ -175,7 +175,7 @@ class AdminGroupShopControllerCore extends AdminController
'name' => 'useImportData', 'name' => 'useImportData',
'value' => 1 'value' => 1
), ),
'select' => array( 'list' => array(
'type' => 'select', 'type' => 'select',
'name' => 'importFromShop', 'name' => 'importFromShop',
'options' => array( 'options' => array(
@@ -171,7 +171,7 @@ class AdminManufacturersControllerCore extends AdminController
'title' => $this->l('Country'), 'title' => $this->l('Country'),
'width' => 100, 'width' => 100,
'type' => 'select', 'type' => 'select',
'select' => $this->countries_array, 'list' => $this->countries_array,
'filter_key' => 'cl!id_country' 'filter_key' => 'cl!id_country'
) )
); );
+1 -1
View File
@@ -66,7 +66,7 @@ class AdminOrdersControllerCore extends AdminController
'customer' => array('title' => $this->l('Customer'), 'widthColumn' => 160, 'width' => 140, 'filter_key' => 'customer', 'tmpTableFilter' => true), 'customer' => array('title' => $this->l('Customer'), 'widthColumn' => 160, 'width' => 140, 'filter_key' => 'customer', 'tmpTableFilter' => true),
'total_paid' => array('title' => $this->l('Total'), 'width' => 70, 'align' => 'right', 'prefix' => '<b>', 'suffix' => '</b>', 'price' => true, 'currency' => true), 'total_paid' => array('title' => $this->l('Total'), 'width' => 70, 'align' => 'right', 'prefix' => '<b>', 'suffix' => '</b>', 'price' => true, 'currency' => true),
'payment' => array('title' => $this->l('Payment'), 'width' => 100), 'payment' => array('title' => $this->l('Payment'), 'width' => 100),
'osname' => array('title' => $this->l('Status'), 'widthColumn' => 230, 'type' => 'select', 'select' => $statesArray, 'filter_key' => 'os!id_order_state', 'filter_type' => 'int', 'width' => 200), 'osname' => array('title' => $this->l('Status'), 'widthColumn' => 230, 'type' => 'select', 'list' => $statesArray, 'filter_key' => 'os!id_order_state', 'filter_type' => 'int', 'width' => 200),
'date_add' => array('title' => $this->l('Date'), 'width' => 35, 'align' => 'right', 'type' => 'datetime', 'filter_key' => 'a!date_add'), 'date_add' => array('title' => $this->l('Date'), 'width' => 35, 'align' => 'right', 'type' => 'datetime', 'filter_key' => 'a!date_add'),
'id_pdf' => array('title' => $this->l('PDF'), 'callback' => 'printPDFIcons', 'orderby' => false, 'search' => false)); 'id_pdf' => array('title' => $this->l('PDF'), 'callback' => 'printPDFIcons', 'orderby' => false, 'search' => false));
$this->shopLinkType = 'shop'; $this->shopLinkType = 'shop';
@@ -3795,21 +3795,22 @@ $product->supplier_name = Supplier::getNameById($product->id_supplier);
{ {
if ($id = (int)(Tools::getValue($this->identifier)) AND Validate::isUnsignedId($id)) if ($id = (int)(Tools::getValue($this->identifier)) AND Validate::isUnsignedId($id))
{ {
if (!$this->_object) if (!$this->object)
$this->_object = new $this->className($id); $this->object = new $this->className($id);
if (Validate::isLoadedObject($this->_object)) if (Validate::isLoadedObject($this->object))
return $this->_object; return $this->object;
$this->_errors[] = Tools::displayError('Object cannot be loaded (not found)'); $this->_errors[] = Tools::displayError('Object cannot be loaded (not found)');
} }
else if ($opt) else if ($opt)
{ {
$this->_object = new $this->className(); $this->object = new $this->className();
return $this->_object; return $this->object;
} }
else else
$this->_errors[] = Tools::displayError('Object cannot be loaded (identifier missing or invalid)'); $this->_errors[] = Tools::displayError('Object cannot be loaded (identifier missing or invalid)');
$this->displayErrors(); $this->displayErrors();
return $this->object;
} }
public function displayInitInformationAndAttachment() public function displayInitInformationAndAttachment()
@@ -52,7 +52,7 @@ class AdminStockMvtControllerCore extends AdminController
'align' => 'center', 'align' => 'center',
'type' => 'select', 'type' => 'select',
'filter_key' => 'a!sign', 'filter_key' => 'a!sign',
'select' => array( 'list' => array(
'1' => $this->l('Increment'), '1' => $this->l('Increment'),
'-1' => $this->l('Decrement'), '-1' => $this->l('Decrement'),
), ),