*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
/**
* Name of the link
*/
- private $linkName = "";
+ private $linkName = '';
/**
* Base of the link
*/
- private $linkBase = "";
+ private $linkBase = '';
+
+ /**
+ * First parameter seperator
+ */
+ private $firstParameter = '?';
+
+ /**
+ * Seperator for more paraemters
+ */
+ private $parameterSeperator = '&';
/**
* Protected constructor
*
* @param $templateInstance An instance of a template engine
* @param $linkName Name of the link we shall generate
- * @param $linkBase Link base for all generated links
+ * @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
*/
- public final static function createWebLinkHelper (CompileableTemplate $templateInstance, $linkName, $linkBase) {
+ public final static function createWebLinkHelper (CompileableTemplate $templateInstance, $linkName, $linkBase = null) {
// Get new instance
$helperInstance = new WebLinkHelper();
// Set link name
$helperInstance->setLinkName($linkName);
+ // 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();
+
+ // Sanity-check on it
+ if (is_null($requestInstance)) {
+ // Throw an exception here
+ throw new NullPointerException($helperInstance, self::EXCEPTION_IS_NULL_POINTER);
+ } // END - if
+
+ // Get page (this will throw an exception if not set)
+ $page = $helperInstance->convertDashesToUnderscores($requestInstance->getRequestElement('page'));
+
+ // Construct config entry
+ $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.');
+ } // END - if
+
+ // Determine link base from config now and 'page' request
+ try {
+ $newLinkBase = $helperInstance->getConfigInstance()->getConfigEntry($configEntry);
+ $linkBase = $newLinkBase;
+ } catch (ConfigEntryNotFoundException $e) {
+ // Is the deprecated linkBase not set?
+ if (is_null($linkBase)) {
+ // Then throw again the exception
+ throw new ConfigEntryNotFoundException(array(__CLASS__, ($configEntry)), FrameworkConfiguration::EXCEPTION_CONFIG_ENTRY_WAS_NOT_FOUND);
+ } // END - if
+ }
+
// Set link base
$helperInstance->setLinkBase($linkBase);
// Add default group
- $helperInstance->openGroupByIdContent('main', "", "");
+ $helperInstance->openGroupByIdContent('main', '', '');
// Return the prepared instance
return $helperInstance;
* extra content
*
* @param $linkText Link text to set in link
+ * @param $linkTitle Link title to set in link
* @param $extraContent Optional extra HTML content
* @return $linkContent Rendered text link content
*/
- private function renderLinkContentWithTextExtraContent ($linkText, $extraContent="") {
+ private function renderLinkContentWithTextExtraContent ($linkText, $linkTitle, $extraContent='') {
// Construct link content
$linkContent = sprintf("<a href=\"%s%s\" title=\"%s\">%s</a>",
$this->getLinkBase(),
$extraContent,
- $linkText,
+ $linkTitle,
$linkText
);
// Is a previous opened group still open?
if ($this->ifGroupOpenedPreviously()) {
// Then close it
- $this->closePreviousGroupByContent("");
+ $this->closePreviousGroupByContent('');
} // END - if
// Get the content
// Is a group with that name open?
if ($this->ifGroupOpenedPreviously()) {
// Then close it here
- $this->closePreviousGroupByContent("");
+ $this->closePreviousGroupByContent('');
} // END - if
// Generate the group content
* @return void
* @throws NoGroupOpenedException If no previous group was opened
*/
- public function addActionLink ($linkAction, $linkText) {
+ protected function addActionLink ($linkAction, $linkText, $linkTitle) {
// Check if a previous group was opened
if ($this->ifGroupOpenedPreviously() === false) {
// No group was opened before!
- throw new NoGroupOpenedException(array($this, $linkAction."(".$linkText.")"), self::EXCEPTION_GROUP_NOT_OPENED);
+ throw new NoGroupOpenedException(array($this, $linkAction . '(' . $linkText . ')'), self::EXCEPTION_GROUP_NOT_OPENED);
} // END - if
// Default parameter seperator is &
- $seperator = "&";
+ $seperator = $this->parameterSeperator;
// Is there a question mark in?
- $linkArray = explode("?", $this->getLinkBase());
+ $linkArray = explode($this->firstParameter, $this->getLinkBase());
if (count($linkArray) == 0) {
// No question mark
- $seperator = "?";
+ $seperator = $this->firstParameter;
} // END - if
// Prepare action
);
// Renders the link content
- $linkContent = $this->renderLinkContentWithTextExtraContent($linkText, $action);
+ $linkContent = $this->renderLinkContentWithTextExtraContent($linkText, $linkTitle, $action);
// Add the content to the previous group
$this->addContentToPreviousGroup($linkContent);
*/
public function addActionLinkById ($linkAction, $languageId) {
// Resolve the language string
- $languageResolved = $this->getLanguageInstance()->getMessage($languageId);
+ $languageResolvedText = $this->getLanguageInstance()->getMessage("link_" . $languageId . "_text");
+
+ // Resolve the language string
+ $languageResolvedTitle = $this->getLanguageInstance()->getMessage("link_" . $languageId . "_title");
// Add the action link
- $this->addActionLink($linkAction, $languageResolved);
+ $this->addActionLink($linkAction, $languageResolvedText, $languageResolvedTitle);
}
/**
*/
public function addLinkWithTextById ($languageId) {
// Resolve the language string
- $languageResolved = $this->getLanguageInstance()->getMessage($languageId);
+ $languageResolvedText = $this->getLanguageInstance()->getMessage("link_" . $languageId . "_text");
+
+ // Resolve the language string
+ $languageResolvedTitle = $this->getLanguageInstance()->getMessage("link_" . $languageId . "_title");
// Now add the link
- $linkContent = $this->renderLinkContentWithTextExtraContent($languageResolved);
+ $linkContent = $this->renderLinkContentWithTextExtraContent($languageResolvedText, $languageResolvedTitle);
// Add the content to the previous group
$this->addContentToPreviousGroup($linkContent);