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 <<<<<<< HEAD:framework/main/classes/helper/html/blocks/class_HtmlBlockHelper.php
15 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
17 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
18 >>>>>>> Some updates::inc/main/classes/helper/html/blocks/class_HtmlBlockHelper.php
19 * @license GNU GPL 3.0 or any newer version
20 * @link http://www.shipsimu.org
22 * This program is free software: you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation, either version 3 of the License, or
25 * (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program. If not, see <http://www.gnu.org/licenses/>.
35 class HtmlBlockHelper extends BaseHtmlHelper implements HelpableTemplate {
39 private $blockName = '';
42 * Protected constructor
46 protected function __construct () {
47 // Call parent constructor
48 parent::__construct(__CLASS__);
52 * Creates the helper class
54 * @param $templateInstance An instance of a template engine
55 * @param $blockName Name of the block we shall generate
56 * @return $helperInstance A prepared instance of this helper
58 public static final function createHtmlBlockHelper (CompileableTemplate $templateInstance, $blockName) {
60 $helperInstance = new HtmlBlockHelper();
62 // Set template instance
63 $helperInstance->setTemplateInstance($templateInstance);
66 $helperInstance->setBlockName($blockName);
68 // Return the prepared instance
69 return $helperInstance;
73 * Setter for block name
75 * @param $blockName Name of the block we shall generate
78 protected final function setBlockName ($blockName) {
79 $this->blockName = (string) $blockName;
83 * Getter for block name
85 * @return $blockName Name of the block we shall generate
87 public final function getBlockName () {
88 return $this->blockName;
92 * Checks whether include registration date in this block
94 * @return $withRegistration Whether with registration date
96 public function ifIncludeRegistrationStamp () {
97 $withRegistration = ($this->getConfigInstance()->getConfigEntry('block_shows_registration') == 'Y');
98 return $withRegistration;
102 * Assignes a template variable with a message from a given message id
104 * @param $templateVariable Template variable to assign
105 * @param $messageId Message id to load an assign
108 public function assignMessageField ($templateVariable, $messageId) {
110 $message = $this->getLanguageInstance()->getMessage($messageId);
113 $this->getTemplateInstance()->assignVariable($templateVariable, $message);
117 * Assigns a link field with a given value
119 * @param $linkField "Link field" (variable) to assign
120 * @param $actionValue Action value to assign
123 public function assignLinkFieldWithAction ($linkField, $actionValue) {
124 $this->getTemplateInstance()->assignVariable($linkField . '_action', $actionValue);
128 * "Filter" method for translating the raw user status into something human-readable
130 * @param $userStatus Raw user status from database layer
131 * @return $translated Translated user status
133 protected function doFilterUserStatusTranslator ($userStatus) {
134 // Generate message id
135 $messageId = 'user_status_' . strtolower($userStatus);
138 $translated = $this->getLanguageInstance()->getMessage($messageId);
145 * Flush the content out,e g. to a template variable
149 public function flushContent () {
150 // Get template instance
151 $templateInstance = $this->getTemplateInstance();
153 // Get the template named like this block
154 $templateInstance->loadCodeTemplate('block_' . $this->getBlockName());
156 // Transfer it to the template instance
157 $templateInstance->assignVariable($this->getBlockName(), $templateInstance->getRawTemplateData());