X-Git-Url: https://git.mxchange.org/?p=shipsimu.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fhelper%2Fweb%2Fclass_WebFormHelper.php;h=1ec70bca8d5e36c56b75e3030bb2153f6997a80b;hp=43ea97822218276adde87a38717d69b8046a878f;hb=84db68e59426190fdc5b8cd4b4525be88699f570;hpb=cc75d90baeef97069f2285757b9fbb610e9dfcc5 diff --git a/inc/classes/main/helper/web/class_WebFormHelper.php b/inc/classes/main/helper/web/class_WebFormHelper.php index 43ea978..1ec70bc 100644 --- a/inc/classes/main/helper/web/class_WebFormHelper.php +++ b/inc/classes/main/helper/web/class_WebFormHelper.php @@ -48,6 +48,11 @@ class WebFormHelper extends BaseHelper implements HelpableTemplate { */ private $subGroupOpened = false; + /** + * Name of the group + */ + private $groupName = ""; + /** * Name of the sub group */ @@ -182,7 +187,7 @@ class WebFormHelper extends BaseHelper implements HelpableTemplate { // Is a group open? if ($this->groupOpened === true) { // Then automatically close it here - $this->addFormGroup("", ""); + $this->addFormGroup(); } // END - if // Simply close it @@ -404,13 +409,13 @@ class WebFormHelper extends BaseHelper implements HelpableTemplate { /** * Add a form group or close an already opened and open a new one * - * @param $groupName Name of the group + * @param $groupName Name of the group or last opened if empty * @param $groupText Text including HTML to show above this group * @return void * @throws FormClosedException If no form has been opened before * @throws EmptyVariableException If $groupName is not set */ - public function addFormGroup ($groupName, $groupText) { + public function addFormGroup ($groupName = "", $groupText = "") { // Is a form opened? if (($this->formOpened === false) && ($this->formEnabled === true)) { // Throw exception here @@ -421,6 +426,15 @@ class WebFormHelper extends BaseHelper implements HelpableTemplate { if ((empty($groupName)) && ($this->groupOpened === false)) { // Throw exception here throw new EmptyVariableException(array($this, 'groupName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } elseif (empty($groupName)) { + // Close the last opened + $groupName = $this->groupName; + } + + // Same group to open? + if (($this->groupOpened === false) && ($groupName == $this->groupName)) { + // Abort here silently + return false; } // END - if // Initialize content with closing div by default @@ -446,12 +460,13 @@ class WebFormHelper extends BaseHelper implements HelpableTemplate { $this->addContent($content); // Switch the state + $this->groupName = $groupName; $this->groupOpened = true; } else { // Is a sub group opened? if ($this->subGroupOpened === true) { // Close it here - $this->addFormSubGroup("", ""); + $this->addFormSubGroup(); } // END - if // Add the content @@ -472,13 +487,13 @@ class WebFormHelper extends BaseHelper implements HelpableTemplate { * throws an exception if no group has been opened before or if the sub * group name is empty. * - * @param $subGroupName Name of the group + * @param $subGroupName Name of the group or last opened if empty * @param $subGroupText Text including HTML to show above this group * @return void * @throws FormGroupClosedException If no group has been opened before * @throws EmptyVariableException If $subGroupName is not set */ - public function addFormSubGroup ($subGroupName, $subGroupText) { + public function addFormSubGroup ($subGroupName = "", $subGroupText = "") { // Is a group opened? if ($this->groupOpened === false) { // Throw exception here @@ -489,7 +504,10 @@ class WebFormHelper extends BaseHelper implements HelpableTemplate { if ((empty($subGroupName)) && ($this->subGroupOpened === false)) { // Throw exception here throw new EmptyVariableException(array($this, 'groupName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } // END - if + } elseif (empty($subGroupName)) { + // Close the last opened + $subGroupName = $this->subGroupName; + } // Initialize content with closing div by default $content = " \n"; @@ -582,7 +600,7 @@ class WebFormHelper extends BaseHelper implements HelpableTemplate { // Is a group open? if ($this->groupOpened === true) { // Then automatically close it here - $this->addFormGroup("", ""); + $this->addFormGroup(); } // END - if // Generate the content @@ -768,9 +786,18 @@ class WebFormHelper extends BaseHelper implements HelpableTemplate { if (($this->formOpened === true) && ($this->formEnabled === true)) { // Close the form automatically $this->addFormTag(); - } // END - if + } elseif ($this->formEnabled === false) { + if ($this->subGroupOpened === true) { + // Close sub group + $this->addFormSubGroup(); + } elseif ($this->groupOpened === true) { + // Close group + $this->addFormGroup(); + } + } // Send content to template engine + //* DEBUG: */ echo __METHOD__.": form=".$this->getFormName().", size=".strlen($this->getContent())."
\n"; $this->getTemplateInstance()->assignVariable($this->getFormName(), $this->getContent()); } @@ -798,7 +825,7 @@ class WebFormHelper extends BaseHelper implements HelpableTemplate { $extraInstance = Registry::getRegistry()->getInstance('extra'); // Get a configured instance - $captchaInstance = ObjectFactory::createObjectByConfiguredName($this->getFormName()."_captcha", array($this->getTemplateInstance(), $extraInstance)); + $captchaInstance = ObjectFactory::createObjectByConfiguredName($this->getFormName()."_captcha", array($this, $extraInstance)); // Initiate the CAPTCHA $captchaInstance->initiateCaptcha();