f407889cbb12319794b1cdf0f254f2fb14f5113c
[shipsimu.git] / inc / classes / main / helper / web / links / class_WebLinkHelper.php
1 <?php
2 /**
3  * A helper for web links
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, this is free software
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.ship-simu.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 WebLinkHelper extends BaseWebHelper implements HelpableTemplate {
25         /**
26          * Name of the link
27          */
28         private $linkName = "";
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       $linkName                       Name of the link we shall generate
45          * @return      $helperInstance         A prepared instance of this helper
46          */
47         public final static function createWebLinkHelper (CompileableTemplate $templateInstance, $linkName) {
48                 // Get new instance
49                 $helperInstance = new WebLinkHelper();
50
51                 // Set template instance
52                 $helperInstance->setTemplateInstance($templateInstance);
53
54                 // Set Link name
55                 $helperInstance->setLinkName($linkName);
56
57                 // Return the prepared instance
58                 return $helperInstance;
59         }
60
61         /**
62          * Setter for link name
63          *
64          * @param       $linkName       Name of the link we shall generate
65          * @return      void
66          */
67         protected final function setLinkName ($linkName) {
68                 $this->linkName = (string) $linkName;
69         }
70
71         /**
72          * Getter for link name
73          *
74          * @return      $linkName       Name of the link we shall generate
75          */
76         public final function getLinkName () {
77                 return $this->linkName;
78         }
79
80         /**
81          * Flush the content out,e g. to a template variable
82          *
83          * @return      void
84          * @todo        Completely unimplemented
85          */
86         public function flushContent () {
87                 // Needed to be implemented!
88         }
89
90         /**
91          * Adds a link group (like the form group is) with some raw language to the
92          * helper.
93          *
94          * @param       $groupId        Id string of the group
95          * @param       $groupText      Text for this group to add
96          * @return      void
97          */
98         public function addLinkGroup ($groupId, $groupText) {
99                 // Is a group with that name open?
100                 if ($this->ifGroupIsOpened($groupId)) {
101                         // Then close it here
102                         $this->closeGroupById($groupId);
103                 } else {
104                         // Open the new group
105                         $this->openGroupByIdContent($groupId, $groupText);
106                 }
107         }
108
109         /**
110          * Adds text (note) to the previously opened group or throws an exception
111          * if no previous group was opened.
112          *
113          * @param       $groupNote      Note to be added to a group
114          * @return      void
115          * @throws      NoGroupOpenedException  If no previous group was opened
116          */
117         public function addLinkNote ($groupNote) {
118                 // Check if a previous group was opened
119                 if (!$this->ifGroupOpenedPreviously()) {
120                         // No group was opened before!
121                         throw new NoGroupOpenedException(array($this, $groupNote), self::EXCEPTION_GROUP_NOT_OPENED);
122                 }
123         }
124 }
125
126 // [EOF]
127 ?>