// Code Review Invoices V&V

This commit is contained in:
vChabot
2012-02-03 15:55:53 +00:00
parent 1d6a012c57
commit 35c01bb36d
9 changed files with 189 additions and 202 deletions
+35 -36
View File
@@ -35,7 +35,7 @@ abstract class HTMLTemplateCore
public $date;
public $available_in_your_account = true;
public $smarty;
public $shop;
public $shop;
/**
* Returns the template's HTML header
@@ -43,9 +43,9 @@ abstract class HTMLTemplateCore
*/
public function getHeader()
{
$shop_name = '';
if (Validate::isLoadedObject($this->shop))
$shop_name = $this->shop->name;
$shop_name = '';
if (Validate::isLoadedObject($this->shop))
$shop_name = $this->shop->name;
$this->smarty->assign(array(
'logo_path' => $this->getLogo(),
@@ -65,7 +65,7 @@ abstract class HTMLTemplateCore
*/
public function getFooter()
{
$shop_address = $this->getShopAddress();
$shop_address = $this->getShopAddress();
$this->smarty->assign(array(
'available_in_your_account' => $this->available_in_your_account,
@@ -75,32 +75,33 @@ abstract class HTMLTemplateCore
'shop_details' => Configuration::get('PS_SHOP_DETAILS'),
'free_text' => Configuration::get('PS_INVOICE_FREE_TEXT')
));
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/footer.tpl');
}
/**
* Returns the shop address
* @return string
*/
protected function getShopAddress()
{
$shop_address = '';
if (Validate::isLoadedObject($this->shop))
{
$shop_address_obj = $this->shop->getAddress();
if (isset($shop_address_obj) && $shop_address_obj instanceof Address)
$shop_address = AddressFormat::generateAddress($shop_address_obj, array(), ' - ', ' ');
return $shop_address;
}
/**
* Returns the shop address
* @return string
*/
protected function getShopAddress()
{
$shop_address = '';
if (Validate::isLoadedObject($this->shop))
{
$shop_address_obj = $this->shop->getAddress();
if (isset($shop_address_obj) && $shop_address_obj instanceof Address)
$shop_address = AddressFormat::generateAddress($shop_address_obj, array(), ' - ', ' ');
return $shop_address;
}
return $shop_address;
}
return $shop_address;
}
/**
/**
* Returns the invoice logo
*/
protected function getLogo()
{
protected function getLogo()
{
$logo = '';
if (file_exists(_PS_IMG_DIR_.'logo_invoice.jpg'))
@@ -109,7 +110,7 @@ abstract class HTMLTemplateCore
$logo = _PS_IMG_.'logo.jpg';
return $logo;
}
}
/**
* Assign hook data
@@ -122,7 +123,7 @@ abstract class HTMLTemplateCore
$hook_name = 'displayPDF'.$template;
$this->smarty->assign(array(
'HOOK_DISPLAY_PDF' => Hook::exec($hook_name, array('object' => $object)),
'HOOK_DISPLAY_PDF' => Hook::exec($hook_name, array('object' => $object))
));
}
@@ -137,16 +138,13 @@ abstract class HTMLTemplateCore
* Returns the template filename
* @return string filename
*/
abstract public function getFilename();
abstract public function getFilename();
/**
* Returns the template filename when using bulk rendering
* @return string filename
*/
abstract public function getBulkFilename();
abstract public function getBulkFilename();
/**
* Translatation method
@@ -157,15 +155,16 @@ abstract class HTMLTemplateCore
{
$iso = Context::getContext()->language->iso_code;
if (!Validate::isLangIsoCode($iso))
die('Invalid iso lang ('.$iso.')');
if (!Validate::isLangIsoCode($iso))
Tools::displayError(sprintf('Invalid iso lang (%s)', Tools::safeOutput($iso)));
if (@!include(_PS_THEME_DIR_.'pdf/lang/'.$iso.'.php'))
die('Cannot include PDF translation language file : '._PS_THEME_DIR_.'pdf/lang/'.$iso.'.php');
$file_name = _PS_THEME_DIR_.'pdf/lang/'.$iso.'.php';
if (!file_exists($file_name) || !include($file_name))
Tools::displayError(sprintf('Cannot include PDF translation language file : %s', $file_name));
if (!isset($_LANGPDF) || !is_array($_LANGPDF))
return str_replace('"', '"', $string);
$key = md5(str_replace('\'', '\\\'', $string));
$key = md5(str_replace('\'', '\\\'', $string));
$str = (key_exists('PDF'.$key, $_LANGPDF) ? $_LANGPDF['PDF'.$key] : $string);
return $str;