class_WebLinkHelper.php

Go to the documentation of this file.
00001 <?php
00024 class WebLinkHelper extends BaseWebHelper implements HelpableTemplate {
00028         private $linkName = "";
00029 
00033         private $linkBase = "";
00034 
00040         protected function __construct () {
00041                 // Call parent constructor
00042                 parent::__construct(__CLASS__);
00043         }
00044 
00053         public final static function createWebLinkHelper (CompileableTemplate $templateInstance, $linkName, $linkBase) {
00054                 // Get new instance
00055                 $helperInstance = new WebLinkHelper();
00056 
00057                 // Set template instance
00058                 $helperInstance->setTemplateInstance($templateInstance);
00059 
00060                 // Set link name
00061                 $helperInstance->setLinkName($linkName);
00062 
00063                 // Set link base
00064                 $helperInstance->setLinkBase($linkBase);
00065 
00066                 // Add default group
00067                 $helperInstance->openGroupByIdContent('main', "", "");
00068 
00069                 // Return the prepared instance
00070                 return $helperInstance;
00071         }
00072 
00082         private function renderLinkContentWithTextExtraContent ($linkText, $linkTitle, $extraContent="") {
00083                 // Construct link content
00084                 $linkContent = sprintf("<a href=\"%s%s\" title=\"%s\">%s</a>",
00085                         $this->getLinkBase(),
00086                         $extraContent,
00087                         $linkTitle,
00088                         $linkText
00089                 );
00090 
00091                 // Return it
00092                 return $linkContent;
00093         }
00094 
00101         protected final function setLinkName ($linkName) {
00102                 $this->linkName = (string) $linkName;
00103         }
00104 
00110         public final function getLinkName () {
00111                 return $this->linkName;
00112         }
00113 
00120         protected final function setLinkBase ($linkBase) {
00121                 $this->linkBase = (string) $linkBase;
00122         }
00123 
00129         public final function getLinkBase () {
00130                 return $this->linkBase;
00131         }
00132 
00139         public function flushContent () {
00140                 // Is a previous opened group still open?
00141                 if ($this->ifGroupOpenedPreviously()) {
00142                         // Then close it
00143                         $this->closePreviousGroupByContent("");
00144                 } // END - if
00145 
00146                 // Get the content
00147                 $content = $this->renderContent();
00148 
00149                 // Get template engine
00150                 $templateInstance = $this->getTemplateInstance();
00151 
00152                 // Add content to variable
00153                 $templateInstance->assignVariable($this->getLinkName(), $content);
00154         }
00155 
00165         public function addLinkGroup ($groupId, $groupText, $groupCode = "div") {
00166                 // Is a group with that name open?
00167                 if ($this->ifGroupOpenedPreviously()) {
00168                         // Then close it here
00169                         $this->closePreviousGroupByContent("");
00170                 } // END - if
00171 
00172                 // Generate the group content
00173                 $content = sprintf("<{$groupCode} id=\"group_%s_%s\">%s",
00174                         $this->getLinkName(),
00175                         $groupId,
00176                         $groupText
00177                 );
00178 
00179                 // Open the new group
00180                 $this->openGroupByIdContent($groupId, $content, $groupCode);
00181         }
00182 
00193         public function addLinkNote ($groupId, $groupNote, $groupCode = "div") {
00194                 // Check if a previous group was opened
00195                 if ($this->ifGroupOpenedPreviously() === false) {
00196                         // No group was opened before!
00197                         throw new NoGroupOpenedException(array($this, $groupNote), self::EXCEPTION_GROUP_NOT_OPENED);
00198                 } // END - if
00199 
00200                 // Is a previous sub group open?
00201                 if ($this->ifSubGroupOpenedPreviously()) {
00202                         // Then close it
00203                         $this->closePreviousSubGroupByContent("</{$groupCode}>");
00204                 } // END - if
00205 
00206                 // Generate the group content
00207                 $content = sprintf("<{$groupCode} id=\"subgroup_%s_%s\">%s",
00208                         $this->getLinkName(),
00209                         $groupId,
00210                         $groupNote
00211                 );
00212 
00213                 // Open the sub group
00214                 $this->openSubGroupByIdContent($groupId, $content, $groupCode);
00215         }
00216 
00225         protected function addActionLink ($linkAction, $linkText, $linkTitle) {
00226                 // Check if a previous group was opened
00227                 if ($this->ifGroupOpenedPreviously() === false) {
00228                         // No group was opened before!
00229                         throw new NoGroupOpenedException(array($this, $linkAction."(".$linkText.")"), self::EXCEPTION_GROUP_NOT_OPENED);
00230                 } // END - if
00231 
00232                 // Default parameter seperator is &amp;
00233                 $seperator = "&amp;";
00234 
00235                 // Is there a question mark in?
00236                 $linkArray = explode("?", $this->getLinkBase());
00237                 if (count($linkArray) == 0) {
00238                         // No question mark
00239                         $seperator = "?";
00240                 } // END - if
00241 
00242                 // Prepare action
00243                 $action = sprintf("%saction=%s",
00244                         $seperator,
00245                         $linkAction
00246                 );
00247 
00248                 // Renders the link content
00249                 $linkContent = $this->renderLinkContentWithTextExtraContent($linkText, $linkTitle, $action);
00250 
00251                 // Add the content to the previous group
00252                 $this->addContentToPreviousGroup($linkContent);
00253         }
00254 
00262         public function addActionLinkById ($linkAction, $languageId) {
00263                 // Resolve the language string
00264                 $languageResolvedText = $this->getLanguageInstance()->getMessage("link_" . $languageId . "_text");
00265 
00266                 // Resolve the language string
00267                 $languageResolvedTitle = $this->getLanguageInstance()->getMessage("link_" . $languageId . "_title");
00268 
00269                 // Add the action link
00270                 $this->addActionLink($linkAction, $languageResolvedText, $languageResolvedTitle);
00271         }
00272 
00280         public function addLinkWithTextById ($languageId) {
00281                 // Resolve the language string
00282                 $languageResolvedText = $this->getLanguageInstance()->getMessage("link_" . $languageId . "_text");
00283 
00284                 // Resolve the language string
00285                 $languageResolvedTitle = $this->getLanguageInstance()->getMessage("link_" . $languageId . "_title");
00286 
00287                 // Now add the link
00288                 $linkContent = $this->renderLinkContentWithTextExtraContent($languageResolvedText, $languageResolvedTitle);
00289 
00290                 // Add the content to the previous group
00291                 $this->addContentToPreviousGroup($linkContent);
00292         }
00293 }
00294 
00295 // [EOF]
00296 ?>

Generated on Mon Dec 8 01:06:46 2008 for Ship-Simulator by  doxygen 1.5.6