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