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