3 * A helper for generating blocks (div or span) on web pages
5 * @author Roland Haeder <webmaster@shipsimu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.shipsimu.org
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 class HtmlBlockHelper extends BaseHtmlHelper implements HelpableTemplate {
28 private $blockName = '';
31 * Protected constructor
35 protected function __construct () {
36 // Call parent constructor
37 parent::__construct(__CLASS__);
41 * Creates the helper class
43 * @param $templateInstance An instance of a template engine
44 * @param $blockName Name of the block we shall generate
45 * @return $helperInstance A prepared instance of this helper
47 public static final function createHtmlBlockHelper (CompileableTemplate $templateInstance, $blockName) {
49 $helperInstance = new HtmlBlockHelper();
51 // Set template instance
52 $helperInstance->setTemplateInstance($templateInstance);
55 $helperInstance->setBlockName($blockName);
57 // Return the prepared instance
58 return $helperInstance;
62 * Setter for block name
64 * @param $blockName Name of the block we shall generate
67 protected final function setBlockName ($blockName) {
68 $this->blockName = (string) $blockName;
72 * Getter for block name
74 * @return $blockName Name of the block we shall generate
76 public final function getBlockName () {
77 return $this->blockName;
81 * Checks whether include registration date in this block
83 * @return $withRegistration Whether with registration date
85 public function ifIncludeRegistrationStamp () {
86 $withRegistration = ($this->getConfigInstance()->getConfigEntry('block_shows_registration') == 'Y');
87 return $withRegistration;
91 * Assignes a template variable with a message from a given message id
93 * @param $templateVariable Template variable to assign
94 * @param $messageId Message id to load an assign
97 public function assignMessageField ($templateVariable, $messageId) {
99 $message = $this->getLanguageInstance()->getMessage($messageId);
102 $this->getTemplateInstance()->assignVariable($templateVariable, $message);
106 * Assigns a link field with a given value
108 * @param $linkField "Link field" (variable) to assign
109 * @param $actionValue Action value to assign
112 public function assignLinkFieldWithAction ($linkField, $actionValue) {
113 $this->getTemplateInstance()->assignVariable($linkField . '_action', $actionValue);
117 * "Filter" method for translating the raw user status into something human-readable
119 * @param $userStatus Raw user status from database layer
120 * @return $translated Translated user status
122 protected function doFilterUserStatusTranslator ($userStatus) {
123 // Generate message id
124 $messageId = 'user_status_' . strtolower($userStatus);
127 $translated = $this->getLanguageInstance()->getMessage($messageId);
134 * Flush the content out,e g. to a template variable
138 public function flushContent () {
139 // Get template instance
140 $templateInstance = $this->getTemplateInstance();
142 // Get the template named like this block
143 $templateInstance->loadCodeTemplate('block_' . $this->getBlockName());
145 // Transfer it to the template instance
146 $templateInstance->assignVariable($this->getBlockName(), $templateInstance->getRawTemplateData());