*
* @param $groupId Group id to open
* @param $content Initial content to add to the group
+ * @param $tag HTML tag used to open this group
* @return void
* @throws HelperGroupAlreadyCreatedException If the group was already created before
*/
- protected function openGroupByIdContent ($groupId, $content) {
- //* DEBUG: */ echo "OPEN:groupId={$groupId}<br />\n";
+ protected function openGroupByIdContent ($groupId, $content, $tag) {
+ //* DEBUG: */ echo "OPEN:groupId={$groupId},content=<pre>".htmlentities($content)."</pre>\n";
// Is the group already there?
if (isset($this->groups[$groupId])) {
// Then throw an exception here
// Add the group to the stack
$this->groups[$this->totalCounter] = $groupId;
$this->groups[$groupId]['opened'] = true;
- $this->groups[$groupId]['content'] = $content."\n";
+ $this->groups[$groupId]['content'] = sprintf("<!-- group %s opened (length: %s, tag: %s) //-->%s\n", $groupId, strlen($content), $tag, $content);
+ $this->groups[$groupId]['tag'] = $tag;
// Mark this group as previously opened
$this->setPreviousGroupId($groupId);
* Closes the previously opened group by added given content to it or
* throws an exception if no previous group was opened
*
- * @param $content Content for previously opened grouop
+ * @param $content Content for previously opened group, or empty to use tag of opener
* @return void
* @throws HelperNoPreviousOpenedGroupException If no previously opened group was found
*/
- public function closePreviousGroupByContent ($content) {
+ public function closePreviousGroupByContent ($content = "") {
+ // Check if any sub group was opened before
+ if ($this->ifSubGroupOpenedPreviously()) {
+ // Close it automatically
+ $this->closePreviousSubGroupByContent();
+ } // END - if
+
// Check if any group was opened before
- if (!$this->ifGroupOpenedPreviously()) {
+ if ($this->ifGroupOpenedPreviously() === false) {
// Then throw an exception
throw new HelperNoPreviousOpenedGroupException(array($this, $content), self::EXCEPTION_NO_PREVIOUS_SUB_GROUP_OPENED);
} // END - if
// Get previous group
$groupId = $this->getPreviousGroupId();
+ // Is the content empty?
+ if ((empty($content)) && (!empty($this->groups[$groupId]['tag']))) {
+ // Get it from opener
+ $content = sprintf("<!-- group %s auto-closed //--></%s>", $groupId, $this->groups[$groupId]['tag']);
+ } // END - if
+
// Add content to it and mark it as closed
- $this->groups[$groupId]['content'] .= $content."\n";
+ $this->groups[$groupId]['content'] .= sprintf("<!-- group %s closed (length: %s, tag: %s) //-->%s\n", $groupId, strlen($content), $this->groups[$groupId]['tag'], $content);
$this->groups[$groupId]['opened'] = false;
// Mark previous group as closed
*
* @param $subGroupId Sub group id to open
* @param $content Initial content to add to the sub group
+ * @param $tag HTML tag used to open this group
* @return void
* @throws HelperSubGroupAlreadyCreatedException If the sub group was already created before
*/
- protected function openSubGroupByIdContent ($subGroupId, $content) {
+ protected function openSubGroupByIdContent ($subGroupId, $content, $tag) {
//* DEBUG: */ echo "OPEN:subGroupId={$subGroupId},content=".htmlentities($content)."<br />\n";
// Is the group already there?
if (isset($this->subGroups[$subGroupId])) {
// Add the group to the stack
$this->subGroups[$this->totalCounter] = $subGroupId;
$this->subGroups[$subGroupId]['opened'] = true;
- $this->subGroups[$subGroupId]['content'] = $content."\n";
+ $this->subGroups[$subGroupId]['content'] = sprintf("<!-- sub-group %s opened (length: %s, tag: %s) //-->%s\n", $subGroupId, strlen($content), $tag, $content);
+ $this->subGroups[$subGroupId]['tag'] = $tag;
// Mark this group as previously opened
$this->setPreviousSubGroupId($subGroupId);
* Closes the previously opened sub group by added given content to it or
* throws an exception if no previous sub group was opened
*
- * @param $content Content for previously opened sub grouop
+ * @param $content Content for previously opened sub group, or leave empty to use div/span of openener
* @return void
* @throws HelperNoPreviousOpenedSubGroupException If no previously opened sub group was found
*/
- public function closePreviousSubGroupByContent ($content) {
+ public function closePreviousSubGroupByContent ($content = "") {
// Check if any sub group was opened before
- if (!$this->ifSubGroupOpenedPreviously()) {
+ if ($this->ifSubGroupOpenedPreviously() === false) {
// Then throw an exception
throw new HelperNoPreviousOpenedSubGroupException(array($this, $content), self::EXCEPTION_NO_PREVIOUS_SUB_GROUP_OPENED);
} // END - if
// Get previous sub group
$subGroupId = $this->getPreviousSubGroupId();
+ // Is the content empty?
+ if ((empty($content)) && (!empty($this->subGroups[$subGroupId]['tag']))) {
+ // Get it from opener
+ $content = sprintf("<!-- sub-group %s auto-closed //--></%s>", $subGroupId, $this->subGroups[$subGroupId]['tag']);
+ } // END - if
+
// Add content to it and mark it as closed
- $this->subGroups[$subGroupId]['content'] .= $content."\n";
+ $this->subGroups[$subGroupId]['content'] .= sprintf("<!-- sub-group %s closed (length: %s, tag: %s) //-->%s\n", $subGroupId, strlen($content), $this->subGroups[$subGroupId]['tag'], $content);
$this->subGroups[$subGroupId]['opened'] = false;
// Mark previous sub group as closed
// Is this a group and is it closed?
if ((isset($this->groups[$idx])) && ($this->groups[$this->groups[$idx]]['opened'] === false)) {
// Then add it's content
- $groupContent = $this->groups[$this->groups[$idx]]['content'];
+ $groupContent = trim($this->groups[$this->groups[$idx]]['content']);
//* DEBUG: */ echo "group={$this->groups[$idx]},content=<pre>".htmlentities($groupContent)."</pre><br />\n";
$content .= $groupContent;
} elseif ((isset($this->subGroups[$idx])) && ($this->subGroups[$this->subGroups[$idx]]['opened'] === false)) {
// Then add it's content
$subGroupContent = $this->subGroups[$this->subGroups[$idx]]['content'];
//* DEBUG: */ echo "subgroup={$this->subGroups[$idx]},content=<pre>".htmlentities($subGroupContent)."</pre><br />\n";
- $content .= $subGroupContent;
+ $content .= trim($subGroupContent);
} else {
// Something went wrong
- $this->debugInstance();
+ $this->debugInstance(__METHOD__."(): Something unexpected happened here.");
}
-
} // END - for
// Is footer content there?