private $content = "";
/**
- * Wether the group is opened or not
+ * Array with groups
*/
- private $groupOpened = false;
+ private $groups = array();
/**
- * Wether the sub group is opened or not
+ * Array with sub group
*/
- private $subGroupOpened = false;
-
- /**
- * Name of the group
- */
- private $groupName = "";
-
- /**
- * Name of the sub group
- */
- private $subGroupId = "";
+ private $subGroups = array();
/**
* Previously opened group
*/
private $previousSubGroupId = "";
+ /**
+ * Total counter for groups and sub groups
+ */
+ private $totalCounter = 0;
+
// Exception constants
- const EXCEPTION_XML_PARSER_ERROR = 0x1e0;
- const EXCEPTION_XML_NODE_UNKNOWN = 0x1e1;
- const EXCEPTION_XML_NODE_MISMATCH = 0x1e2;
- const EXCEPTION_GROUP_NOT_OPENED = 0x1e3;
+ const EXCEPTION_XML_PARSER_ERROR = 0x1e0;
+ const EXCEPTION_XML_NODE_UNKNOWN = 0x1e1;
+ const EXCEPTION_XML_NODE_MISMATCH = 0x1e2;
+ const EXCEPTION_GROUP_NOT_OPENED = 0x1e3;
+ const EXCEPTION_GROUP_ALREADY_FOUND = 0x1e4;
+ const EXCEPTION_SUB_GROUP_ALREADY_FOUND = 0x1e5;
+ const EXCEPTION_NO_PREVIOUS_SUB_GROUP_OPENED = 0x1e6;
+ const EXCEPTION_NO_PREVIOUS_GROUP_OPENED = 0x1e7;
/**
* Protected constructor
// Get the required instance
$this->valueInstance = Registry::getRegistry()->getInstance($registryKey);
- // Is the instance valid?
+ // Is the value instance valid?
if (is_null($this->valueInstance)) {
// Try to create it "from scratch", by first init extra instance
$extraInstance = null;
} // END - if
}
+ /**
+ * Opens a helper group with given group id and content or throws an
+ * exception if that group is already found regardless if it is open or
+ * closed.
+ *
+ * @param $groupId Group id to open
+ * @param $content Initial content to add to the group
+ * @return void
+ * @throws HelperGroupAlreadyCreatedException If the group was already created before
+ */
+ protected function openGroupByIdContent ($groupId, $content) {
+ //* DEBUG: */ echo "OPEN:groupId={$groupId}<br />\n";
+ // Is the group already there?
+ if (isset($this->groups[$groupId])) {
+ // Then throw an exception here
+ $this->debugBackTrace();
+ throw new HelperGroupAlreadyCreatedException(array($this, $groupId), self::EXCEPTION_GROUP_ALREADY_FOUND);
+ } // END - if
+
+ // Count one up
+ $this->totalCounter++;
+
+ // Add the group to the stack
+ $this->groups[$this->totalCounter] = $groupId;
+ $this->groups[$groupId]['opened'] = true;
+ $this->groups[$groupId]['content'] = $content."\n";
+
+ // 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
+ * @return void
+ * @throws HelperNoPreviousOpenedGroupException If no previously opened group was found
+ */
+ public function closePreviousGroupByContent ($content) {
+ // Check if any group was opened before
+ if (!$this->ifGroupOpenedPreviously()) {
+ // 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();
+
+ // Add content to it and mark it as closed
+ $this->groups[$groupId]['content'] .= $content."\n";
+ $this->groups[$groupId]['opened'] = false;
+
+ // Mark previous group as closed
+ $this->setPreviousGroupId("");
+ //* DEBUG: */ echo "CLOSE:groupId={$groupId}<br />\n";
+ }
+
+ /**
+ * Opens a helper sub group with given group id and content or throws an
+ * exception if that sub group is already found regardless if it is open or
+ * closed.
+ *
+ * @param $subGroupId Sub group id to open
+ * @param $content Initial content to add to the sub group
+ * @return void
+ * @throws HelperSubGroupAlreadyCreatedException If the sub group was already created before
+ */
+ protected function openSubGroupByIdContent ($subGroupId, $content) {
+ //* DEBUG: */ echo "OPEN:subGroupId={$subGroupId},content=".htmlentities($content)."<br />\n";
+ // Is the group already there?
+ if (isset($this->subGroups[$subGroupId])) {
+ // Then throw an exception here
+ throw new HelperSubGroupAlreadyCreatedException(array($this, $subGroupId), self::EXCEPTION_SUB_GROUP_ALREADY_FOUND);
+ } // END - if
+
+ // Count one up
+ $this->totalCounter++;
+
+ // Add the group to the stack
+ $this->subGroups[$this->totalCounter] = $subGroupId;
+ $this->subGroups[$subGroupId]['opened'] = true;
+ $this->subGroups[$subGroupId]['content'] = $content."\n";
+
+ // 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
+ * @return void
+ * @throws HelperNoPreviousOpenedSubGroupException If no previously opened sub group was found
+ */
+ public function closePreviousSubGroupByContent ($content) {
+ // Check if any sub group was opened before
+ if (!$this->ifSubGroupOpenedPreviously()) {
+ // 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();
+
+ // Add content to it and mark it as closed
+ $this->subGroups[$subGroupId]['content'] .= $content."\n";
+ $this->subGroups[$subGroupId]['opened'] = false;
+
+ // Mark previous sub group as closed
+ $this->setPreviousSubGroupId("");
+ //* DEBUG: */ echo "CLOSE:subGroupId={$subGroupId}<br />\n";
+ }
+
+ /**
+ * Renders all group and sub group in their order
+ *
+ * @return $content Rendered HTML content
+ */
+ public function renderContent () {
+ // Initiate content
+ $content = $this->getContent();
+
+ // Now "walk" through all groups and sub-groups
+ for ($idx = 1; $idx <= $this->totalCounter; $idx++) {
+ // 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
+ $content .= $this->groups[$this->groups[$idx]]['content'];
+ } elseif ((isset($this->subGroups[$idx])) && ($this->subGroups[$this->subGroups[$idx]]['opened'] === false)) {
+ // Then add it's content
+ $content .= $this->subGroups[$this->subGroups[$idx]]['content'];
+ } else {
+ // Something went wrong
+ die("GROUP/SUB GROUP ERROR: {$idx}");
+ }
+
+ } // END - for
+
+ // Return it
+ return $content;
+ }
+
/**
* Getter for direct field values
*
/**
* Getter for previous sub group id
*
- * @return $previousSubGroupId Id of previously opened sub group
+ * @return $previousSubGroupId Id of previously opened sub group
*/
protected final function getPreviousSubGroupId () {
return $this->previousSubGroupId;
/**
* Setter for previous sub group id
*
- * @param $previousSubGroupId Id of previously opened sub group
+ * @param $previousSubGroupId Id of previously opened sub group
* @return void
*/
protected final function setPreviousSubGroupId ($previousSubGroupId) {