3 namespace CoreFramework\Helper;
5 // Import framework stuff
6 use CoreFramework\Template\CompileableTemplate;
9 * A helper for generating blocks (div or span) on web pages
11 * @author Roland Haeder <webmaster@shipsimu.org>
13 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
14 * @license GNU GPL 3.0 or any newer version
15 * @link http://www.shipsimu.org
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 class HtmlBlockHelper extends BaseHtmlHelper implements HelpableTemplate {
34 private $blockName = '';
37 * Protected constructor
41 protected function __construct () {
42 // Call parent constructor
43 parent::__construct(__CLASS__);
47 * Creates the helper class
49 * @param $templateInstance An instance of a template engine
50 * @param $blockName Name of the block we shall generate
51 * @return $helperInstance A prepared instance of this helper
53 public static final function createHtmlBlockHelper (CompileableTemplate $templateInstance, $blockName) {
55 $helperInstance = new HtmlBlockHelper();
57 // Set template instance
58 $helperInstance->setTemplateInstance($templateInstance);
61 $helperInstance->setBlockName($blockName);
63 // Return the prepared instance
64 return $helperInstance;
68 * Setter for block name
70 * @param $blockName Name of the block we shall generate
73 protected final function setBlockName ($blockName) {
74 $this->blockName = (string) $blockName;
78 * Getter for block name
80 * @return $blockName Name of the block we shall generate
82 public final function getBlockName () {
83 return $this->blockName;
87 * Checks whether include registration date in this block
89 * @return $withRegistration Whether with registration date
91 public function ifIncludeRegistrationStamp () {
92 $withRegistration = ($this->getConfigInstance()->getConfigEntry('block_shows_registration') == 'Y');
93 return $withRegistration;
97 * Assignes a template variable with a message from a given message id
99 * @param $templateVariable Template variable to assign
100 * @param $messageId Message id to load an assign
103 public function assignMessageField ($templateVariable, $messageId) {
105 $message = $this->getLanguageInstance()->getMessage($messageId);
108 $this->getTemplateInstance()->assignVariable($templateVariable, $message);
112 * Assigns a link field with a given value
114 * @param $linkField "Link field" (variable) to assign
115 * @param $actionValue Action value to assign
118 public function assignLinkFieldWithAction ($linkField, $actionValue) {
119 $this->getTemplateInstance()->assignVariable($linkField . '_action', $actionValue);
123 * "Filter" method for translating the raw user status into something human-readable
125 * @param $userStatus Raw user status from database layer
126 * @return $translated Translated user status
128 protected function doFilterUserStatusTranslator ($userStatus) {
129 // Generate message id
130 $messageId = 'user_status_' . strtolower($userStatus);
133 $translated = $this->getLanguageInstance()->getMessage($messageId);
140 * Flush the content out,e g. to a template variable
144 public function flushContent () {
145 // Get template instance
146 $templateInstance = $this->getTemplateInstance();
148 // Get the template named like this block
149 $templateInstance->loadCodeTemplate('block_' . $this->getBlockName());
151 // Transfer it to the template instance
152 $templateInstance->assignVariable($this->getBlockName(), $templateInstance->getRawTemplateData());