3 namespace Org\Mxchange\CoreFramework\Helper;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Helper\Template\HelpableTemplate;
7 use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
10 * A helper for generating blocks (div or span) on web pages
12 * @author Roland Haeder <webmaster@shipsimu.org>
14 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
15 * @license GNU GPL 3.0 or any newer version
16 * @link http://www.shipsimu.org
18 * This program is free software: you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation, either version 3 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 class HtmlBlockHelper extends BaseHtmlHelper implements HelpableTemplate {
35 private $blockName = '';
38 * Protected constructor
42 protected function __construct () {
43 // Call parent constructor
44 parent::__construct(__CLASS__);
48 * Creates the helper class
50 * @param $templateInstance An instance of a template engine
51 * @param $blockName Name of the block we shall generate
52 * @return $helperInstance A prepared instance of this helper
54 public static final function createHtmlBlockHelper (CompileableTemplate $templateInstance, $blockName) {
56 $helperInstance = new HtmlBlockHelper();
58 // Set template instance
59 $helperInstance->setTemplateInstance($templateInstance);
62 $helperInstance->setBlockName($blockName);
64 // Return the prepared instance
65 return $helperInstance;
69 * Setter for block name
71 * @param $blockName Name of the block we shall generate
74 protected final function setBlockName ($blockName) {
75 $this->blockName = (string) $blockName;
79 * Getter for block name
81 * @return $blockName Name of the block we shall generate
83 public final function getBlockName () {
84 return $this->blockName;
88 * Checks whether include registration date in this block
90 * @return $withRegistration Whether with registration date
92 public function ifIncludeRegistrationStamp () {
93 $withRegistration = ($this->getConfigInstance()->getConfigEntry('block_shows_registration') == 'Y');
94 return $withRegistration;
98 * Assignes a template variable with a message from a given message id
100 * @param $templateVariable Template variable to assign
101 * @param $messageId Message id to load an assign
104 public function assignMessageField ($templateVariable, $messageId) {
106 $message = $this->getLanguageInstance()->getMessage($messageId);
109 $this->getTemplateInstance()->assignVariable($templateVariable, $message);
113 * Assigns a link field with a given value
115 * @param $linkField "Link field" (variable) to assign
116 * @param $actionValue Action value to assign
119 public function assignLinkFieldWithAction ($linkField, $actionValue) {
120 $this->getTemplateInstance()->assignVariable($linkField . '_action', $actionValue);
124 * "Filter" method for translating the raw user status into something human-readable
126 * @param $userStatus Raw user status from database layer
127 * @return $translated Translated user status
129 protected function doFilterUserStatusTranslator ($userStatus) {
130 // Generate message id
131 $messageId = 'user_status_' . strtolower($userStatus);
134 $translated = $this->getLanguageInstance()->getMessage($messageId);
141 * Flush the content out,e g. to a template variable
145 public function flushContent () {
146 // Get template instance
147 $templateInstance = $this->getTemplateInstance();
149 // Get the template named like this block
150 $templateInstance->loadCodeTemplate('block_' . $this->getBlockName());
152 // Transfer it to the template instance
153 $templateInstance->assignVariable($this->getBlockName(), $templateInstance->getRawTemplateData());