From d24fcec613dc757c6d689df0e14cdd3943d9cad2 Mon Sep 17 00:00:00 2001 From: fBrignoli Date: Tue, 6 Dec 2011 08:55:01 +0000 Subject: [PATCH] [*] PDF : Display Hook --- classes/pdf/HTMLTemplate.php | 19 ++++++++++--------- classes/pdf/PDF.php | 15 ++++++++------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/classes/pdf/HTMLTemplate.php b/classes/pdf/HTMLTemplate.php index 6a5a9d35c..3ccafedf4 100755 --- a/classes/pdf/HTMLTemplate.php +++ b/classes/pdf/HTMLTemplate.php @@ -43,8 +43,6 @@ abstract class HTMLTemplateCore */ public function getHeader() { - $this->assignHookData(); - $this->smarty->assign(array( 'logo_path' => $this->getLogo(), 'img_ps_dir' => 'http://'.Tools::getMediaServer(_PS_IMG_)._PS_IMG_, @@ -94,15 +92,18 @@ abstract class HTMLTemplateCore } /** - * Returns the HTML content of the template's footer - */ - public function assignHookData() + * Assign hook data + * + * @param $object generally the object used in the constructor + */ + public function assignHookData($object) { - $data = array('title' => 'cool', - 'delivery' => array('date' => '25/11/11', 'delay' => '3')); + $template = ucfirst(str_replace('HTMLTemplate', '', get_class($this))); + $hook_name = 'displayPDF'.$template; - foreach ($data as $key => $value) - $this->smarty->assign($key, $value); + $this->smarty->assign(array( + 'HOOK_DISPLAY_PDF' => Hook::exec($hook_name, array('object' => $object)) + )); } /** diff --git a/classes/pdf/PDF.php b/classes/pdf/PDF.php index f0749e7aa..e86d5da5d 100755 --- a/classes/pdf/PDF.php +++ b/classes/pdf/PDF.php @@ -54,7 +54,6 @@ class PDFCore public function render() { - $render = false; $this->pdf_renderer->setFontForLang('fr'); foreach ($this->objects as $object) @@ -69,6 +68,8 @@ class PDFCore if (count($this->objects) > 1) $this->filename = $template->getBulkFilename(); } + + $template->assignHookData($object); $this->pdf_renderer->createHeader($template->getHeader()); $this->pdf_renderer->createFooter($template->getFooter()); @@ -89,12 +90,12 @@ class PDFCore $class = false; $classname = 'HTMLTemplate'.$this->template; - if (class_exists($classname)) - { - $class = new $classname($object, $this->smarty); - if (!($class instanceof HTMLTemplate)) - throw new PrestashopException('Invalid class. It should be an instance of HTMLTemplate'); - } + if (class_exists($classname)) + { + $class = new $classname($object, $this->smarty); + if (!($class instanceof HTMLTemplate)) + throw new PrestashopException('Invalid class. It should be an instance of HTMLTemplate'); + } return $class; }