From 2f6dc0cc37c3b30b60a81a3d9585d94f2d9b7215 Mon Sep 17 00:00:00 2001 From: mDeflotte Date: Wed, 28 Sep 2011 13:56:53 +0000 Subject: [PATCH] //PasswordController+PdfInvoiceController+PdfOrderReturnController+PdfOrederSlipController+PricesDropController : Refacto done --- controllers/front/PasswordController.php | 39 ++++++++++++------- controllers/front/PdfInvoiceController.php | 18 +++++---- .../front/PdfOrderReturnController.php | 14 ++++--- controllers/front/PdfOrderSlipController.php | 18 +++++---- controllers/front/PricesDropController.php | 6 ++- 5 files changed, 62 insertions(+), 33 deletions(-) diff --git a/controllers/front/PasswordController.php b/controllers/front/PasswordController.php index 812017943..42e966361 100644 --- a/controllers/front/PasswordController.php +++ b/controllers/front/PasswordController.php @@ -31,11 +31,15 @@ class PasswordControllerCore extends FrontController { public $php_self = 'password'; - public function process() + /** + * Start forms process + * @see FrontController::preProcess() + */ + public function preProcess() { if (Tools::isSubmit('email')) { - if (!($email = Tools::getValue('email')) OR !Validate::isEmail($email)) + if (!($email = Tools::getValue('email')) || !Validate::isEmail($email)) $this->errors[] = Tools::displayError('Invalid e-mail address'); else { @@ -50,10 +54,11 @@ class PasswordControllerCore extends FrontController else { if (Mail::Send($this->context->language->id, 'password_query', Mail::l('Password query confirmation'), - array('{email}' => $customer->email, - '{lastname}' => $customer->lastname, - '{firstname}' => $customer->firstname, - '{url}' => $this->context->link->getPageLink('password', true, NULL, 'token='.$customer->secure_key.'&id_customer='.(int)$customer->id)), + array( + '{email}' => $customer->email, + '{lastname}' => $customer->lastname, + '{firstname}' => $customer->firstname, + '{url}' => $this->context->link->getPageLink('password', true, null, 'token='.$customer->secure_key.'&id_customer='.(int)$customer->id)), $customer->email, $customer->firstname.' '.$customer->lastname)) $this->context->smarty->assign(array('confirmation' => 2, 'email' => $customer->email)); @@ -63,7 +68,7 @@ class PasswordControllerCore extends FrontController } } } - elseif (($token = Tools::getValue('token')) && ($id_customer = (int)(Tools::getValue('id_customer')))) + else if (($token = Tools::getValue('token')) && ($id_customer = (int)(Tools::getValue('id_customer')))) { $email = Db::getInstance()->getValue('SELECT `email` FROM '._DB_PREFIX_.'customer c WHERE c.`secure_key` = "'.pSQL($token).'" AND c.id_customer='.(int)($id_customer)); if ($email) @@ -79,10 +84,11 @@ class PasswordControllerCore extends FrontController if ($customer->update()) { if (Mail::Send($this->context->language->id, 'password', Mail::l('Your password'), - array('{email}' => $customer->email, - '{lastname}' => $customer->lastname, - '{firstname}' => $customer->firstname, - '{passwd}' => $password), + array( + '{email}' => $customer->email, + '{lastname}' => $customer->lastname, + '{firstname}' => $customer->firstname, + '{passwd}' => $password), $customer->email, $customer->firstname.' '.$customer->lastname)) $this->context->smarty->assign(array('confirmation' => 1, 'email' => $customer->email)); @@ -96,9 +102,16 @@ class PasswordControllerCore extends FrontController else $this->errors[] = Tools::displayError('We cannot regenerate your password with the data you submitted'); } - elseif (($token = Tools::getValue('token')) || ($id_customer = Tools::getValue('id_customer'))) + else if (($token = Tools::getValue('token')) || ($id_customer = Tools::getValue('id_customer'))) $this->errors[] = Tools::displayError('We cannot regenerate your password with the data you submitted'); - + } + + /** + * Assign template vars related to page content + * @see FrontController::process() + */ + public function process() + { $this->setTemplate(_PS_THEME_DIR_.'password.tpl'); } } diff --git a/controllers/front/PdfInvoiceController.php b/controllers/front/PdfInvoiceController.php index 61b3494b0..b80e32323 100644 --- a/controllers/front/PdfInvoiceController.php +++ b/controllers/front/PdfInvoiceController.php @@ -27,22 +27,26 @@ class PdfInvoiceControllerCore extends FrontController { + /** + * Assign template vars related to page content + * @see FrontController::process() + */ public function process() { $this->displayHeader(false); $this->displayFooter(false); - if (!$this->context->customer->isLogged() AND !Tools::getValue('secure_key')) + if (!$this->context->customer->isLogged() && !Tools::getValue('secure_key')) Tools::redirect('index.php?controller=authentication&back=pdf-invoice'); if (!(int)(Configuration::get('PS_INVOICE'))) die(Tools::displayError('Invoices are disabled in this shop.')); - if (isset($_GET['id_order']) AND Validate::isUnsignedId($_GET['id_order'])) + if (isset($_GET['id_order']) && Validate::isUnsignedId($_GET['id_order'])) $order = new Order((int)($_GET['id_order'])); - if (!isset($order) OR !Validate::isLoadedObject($order)) - die(Tools::displayError('Invoice not found')); - elseif ((isset($this->context->customer->id) AND $order->id_customer != $this->context->customer->id) OR (Tools::isSubmit('secure_key') AND $order->secure_key != Tools::getValue('secure_key'))) - die(Tools::displayError('Invoice not found')); - elseif (!OrderState::invoiceAvailable($order->getCurrentState()) AND !$order->invoice_number) + if (!isset($order) || !Validate::isLoadedObject($order)) + die(Tools::displayError('Invoice not found')); + else if ((isset($this->context->customer->id) && $order->id_customer != $this->context->customer->id) || (Tools::isSubmit('secure_key') && $order->secure_key != Tools::getValue('secure_key'))) + die(Tools::displayError('Invoice not found')); + else if (!OrderState::invoiceAvailable($order->getCurrentState()) && !$order->invoice_number) die(Tools::displayError('No invoice available')); else PDF::invoice($order); diff --git a/controllers/front/PdfOrderReturnController.php b/controllers/front/PdfOrderReturnController.php index c59aee774..b7e942e3b 100644 --- a/controllers/front/PdfOrderReturnController.php +++ b/controllers/front/PdfOrderReturnController.php @@ -27,6 +27,10 @@ class PdfOrderReturnControllerCore extends FrontController { + /** + * Assign template vars related to page content + * @see FrontController::process() + */ public function process() { $this->displayHeader(false); @@ -35,14 +39,14 @@ class PdfOrderReturnControllerCore extends FrontController if (!$this->context->customer->isLogged()) Tools::redirect('index.php?controller=authentication&back=order-follow'); - if (isset($_GET['id_order_return']) AND Validate::isUnsignedId($_GET['id_order_return'])) + if (isset($_GET['id_order_return']) && Validate::isUnsignedId($_GET['id_order_return'])) $orderReturn = new OrderReturn((int)($_GET['id_order_return'])); - if (!isset($orderReturn) OR !Validate::isLoadedObject($orderReturn)) - die(Tools::displayError('Order return not found')); + if (!isset($orderReturn) || !Validate::isLoadedObject($orderReturn)) + die(Tools::displayError('Order return not found')); else if ($orderReturn->id_customer != $this->context->customer->id) - die(Tools::displayError('Order return not found')); + die(Tools::displayError('Order return not found')); else if ($orderReturn->state < 2) - die(Tools::displayError('Order return not confirmed')); + die(Tools::displayError('Order return not confirmed')); else PDF::orderReturn($orderReturn); } diff --git a/controllers/front/PdfOrderSlipController.php b/controllers/front/PdfOrderSlipController.php index d3d2bb444..2f676b20f 100644 --- a/controllers/front/PdfOrderSlipController.php +++ b/controllers/front/PdfOrderSlipController.php @@ -27,6 +27,10 @@ class PdfOrderSlipControllerCore extends FrontController { + /** + * Assign template vars related to page content + * @see FrontController::process() + */ public function process() { $this->displayHeader(false); @@ -35,17 +39,17 @@ class PdfOrderSlipControllerCore extends FrontController if (!$this->context->customer->isLogged()) Tools::redirect('index.php?controller=authentication&back=order-follow'); - if (isset($_GET['id_order_slip']) AND Validate::isUnsignedId($_GET['id_order_slip'])) + if (isset($_GET['id_order_slip']) && Validate::isUnsignedId($_GET['id_order_slip'])) $orderSlip = new OrderSlip((int)($_GET['id_order_slip'])); - if (!isset($orderSlip) OR !Validate::isLoadedObject($orderSlip)) - die(Tools::displayError('Order return not found')); - elseif ($orderSlip->id_customer != $this->context->customer->id) - die(Tools::displayError('Order return not found')); + if (!isset($orderSlip) || !Validate::isLoadedObject($orderSlip)) + die(Tools::displayError('Order return not found')); + else if ($orderSlip->id_customer != $this->context->customer->id) + die(Tools::displayError('Order return not found')); $order = new Order((int)($orderSlip->id_order)); if (!Validate::isLoadedObject($order)) - die(Tools::displayError('Order not found')); + die(Tools::displayError('Order not found')); $order->products = OrderSlip::getOrdersSlipProducts((int)($orderSlip->id), $order); - $ref = NULL; + $ref = null; PDF::invoice($order, 'D', false, $ref, $orderSlip); } } \ No newline at end of file diff --git a/controllers/front/PricesDropController.php b/controllers/front/PricesDropController.php index 0f1131f8d..e0d520a9b 100644 --- a/controllers/front/PricesDropController.php +++ b/controllers/front/PricesDropController.php @@ -35,10 +35,14 @@ class PricesDropControllerCore extends FrontController $this->addCSS(_THEME_CSS_DIR_.'product_list.css'); } + /** + * Assign template vars related to page content + * @see FrontController::process() + */ public function process() { $this->productSort(); - $nbProducts = Product::getPricesDrop($this->context->language->id, NULL, NULL, true); + $nbProducts = Product::getPricesDrop($this->context->language->id, null, null, true); $this->pagination($nbProducts); $this->context->smarty->assign(array(