]> git.mxchange.org Git - core.git/blob - framework/main/classes/helper/html/blocks/class_HtmlBlockHelper.php
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\Bootstrap\FrameworkBootstrap;
7 use Org\Mxchange\CoreFramework\Helper\Template\HelpableTemplate;
8 use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
9
10 /**
11  * A helper for generating blocks (div or span) on web pages
12  *
13  * @author              Roland Haeder <webmaster@shipsimu.org>
14  * @version             0.0.0
15  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
16  * @license             GNU GPL 3.0 or any newer version
17  * @link                http://www.shipsimu.org
18  *
19  * This program is free software: you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation, either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  */
32 class HtmlBlockHelper extends BaseHtmlHelper implements HelpableTemplate {
33         /**
34          * Name of the block
35          */
36         private $blockName = '';
37
38         /**
39          * Protected constructor
40          *
41          * @return      void
42          */
43         protected function __construct () {
44                 // Call parent constructor
45                 parent::__construct(__CLASS__);
46         }
47
48         /**
49          * Creates the helper class
50          *
51          * @param       $templateInstance       An instance of a template engine
52          * @param       $blockName                      Name of the block we shall generate
53          * @return      $helperInstance         A prepared instance of this helper
54          */
55         public static final function createHtmlBlockHelper (CompileableTemplate $templateInstance, string $blockName) {
56                 // Get new instance
57                 $helperInstance = new HtmlBlockHelper();
58
59                 // Set template instance
60                 $helperInstance->setTemplateInstance($templateInstance);
61
62                 // Set block name
63                 $helperInstance->setBlockName($blockName);
64
65                 // Return the prepared instance
66                 return $helperInstance;
67         }
68
69         /**
70          * Setter for block name
71          *
72          * @param       $blockName      Name of the block we shall generate
73          * @return      void
74          */
75         protected final function setBlockName (string $blockName) {
76                 $this->blockName = $blockName;
77         }
78
79         /**
80          * Getter for block name
81          *
82          * @return      $blockName      Name of the block we shall generate
83          */
84         public final function getBlockName () {
85                 return $this->blockName;
86         }
87
88         /**
89          * Checks whether include registration date in this block
90          *
91          * @return      $withRegistration       Whether with registration date
92          */
93         public function ifIncludeRegistrationStamp () {
94                 $withRegistration = (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('block_shows_registration') == 'Y');
95                 return $withRegistration;
96         }
97
98         /**
99          * Assignes a template variable with a message from a given message id
100          *
101          * @param       $templateVariable       Template variable to assign
102          * @param       $messageId                      Message id to load an assign
103          * @return      void
104          */
105         public function assignMessageField (string $templateVariable, string $messageId) {
106                 // Get message
107                 $message = FrameworkBootstrap::getLanguageInstance()->getMessage($messageId);
108
109                 // And assign it
110                 $this->getTemplateInstance()->assignVariable($templateVariable, $message);
111         }
112
113         /**
114          * Assigns a link field with a given value
115          *
116          * @param       $linkField              "Link field" (variable) to assign
117          * @param       $actionValue    Action value to assign
118          * @return      void
119          */
120         public function assignLinkFieldWithAction (string $linkField, $actionValue) {
121                 $this->getTemplateInstance()->assignVariable($linkField . '_action', $actionValue);
122         }
123
124         /**
125          * "Filter" method for translating the raw user status into something human-readable
126          *
127          * @param       $userStatus             Raw user status from database layer
128          * @return      $translated             Translated user status
129          */
130         protected function doFilterUserStatusTranslator (string $userStatus) {
131                 // Generate message id
132                 $messageId = sprintf('user_status_%s', strtolower($userStatus));
133
134                 // Get that message
135                 $translated = FrameworkBootstrap::getLanguageInstance()->getMessage($messageId);
136
137                 // Return it
138                 return $translated;
139         }
140
141         /**
142          * Flush the content out,e g. to a template variable
143          *
144          * @return      void
145          */
146         public function flushContent () {
147                 // Get template instance
148                 $templateInstance = $this->getTemplateInstance();
149
150                 // Get the template named like this block
151                 $templateInstance->loadCodeTemplate('block_' . $this->getBlockName());
152
153                 // Transfer it to the template instance
154                 $templateInstance->assignVariable($this->getBlockName(), $templateInstance->getRawTemplateData());
155         }
156
157 }