/** * Render everything * * @param Tx_MooxNews_Domain_Model_News $object current news object * @param string $as name of property which holds the text * @param integer $currentPage Selected page * @param string $token Token used to split the text * @return string */ public function render(Tx_MooxNews_Domain_Model_News $object, $as, $currentPage, $token = '###more###') { $parts = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode($token, $object->getBodytext(), TRUE); $numberOfPages = count($parts); if ($numberOfPages === 1) { $result = $parts[0]; } else { $currentPage = (int) $currentPage; if ($currentPage < 1) { $currentPage = 1; } elseif ($currentPage > $numberOfPages) { $currentPage = $numberOfPages; } $tagsToOpen = array(); $tagsToClose = array(); for ($j = 0; $j < $currentPage; $j++) { $chunk = $parts[$j]; while ($chunk = mb_strstr($chunk, '<')) { $tag = $this->extractTag($chunk); $tagStrLen = mb_strlen($tag); if ($this->isOpeningTag($tag)) { if ($j < $currentPage - 1) { $tagsToOpen[] = $tag; } $tagsToClose[] = $tag; } elseif ($this->isClosingTag($tag)) { if ($j < $currentPage - 1) { array_pop($tagsToOpen); } elseif (mb_strpos($parts[$j], $chunk) === 0) { $parts[$j] = mb_substr($parts[$j], $tagStrLen); array_pop($tagsToOpen); } array_pop($tagsToClose); } $chunk = mb_substr($chunk, $tagStrLen); } } $result = join('', $tagsToOpen) . $parts[$currentPage - 1]; while ($tag = array_pop($tagsToClose)) { $result .= $this->getClosingTagByOpeningTag($tag); } } $pages = array(); for ($i = 1; $i <= $numberOfPages; $i++) { $pages[] = array('number' => $i, 'isCurrent' => $i === $currentPage); } $pagination = array('pages' => $pages, 'numberOfPages' => $numberOfPages, 'current' => $currentPage); if ($currentPage < $numberOfPages) { $pagination['nextPage'] = $currentPage + 1; } if ($currentPage > 1) { $pagination['previousPage'] = $currentPage - 1; } $this->templateVariableContainer->add($as, $result); $this->templateVariableContainer->add('pagination', $pagination); return $this->renderChildren(); }
/** * Test if bodytext can be set * * @test * @return void */ public function bodytextCanBeSet() { $bodytext = 'News bodytext'; $this->newsDomainModelInstance->setBodytext($bodytext); $this->assertEquals($bodytext, $this->newsDomainModelInstance->getBodytext()); }