Continued:
[core.git] / framework / main / classes / helper / html / blocks / class_HtmlBlockHelper.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\CoreFramework\Helper;
4
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Helper\Template\HelpableTemplate;
7 use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
8
9 /**
10  * A helper for generating blocks (div or span) on web pages
11  *
12  * @author              Roland Haeder <webmaster@shipsimu.org>
13  * @version             0.0.0
14  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
15  * @license             GNU GPL 3.0 or any newer version
16  * @link                http://www.shipsimu.org
17  *
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.
22  *
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.
27  *
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/>.
30  */
31 class HtmlBlockHelper extends BaseHtmlHelper implements HelpableTemplate {
32         /**
33          * Name of the block
34          */
35         private $blockName = '';
36
37         /**
38          * Protected constructor
39          *
40          * @return      void
41          */
42         protected function __construct () {
43                 // Call parent constructor
44                 parent::__construct(__CLASS__);
45         }
46
47         /**
48          * Creates the helper class
49          *
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
53          */
54         public static final function createHtmlBlockHelper (CompileableTemplate $templateInstance, $blockName) {
55                 // Get new instance
56                 $helperInstance = new HtmlBlockHelper();
57
58                 // Set template instance
59                 $helperInstance->setTemplateInstance($templateInstance);
60
61                 // Set block name
62                 $helperInstance->setBlockName($blockName);
63
64                 // Return the prepared instance
65                 return $helperInstance;
66         }
67
68         /**
69          * Setter for block name
70          *
71          * @param       $blockName      Name of the block we shall generate
72          * @return      void
73          */
74         protected final function setBlockName ($blockName) {
75                 $this->blockName = (string) $blockName;
76         }
77
78         /**
79          * Getter for block name
80          *
81          * @return      $blockName      Name of the block we shall generate
82          */
83         public final function getBlockName () {
84                 return $this->blockName;
85         }
86
87         /**
88          * Checks whether include registration date in this block
89          *
90          * @return      $withRegistration       Whether with registration date
91          */
92         public function ifIncludeRegistrationStamp () {
93                 $withRegistration = ($this->getConfigInstance()->getConfigEntry('block_shows_registration') == 'Y');
94                 return $withRegistration;
95         }
96
97         /**
98          * Assignes a template variable with a message from a given message id
99          *
100          * @param       $templateVariable       Template variable to assign
101          * @param       $messageId                      Message id to load an assign
102          * @return      void
103          */
104         public function assignMessageField ($templateVariable, $messageId) {
105                 // Get message
106                 $message = $this->getLanguageInstance()->getMessage($messageId);
107
108                 // And assign it
109                 $this->getTemplateInstance()->assignVariable($templateVariable, $message);
110         }
111
112         /**
113          * Assigns a link field with a given value
114          *
115          * @param       $linkField              "Link field" (variable) to assign
116          * @param       $actionValue    Action value to assign
117          * @return      void
118          */
119         public function assignLinkFieldWithAction ($linkField, $actionValue) {
120                 $this->getTemplateInstance()->assignVariable($linkField . '_action', $actionValue);
121         }
122
123         /**
124          * "Filter" method for translating the raw user status into something human-readable
125          *
126          * @param       $userStatus             Raw user status from database layer
127          * @return      $translated             Translated user status
128          */
129         protected function doFilterUserStatusTranslator ($userStatus) {
130                 // Generate message id
131                 $messageId = 'user_status_' . strtolower($userStatus);
132
133                 // Get that message
134                 $translated = $this->getLanguageInstance()->getMessage($messageId);
135
136                 // Return it
137                 return $translated;
138         }
139
140         /**
141          * Flush the content out,e g. to a template variable
142          *
143          * @return      void
144          */
145         public function flushContent () {
146                 // Get template instance
147                 $templateInstance = $this->getTemplateInstance();
148
149                 // Get the template named like this block
150                 $templateInstance->loadCodeTemplate('block_' . $this->getBlockName());
151
152                 // Transfer it to the template instance
153                 $templateInstance->assignVariable($this->getBlockName(), $templateInstance->getRawTemplateData());
154         }
155
156 }