From 34268c722b4510054c371830319afcea085728ca Mon Sep 17 00:00:00 2001 From: Eriksen Costa Date: Sun, 19 Dec 2010 18:14:02 -0200 Subject: [PATCH] Adicionados novos métodos para {{{Core_Controller_Page_Abtract}}}: --- ieducar/intranet/include/clsBase.inc.php | 17 ++++++++++++++++- ieducar/lib/Core/Controller/Page/Abstract.php | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ieducar/tests/unit/Core/Controller/Page/AbstractTest.php | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 120 insertions(+), 2 deletions(-) diff --git a/ieducar/intranet/include/clsBase.inc.php b/ieducar/intranet/include/clsBase.inc.php index 45ab7f8..8ddb375 100755 --- a/ieducar/intranet/include/clsBase.inc.php +++ b/ieducar/intranet/include/clsBase.inc.php @@ -474,11 +474,26 @@ class clsBase extends clsConfig return $retorno; } + /** + * @see Core_Page_Controller_Abstract#getAppendedOutput() + * @see Core_Page_Controller_Abstract#getPrependedOutput() + */ function MakeBody() { $corpo = ''; foreach ($this->clsForm as $form) { $corpo .= $form->RenderHTML(); + + // Prepend output. + if (method_exists($form, 'getPrependedOutput')) { + $corpo = $form->getPrependedOutput() . $corpo; + } + + // Append output. + if (method_exists($form, 'getAppendedOutput')) { + $corpo = $corpo . $form->getAppendedOutput(); + } + if (is_string($form->prog_alert) && $form->prog_alert) { $this->prog_alert .= $form->prog_alert; } @@ -733,7 +748,7 @@ class clsBase extends clsConfig $saida_geral = $this->MakeHeadHtml(); // @todo else ruim, colocar abre e fecha colchetes ao redor de foreach. - if($this->renderMenu) { + if ($this->renderMenu) { $saida_geral .= $this->MakeBody(); } else { diff --git a/ieducar/lib/Core/Controller/Page/Abstract.php b/ieducar/lib/Core/Controller/Page/Abstract.php index ff29e3d..8d89657 100644 --- a/ieducar/lib/Core/Controller/Page/Abstract.php +++ b/ieducar/lib/Core/Controller/Page/Abstract.php @@ -130,6 +130,11 @@ abstract class Core_Controller_Page_Abstract public $url_cancelar = NULL; /** + * @var array + */ + private $_output = array(); + + /** * Construtor. */ public function __construct() @@ -384,6 +389,70 @@ abstract class Core_Controller_Page_Abstract } /** + * Adiciona conteúdo HTML após o conteúdo gerado por um + * Core_Controller_Page_Abstract. + * + * @param string $data A string HTML a ser adiciona após o conteúdo. + * @return Core_Controller_Page_Abstract Provê interface fluída + */ + public function appendOutput($data) + { + if (!empty($data) && is_string($data)) { + $this->_output['append'][] = $data; + } + return $this; + } + + /** + * Retorna todo o conteúdo acrescentado como uma string. + * @return string O conteúdo a ser acrescentado separado com uma quebra de linha. + * @see clsBase#MakeBody() + */ + public function getAppendedOutput() + { + return $this->_getOutput('append'); + } + + /** + * Adiciona conteúdo HTML antes do conteúdo HTML gerado por um + * Core_Controller_Page_Abstract. + * + * @param string $data A string HTML a ser adiciona após o conteúdo. + * @return Core_Controller_Page_Abstract Provê interface fluída + */ + public function prependOutput($data) + { + if (!empty($data) && is_string($data)) { + $this->_output['prepend'][] = $data; + } + return $this; + } + + /** + * Retorna todo o conteúdo prefixado como uma string. + * @return string O conteúdo a ser prefixado separado com uma quebra de linha. + * @see clsBase#MakeBody() + */ + public function getPrependedOutput() + { + return $this->_getOutput('prepend'); + } + + /** + * Retorna o conteúdo a ser adicionado a saída de acordo com a região. + * @param string $pos Região para retornar o conteúdo a ser adicionado na saída. + * @return string|NULL Conteúdo da região separado por uma quebra de linha ou + * NULL caso a região não exista. + */ + private function _getOutput($pos = 'prepend') + { + if (isset($this->_output[$pos])) { + return implode(PHP_EOL, $this->_output[$pos]); + } + return NULL; + } + + /** * @see CoreExt_Controller_Interface#dispatch() */ public function dispatch() diff --git a/ieducar/tests/unit/Core/Controller/Page/AbstractTest.php b/ieducar/tests/unit/Core/Controller/Page/AbstractTest.php index f62aa88..640e4a1 100644 --- a/ieducar/tests/unit/Core/Controller/Page/AbstractTest.php +++ b/ieducar/tests/unit/Core/Controller/Page/AbstractTest.php @@ -163,4 +163,38 @@ class Core_Controller_Page_AbstractTest extends UnitBaseTest { $this->_pageController->getBaseTitulo(); } -} \ No newline at end of file + + public function testAppendOutput() + { + $this->_pageController->appendOutput('string 1') + ->appendOutput('string 2'); + + $this->assertEquals( + 'string 1' . PHP_EOL . 'string 2', + $this->_pageController->getAppendedOutput(), + '->getAppendedOutput() retorna o conteúdo a ser adicionado como uma string separada por quebra de linha' + ); + } + + public function testGetApendedOutputRetornaNullQuandoNaoExisteConteudoASerAdicionado() + { + $this->assertNull($this->_pageController->getAppendedOutput()); + } + + public function testPrependOutput() + { + $this->_pageController->prependOutput('string 1') + ->prependOutput('string 2'); + + $this->assertEquals( + 'string 1' . PHP_EOL . 'string 2', + $this->_pageController->getPrependedOutput(), + '->getPrependedOutput() retorna o conteúdo a ser adicionado como uma string separada por quebra de linha' + ); + } + + public function testGetPrependedOutputRetornaNullQuandoNaoExisteConteudoASerAdicionado() + { + $this->assertNull($this->_pageController->getPrependedOutput()); + } +} -- libgit2 0.21.2