* @version 0.0.0
* @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
class WebLinkHelper extends BaseWebHelper implements HelpableTemplate {
/**
* Name of the link
*/
private $linkName = "";
/**
* Base of the link
*/
private $linkBase = "";
/**
* Protected constructor
*
* @return void
*/
protected function __construct () {
// Call parent constructor
parent::__construct(__CLASS__);
}
/**
* Creates the helper class
*
* @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
* @return $helperInstance A prepared instance of this helper
*/
public final static function createWebLinkHelper (CompileableTemplate $templateInstance, $linkName, $linkBase) {
// Get new instance
$helperInstance = new WebLinkHelper();
// Set template instance
$helperInstance->setTemplateInstance($templateInstance);
// Set link name
$helperInstance->setLinkName($linkName);
// Set link base
$helperInstance->setLinkBase($linkBase);
// Return the prepared instance
return $helperInstance;
}
/**
* Setter for link name
*
* @param $linkName Name of the link we shall generate
* @return void
*/
protected final function setLinkName ($linkName) {
$this->linkName = (string) $linkName;
}
/**
* Getter for link name
*
* @return $linkName Name of the link we shall generate
*/
public final function getLinkName () {
return $this->linkName;
}
/**
* Setter for link base
*
* @param $linkBase Base of the link we shall generate
* @return void
*/
protected final function setLinkBase ($linkBase) {
$this->linkBase = (string) $linkBase;
}
/**
* Getter for link base
*
* @return $linkBase Base of the link we shall generate
*/
public final function getLinkBase () {
return $this->linkBase;
}
/**
* Flush the content out,e g. to a template variable
*
* @return void
* @todo Completely unimplemented
*/
public function flushContent () {
// Is a previous opened group still open?
if ($this->ifGroupOpenedPreviously()) {
// Then close it
$this->closePreviousGroupByContent("");
} // END - if
// Get the content
$content = $this->renderContent();
// Get template engine
$templateInstance = $this->getTemplateInstance();
// Add content to variable
$templateInstance->assignVariable($this->getLinkName(), $content);
}
/**
* Adds a link group (like the form group is) with some raw language to the
* helper.
*
* @param $groupId Id string of the group
* @param $groupText Text for this group to add
* @return void
*/
public function addLinkGroup ($groupId, $groupText) {
// Is a group with that name open?
if ($this->ifGroupIsOpened($groupId)) {
// Then close it here
$this->closePreviousGroupByContent("");
} else {
// Is a previous opened group still open?
if ($this->ifGroupOpenedPreviously()) {
// Then close it
$this->closePreviousGroupByContent("");
} // END - if
// Generate the group content
$content = sprintf("
%s",
$this->getLinkName(),
$groupId,
$groupText
);
// Open the new group
$this->openGroupByIdContent($groupId, $content);
}
}
/**
* Adds text (note) to the previously opened group or throws an exception
* if no previous group was opened.
*
* @param $groupNote Note to be added to a group
* @return void
* @throws NoGroupOpenedException If no previous group was opened
*/
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, $groupNote), self::EXCEPTION_GROUP_NOT_OPENED);
} // END - if
// Default parameter seperator is &
$seperator = "&";
// Get link base
$linkBase = $this->getLinkBase();
// Is there a question mark in?
$linkArray = explode("?", $linkBase);
if (count($linkArray) == 0) {
// No question mark
$seperator = "?";
}
// Renders the link content
$linkContent = sprintf("
%s",
$linkBase,
$seperator,
$linkAction,
$linkText,
$linkText
);
// Add the content to the previous group
$this->addContentToPreviousGroup($linkContent);
}
}
// [EOF]
?>