3 namespace Org\Mxchange\CoreFramework\Helper;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
7 use Org\Mxchange\CoreFramework\Helper\Template\HelpableTemplate;
8 use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
11 * A helper for generating blocks (div or span) on web pages
13 * @author Roland Haeder <webmaster@shipsimu.org>
15 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
16 * @license GNU GPL 3.0 or any newer version
17 * @link http://www.shipsimu.org
19 * This program is free software: you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation, either version 3 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 class HtmlBlockHelper extends BaseHtmlHelper implements HelpableTemplate {
36 private $blockName = '';
39 * Protected constructor
43 protected function __construct () {
44 // Call parent constructor
45 parent::__construct(__CLASS__);
49 * Creates the helper class
51 * @param $templateInstance An instance of a template engine
52 * @param $blockName Name of the block we shall generate
53 * @return $helperInstance A prepared instance of this helper
55 public static final function createHtmlBlockHelper (CompileableTemplate $templateInstance, string $blockName) {
57 $helperInstance = new HtmlBlockHelper();
59 // Set template instance
60 $helperInstance->setTemplateInstance($templateInstance);
63 $helperInstance->setBlockName($blockName);
65 // Return the prepared instance
66 return $helperInstance;
70 * Setter for block name
72 * @param $blockName Name of the block we shall generate
75 protected final function setBlockName ($blockName) {
76 $this->blockName = (string) $blockName;
80 * Getter for block name
82 * @return $blockName Name of the block we shall generate
84 public final function getBlockName () {
85 return $this->blockName;
89 * Checks whether include registration date in this block
91 * @return $withRegistration Whether with registration date
93 public function ifIncludeRegistrationStamp () {
94 $withRegistration = (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('block_shows_registration') == 'Y');
95 return $withRegistration;
99 * Assignes a template variable with a message from a given message id
101 * @param $templateVariable Template variable to assign
102 * @param $messageId Message id to load an assign
105 public function assignMessageField (string $templateVariable, string $messageId) {
107 $message = FrameworkBootstrap::getLanguageInstance()->getMessage($messageId);
110 $this->getTemplateInstance()->assignVariable($templateVariable, $message);
114 * Assigns a link field with a given value
116 * @param $linkField "Link field" (variable) to assign
117 * @param $actionValue Action value to assign
120 public function assignLinkFieldWithAction (string $linkField, $actionValue) {
121 $this->getTemplateInstance()->assignVariable($linkField . '_action', $actionValue);
125 * "Filter" method for translating the raw user status into something human-readable
127 * @param $userStatus Raw user status from database layer
128 * @return $translated Translated user status
130 protected function doFilterUserStatusTranslator (string $userStatus) {
131 // Generate message id
132 $messageId = sprintf('user_status_%s', strtolower($userStatus));
135 $translated = FrameworkBootstrap::getLanguageInstance()->getMessage($messageId);
142 * Flush the content out,e g. to a template variable
146 public function flushContent () {
147 // Get template instance
148 $templateInstance = $this->getTemplateInstance();
150 // Get the template named like this block
151 $templateInstance->loadCodeTemplate('block_' . $this->getBlockName());
153 // Transfer it to the template instance
154 $templateInstance->assignVariable($this->getBlockName(), $templateInstance->getRawTemplateData());