]> git.mxchange.org Git - core.git/blobdiff - inc/classes/main/helper/web/links/class_WebLinkHelper.php
Some API changes:
[core.git] / inc / classes / main / helper / web / links / class_WebLinkHelper.php
index fa0d9a2bfad0c024d6d3a4070681c5e92dc2a5f4..9ed903767de675027dc0f3dc06dc058f6ee45246 100644 (file)
@@ -2,11 +2,11 @@
 /**
  * A helper for web links
  *
- * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2013 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.org
+ * @link               http://www.shipsimu.org
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -33,14 +33,14 @@ class WebLinkHelper extends BaseWebHelper implements HelpableTemplate {
        private $linkBase = '';
 
        /**
-        * First parameter seperator
+        * First parameter separator
         */
-       private $firstParameter = '?';
+       const FIRST_PARAMETER_SEPARATOR = '?';
 
        /**
-        * Seperator for more paraemters
+        * SEPARATOR for more paraemters
         */
-       private $parameterSeperator = '&amp;';
+       const EXTRA_PARAMETER_SEPARATOR = '&amp;';
 
        /**
         * Protected constructor
@@ -59,10 +59,9 @@ class WebLinkHelper extends BaseWebHelper implements HelpableTemplate {
         * @param       $linkName                       Name of the link we shall generate
         * @param       $linkBase                       Link base for the link. This parameter is deprecated.
         * @return      $helperInstance         A prepared instance of this helper
-        * @throws      NullPointerException    Thrown if an instance is null
-        * @throws      ConfigEntryNotFoundException    A deprecated exception at this point
+        * @throws      NoConfigEntryException  A deprecated exception at this point
         */
-       public final static function createWebLinkHelper (CompileableTemplate $templateInstance, $linkName, $linkBase = null) {
+       public static final function createWebLinkHelper (CompileableTemplate $templateInstance, $linkName, $linkBase = NULL) {
                // Get new instance
                $helperInstance = new WebLinkHelper();
 
@@ -75,12 +74,6 @@ class WebLinkHelper extends BaseWebHelper implements HelpableTemplate {
                // Get the application instance
                $applicationInstance = Registry::getRegistry()->getInstance('application');
 
-               // Sanity-check on it
-               if (is_null($applicationInstance)) {
-                       // Throw an exception here
-                       throw new NullPointerException($helperInstance, self::EXCEPTION_IS_NULL_POINTER);
-               } // END - if
-
                // Get the request instance
                $requestInstance = $applicationInstance->getRequestInstance();
 
@@ -94,23 +87,23 @@ class WebLinkHelper extends BaseWebHelper implements HelpableTemplate {
                $page = $helperInstance->convertDashesToUnderscores($requestInstance->getRequestElement('page'));
 
                // Construct config entry
-               $configEntry = $page . '_' . $linkName;
+               $configEntry = $page . '_' . $linkName . '_action_url';
 
                // Is the deprecated parameter set?
                if (!is_null($linkBase)) {
                        // Then output a deprecation message
-                       $helperInstance->deprecationWarning(__METHOD__ . ': linkBase is deprecated. Please remove it from your templates and add a config entry ' . $configEntry . ' in your config.php file.');
+                       $helperInstance->deprecationWarning('[' . __METHOD__ . ':' . __LINE__ . ']:  linkBase is deprecated. Please remove it from your templates and add a config entry ' . $configEntry . ' in your config.php file.');
                } // END - if
 
                // Determine link base from config now and 'page' request
                try {
                        $newLinkBase = $helperInstance->getConfigInstance()->getConfigEntry($configEntry);
                        $linkBase = $newLinkBase;
-               } catch (ConfigEntryNotFoundException $e) {
+               } catch (NoConfigEntryException $e) {
                        // Is the deprecated linkBase not set?
                        if (is_null($linkBase)) {
                                // Then throw again the exception
-                               throw new ConfigEntryNotFoundException(array(__CLASS__, ($configEntry)), self::EXCEPTION_CONFIG_ENTRY_WAS_NOT_FOUND);
+                               throw new NoConfigEntryException(array(__CLASS__, ($configEntry)), FrameworkConfiguration::EXCEPTION_CONFIG_ENTRY_WAS_NOT_FOUND);
                        } // END - if
                }
 
@@ -246,7 +239,7 @@ class WebLinkHelper extends BaseWebHelper implements HelpableTemplate {
         */
        public function addLinkNote ($groupId, $groupNote, $groupCode = "div") {
                // Check if a previous group was opened
-               if ($this->ifGroupOpenedPreviously() === false) {
+               if ($this->ifGroupOpenedPreviously() === FALSE) {
                        // No group was opened before!
                        throw new NoGroupOpenedException(array($this, $groupNote), self::EXCEPTION_GROUP_NOT_OPENED);
                } // END - if
@@ -278,24 +271,24 @@ class WebLinkHelper extends BaseWebHelper implements HelpableTemplate {
         */
        protected function addActionLink ($linkAction, $linkText, $linkTitle) {
                // Check if a previous group was opened
-               if ($this->ifGroupOpenedPreviously() === false) {
+               if ($this->ifGroupOpenedPreviously() === FALSE) {
                        // 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 = $this->parameterSeperator;
+               // Default parameter SEPARATOR is &amp;
+               $separator = self::EXTRA_PARAMETER_SEPARATOR;
 
                // Is there a question mark in?
-               $linkArray = explode($this->firstParameter, $this->getLinkBase());
+               $linkArray = explode(self::FIRST_PARAMETER_SEPARATOR, $this->getLinkBase());
                if (count($linkArray) == 0) {
                        // No question mark
-                       $seperator = $this->firstParameter;
+                       $separator = self::FIRST_PARAMETER_SEPARATOR;
                } // END - if
 
                // Prepare action
-               $action = sprintf("%saction=%s",
-                       $seperator,
+               $action = sprintf('%saction=%s',
+                       $separator,
                        $linkAction
                );