]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/helper/web/links/class_WebLinkHelper.php
A lot rewrites and fixes for weak redirect methods
[shipsimu.git] / inc / classes / main / helper / web / links / class_WebLinkHelper.php
index 24fb844b23ff6e0093b1fd0f853351d3513082be..1a238a6d2c2239d732363c50b371719a81ce6cf1 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
         *
@@ -115,7 +139,7 @@ class WebLinkHelper extends BaseWebHelper implements HelpableTemplate {
                // Is a previous opened group still open?
                if ($this->ifGroupOpenedPreviously()) {
                        // Then close it
-                       $this->closePreviousGroupByContent("</div>");
+                       $this->closePreviousGroupByContent("");
                } // END - if
 
                // Get the content
@@ -134,49 +158,59 @@ class WebLinkHelper extends BaseWebHelper implements HelpableTemplate {
         *
         * @param       $groupId        Id string of the group
         * @param       $groupText      Text for this group to add
+        * @param       $groupCode      Code to open and close groups
         * @return      void
         */
-       public function addLinkGroup ($groupId, $groupText) {
+       public function addLinkGroup ($groupId, $groupText, $groupCode = "div") {
                // Is a group with that name open?
-               if ($this->ifGroupIsOpened($groupId)) {
+               if ($this->ifGroupOpenedPreviously()) {
                        // Then close it here
-                       $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, $content);
-               }
+                       $this->closePreviousGroupByContent("");
+               } // END - if
+
+               // Generate the group content
+               $content = sprintf("<{$groupCode} id=\"group_%s_%s\">%s",
+                       $this->getLinkName(),
+                       $groupId,
+                       $groupText
+               );
+
+               // Open the new group
+               $this->openGroupByIdContent($groupId, $content, $groupCode);
        }
 
        /**
         * Adds text (note) to the previously opened group or throws an exception
         * if no previous group was opened.
         *
+        * @param       $groupId        Group id to set
         * @param       $groupNote      Note to be added to a group
+        * @param       $groupCode      Code to open and close groups
         * @return      void
         * @throws      NoGroupOpenedException  If no previous group was opened
         */
-       public function addLinkNote ($groupNote) {
+       public function addLinkNote ($groupId, $groupNote, $groupCode = "div") {
                // Check if a previous group was opened
-               if (!$this->ifGroupOpenedPreviously()) {
+               if ($this->ifGroupOpenedPreviously() === false) {
                        // 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);
+               // Is a previous sub group open?
+               if ($this->ifSubGroupOpenedPreviously()) {
+                       // Then close it
+                       $this->closePreviousSubGroupByContent("</{$groupCode}>");
+               } // END - if
+
+               // Generate the group content
+               $content = sprintf("<{$groupCode} id=\"subgroup_%s_%s\">%s",
+                       $this->getLinkName(),
+                       $groupId,
+                       $groupNote
+               );
+
+               // Open the sub group
+               $this->openSubGroupByIdContent($groupId, $content, $groupCode);
        }
 
        /**
@@ -189,33 +223,63 @@ class WebLinkHelper extends BaseWebHelper implements HelpableTemplate {
         */
        public function addActionLink ($linkAction, $linkText) {
                // Check if a previous group was opened
-               if (!$this->ifGroupOpenedPreviously()) {
+               if ($this->ifGroupOpenedPreviously() === false) {
                        // No group was opened before!
-                       throw new NoGroupOpenedException(array($this, $groupNote), self::EXCEPTION_GROUP_NOT_OPENED);
+                       throw new NoGroupOpenedException(array($this, $linkAction."(".$linkText.")"), self::EXCEPTION_GROUP_NOT_OPENED);
                } // END - if
 
                // Default parameter seperator is &amp;
                $seperator = "&amp;";
 
-               // Get link base
-               $linkBase = $this->getLinkBase();
-
                // Is there a question mark in?
-               $linkArray = explode("?", $linkBase);
+               $linkArray = explode("?", $this->getLinkBase());
                if (count($linkArray) == 0) {
                        // No question mark
                        $seperator = "?";
-               }
+               } // END - if
 
-               // Renders the link content
-               $linkContent = sprintf("<a href=\"%s%saction=%s\" title=\"%s\">%s</a>",
-                       $linkBase,
+               // Prepare action
+               $action = sprintf("%saction=%s",
                        $seperator,
-                       $linkAction,
-                       $linkText,
-                       $linkText
+                       $linkAction
                );
 
+               // Renders the link content
+               $linkContent = $this->renderLinkContentWithTextExtraContent($linkText, $action);
+
+               // Add the content to the previous group
+               $this->addContentToPreviousGroup($linkContent);
+       }
+
+       /**
+        * Adds a link to the previously opened group with a text from language system
+        *
+        * @param       $linkAction             Action (action=xxx) value for the link
+        * @param       $languageId             Language id string to use
+        * @return      void
+        */
+       public function addActionLinkById ($linkAction, $languageId) {
+               // Resolve the language string
+               $languageResolved = $this->getLanguageInstance()->getMessage($languageId);
+
+               // Add the action link
+               $this->addActionLink($linkAction, $languageResolved);
+       }
+
+       /**
+        * 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);
+
                // Add the content to the previous group
                $this->addContentToPreviousGroup($linkContent);
        }