]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/helper/web/links/class_WebLinkHelper.php
A lot naming conventions applied:
[shipsimu.git] / inc / classes / main / helper / web / links / class_WebLinkHelper.php
index d52610261fa93e8da557df1e39e4e31263f78ab8..7c6a3fff9f7349623f6399aea97ba34dbb2064e4 100644 (file)
@@ -63,10 +63,34 @@ class WebLinkHelper extends BaseWebHelper implements HelpableTemplate {
                // Set link base
                $helperInstance->setLinkBase($linkBase);
 
+               // Add default group
+               $helperInstance->openGroupByIdContent('main', "");
+
                // Return the prepared instance
                return $helperInstance;
        }
 
+       /**
+        * Renders the link content (HTML code) with given link text and optional
+        * extra content
+        *
+        * @param       $linkText               Link text to set in link
+        * @param       $extraContent   Optional extra HTML content
+        * @return      $linkContent    Rendered text link content
+        */
+       private function renderLinkContentWithTextExtraContent ($linkText, $extraContent="") {
+               // Construct link content
+               $linkContent = sprintf("<a href=\"%s%s\" title=\"%s\">%s</a>",
+                       $this->getLinkBase(),
+                       $extraContent,
+                       $linkText,
+                       $linkText
+               );
+
+               // Return it
+               return $linkContent;
+       }
+
        /**
         * Setter for link name
         *
@@ -112,7 +136,20 @@ class WebLinkHelper extends BaseWebHelper implements HelpableTemplate {
         * @todo        Completely unimplemented
         */
        public function flushContent () {
-               // Needed to be implemented!
+               // Is a previous opened group still open?
+               if ($this->ifGroupOpenedPreviously()) {
+                       // Then close it
+                       $this->closePreviousGroupByContent("</div>");
+               } // END - if
+
+               // Get the content
+               $content = $this->renderContent();
+
+               // Get template engine
+               $templateInstance = $this->getTemplateInstance();
+
+               // Add content to variable
+               $templateInstance->assignVariable($this->getLinkName(), $content);
        }
 
        /**
@@ -127,10 +164,23 @@ class WebLinkHelper extends BaseWebHelper implements HelpableTemplate {
                // Is a group with that name open?
                if ($this->ifGroupIsOpened($groupId)) {
                        // Then close it here
-                       $this->closeGroupById($groupId);
+                       $this->closePreviousGroupByContent("</div>");
                } else {
+                       // Is a previous opened group still open?
+                       if ($this->ifGroupOpenedPreviously()) {
+                               // Then close it
+                               $this->closePreviousGroupByContent("</div>");
+                       } // END - if
+
+                       // Generate the group content
+                       $content = sprintf("<div id=\"group_%s_%s\">%s",
+                               $this->getLinkName(),
+                               $groupId,
+                               $groupText
+                       );
+
                        // Open the new group
-                       $this->openGroupByIdContent($groupId, $groupText);
+                       $this->openGroupByIdContent($groupId, $content);
                }
        }
 
@@ -141,17 +191,72 @@ class WebLinkHelper extends BaseWebHelper implements HelpableTemplate {
         * @param       $groupNote      Note to be added to a group
         * @return      void
         * @throws      NoGroupOpenedException  If no previous group was opened
-        * @todo        Implement adding the note to the previously opened group or sub group
         */
        public function addLinkNote ($groupNote) {
                // Check if a previous group was opened
                if (!$this->ifGroupOpenedPreviously()) {
                        // No group was opened before!
                        throw new NoGroupOpenedException(array($this, $groupNote), self::EXCEPTION_GROUP_NOT_OPENED);
-               }
+               } // END - if
+
+               // Add the content to the previous group
+               $this->addContentToPreviousGroup($groupNote);
+       }
+
+       /**
+        * Adds a link to the previously opened group or throws an exception if no group has been opened
+        *
+        * @param       $linkAction             Action (action=xxx) value for the link
+        * @param       $linkText               Link text and title (title="xxx") for the link
+        * @return      void
+        * @throws      NoGroupOpenedException  If no previous group was opened
+        */
+       public function addActionLink ($linkAction, $linkText) {
+               // Check if a previous group was opened
+               if (!$this->ifGroupOpenedPreviously()) {
+                       // No group was opened before!
+                       throw new NoGroupOpenedException(array($this, $linkAction."(".$linkText.")"), self::EXCEPTION_GROUP_NOT_OPENED);
+               } // END - if
+
+               // Default parameter seperator is &amp;
+               $seperator = "&amp;";
+
+               // Is there a question mark in?
+               $linkArray = explode("?", $this->getLinkBase());
+               if (count($linkArray) == 0) {
+                       // No question mark
+                       $seperator = "?";
+               } // END - if
+
+               // Prepare action
+               $action = sprintf("%saction=%s",
+                       $seperator,
+                       $linkAction
+               );
+
+               // Renders the link content
+               $linkContent = $this->renderLinkContentWithTextExtraContent($linkText, $action);
+
+               // Add the content to the previous group
+               $this->addContentToPreviousGroup($linkContent);
+       }
+
+       /**
+        * Adds a default link (no extra parameters) to the content with specified
+        * language id string.
+        *
+        * @param       $languageId             Language id string to use
+        * @return      void
+        */
+       public function addLinkWithTextById ($languageId) {
+               // Resolve the language string
+               $languageResolved = $this->getLanguageInstance()->getMessage($languageId);
+
+               // Now add the link
+               $linkContent = $this->renderLinkContentWithTextExtraContent($languageResolved);
 
-               // Not fully implemented!
-               $this->partialStub();
+               // Add the content to the previous group
+               $this->addContentToPreviousGroup($linkContent);
        }
 }