class_WebLinkHelper.php
Go to the documentation of this file.00001 <?php
00024 class WebLinkHelper extends BaseWebHelper implements HelpableTemplate {
00028 private $linkName = "";
00029
00033 private $linkBase = "";
00034
00040 protected function __construct () {
00041
00042 parent::__construct(__CLASS__);
00043 }
00044
00053 public final static function createWebLinkHelper (CompileableTemplate $templateInstance, $linkName, $linkBase) {
00054
00055 $helperInstance = new WebLinkHelper();
00056
00057
00058 $helperInstance->setTemplateInstance($templateInstance);
00059
00060
00061 $helperInstance->setLinkName($linkName);
00062
00063
00064 $helperInstance->setLinkBase($linkBase);
00065
00066
00067 $helperInstance->openGroupByIdContent('main', "", "");
00068
00069
00070 return $helperInstance;
00071 }
00072
00082 private function renderLinkContentWithTextExtraContent ($linkText, $linkTitle, $extraContent="") {
00083
00084 $linkContent = sprintf("<a href=\"%s%s\" title=\"%s\">%s</a>",
00085 $this->getLinkBase(),
00086 $extraContent,
00087 $linkTitle,
00088 $linkText
00089 );
00090
00091
00092 return $linkContent;
00093 }
00094
00101 protected final function setLinkName ($linkName) {
00102 $this->linkName = (string) $linkName;
00103 }
00104
00110 public final function getLinkName () {
00111 return $this->linkName;
00112 }
00113
00120 protected final function setLinkBase ($linkBase) {
00121 $this->linkBase = (string) $linkBase;
00122 }
00123
00129 public final function getLinkBase () {
00130 return $this->linkBase;
00131 }
00132
00139 public function flushContent () {
00140
00141 if ($this->ifGroupOpenedPreviously()) {
00142
00143 $this->closePreviousGroupByContent("");
00144 }
00145
00146
00147 $content = $this->renderContent();
00148
00149
00150 $templateInstance = $this->getTemplateInstance();
00151
00152
00153 $templateInstance->assignVariable($this->getLinkName(), $content);
00154 }
00155
00165 public function addLinkGroup ($groupId, $groupText, $groupCode = "div") {
00166
00167 if ($this->ifGroupOpenedPreviously()) {
00168
00169 $this->closePreviousGroupByContent("");
00170 }
00171
00172
00173 $content = sprintf("<{$groupCode} id=\"group_%s_%s\">%s",
00174 $this->getLinkName(),
00175 $groupId,
00176 $groupText
00177 );
00178
00179
00180 $this->openGroupByIdContent($groupId, $content, $groupCode);
00181 }
00182
00193 public function addLinkNote ($groupId, $groupNote, $groupCode = "div") {
00194
00195 if ($this->ifGroupOpenedPreviously() === false) {
00196
00197 throw new NoGroupOpenedException(array($this, $groupNote), self::EXCEPTION_GROUP_NOT_OPENED);
00198 }
00199
00200
00201 if ($this->ifSubGroupOpenedPreviously()) {
00202
00203 $this->closePreviousSubGroupByContent("</{$groupCode}>");
00204 }
00205
00206
00207 $content = sprintf("<{$groupCode} id=\"subgroup_%s_%s\">%s",
00208 $this->getLinkName(),
00209 $groupId,
00210 $groupNote
00211 );
00212
00213
00214 $this->openSubGroupByIdContent($groupId, $content, $groupCode);
00215 }
00216
00225 protected function addActionLink ($linkAction, $linkText, $linkTitle) {
00226
00227 if ($this->ifGroupOpenedPreviously() === false) {
00228
00229 throw new NoGroupOpenedException(array($this, $linkAction."(".$linkText.")"), self::EXCEPTION_GROUP_NOT_OPENED);
00230 }
00231
00232
00233 $seperator = "&";
00234
00235
00236 $linkArray = explode("?", $this->getLinkBase());
00237 if (count($linkArray) == 0) {
00238
00239 $seperator = "?";
00240 }
00241
00242
00243 $action = sprintf("%saction=%s",
00244 $seperator,
00245 $linkAction
00246 );
00247
00248
00249 $linkContent = $this->renderLinkContentWithTextExtraContent($linkText, $linkTitle, $action);
00250
00251
00252 $this->addContentToPreviousGroup($linkContent);
00253 }
00254
00262 public function addActionLinkById ($linkAction, $languageId) {
00263
00264 $languageResolvedText = $this->getLanguageInstance()->getMessage("link_" . $languageId . "_text");
00265
00266
00267 $languageResolvedTitle = $this->getLanguageInstance()->getMessage("link_" . $languageId . "_title");
00268
00269
00270 $this->addActionLink($linkAction, $languageResolvedText, $languageResolvedTitle);
00271 }
00272
00280 public function addLinkWithTextById ($languageId) {
00281
00282 $languageResolvedText = $this->getLanguageInstance()->getMessage("link_" . $languageId . "_text");
00283
00284
00285 $languageResolvedTitle = $this->getLanguageInstance()->getMessage("link_" . $languageId . "_title");
00286
00287
00288 $linkContent = $this->renderLinkContentWithTextExtraContent($languageResolvedText, $languageResolvedTitle);
00289
00290
00291 $this->addContentToPreviousGroup($linkContent);
00292 }
00293 }
00294
00295
00296 ?>