From 10f84ee8ec9aa5593f9805201d60c9e28e8df4c4 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 14 Jan 2008 16:01:38 -0500 Subject: [PATCH] Updating the PrinterNavigation system to take an XML structure instead that is much more powerful than the scoped keys of the old version --- PrinterNavigation.php | 208 +++++++++++++++++------------------------- 1 file changed, 86 insertions(+), 122 deletions(-) diff --git a/PrinterNavigation.php b/PrinterNavigation.php index e5dae90..74d5713 100644 --- a/PrinterNavigation.php +++ b/PrinterNavigation.php @@ -41,129 +41,60 @@ class BSPrinterNavigation { /** - * Global links that are used for admin home, logout, etc. - * @var array - */ - private $toplinks = array(); + * XML document structure + * @var SimpleXMLElement + */ + private $structure; /** - * Navigational tabs: array(text, url) - * @var array - */ - private $tabs = array(); + * Keys to set focus on + * @var array + */ + private $focusKeys = array(); /** - * Sections: text - * @var array - */ - private $sections = array(); + * Sections to display + * @var array + */ + private $displaySections = array(); /** - * Links: array(text, url) - * @var array - */ - private $links = array(); - - /** - * Array of scopes to set focus to key - * @var array - */ - private $focus = array('tab' => null, 'link' => null); - - // ################################################################### - /** - * Adds a global link to the array; these cannot be removed once added - * - * @param string Link text - * @param string HREF of the URL - */ - public function addTopLink($text, $href) + * Constructor + * + * @param string Navigation XML data + */ + public function __construct($xml) { - $this->toplinks["$href"] = $text; + $this->structure = new SimpleXMLElement($xml); } - // ################################################################### /** - * Adds to the structure array. The following is the global structure - * of the array, but you can specify any entry point. When you add onto - * the structure, it will go at the bottom - * array( - * 'unique_key' => array( - * '
unique_key' => array( - * 'unique_key' => array('text', 'url') - * ) - * ) - * ) - * - * Note that the portion in brackets is called the "scope" - * - * @param string Scope to add to - * @param string Unique key for the scope - * @param string Parent key to add to - * @param string Text to display (usually localized) - * @param string URL to go to when text is clicked - */ - public function addComponent($scope, $key, $parent, $text, $url) + * Adds focus to a given key + * + * @param string Key + */ + public function addFocus($key) { - if ($scope == 'tab') - { - $this->tabs["$key"] = array($text, $url); - } - else if ($scope == 'section') - { - $this->sections["$parent"]["$key"] = $text; - } - else if ($scope == 'link') - { - $this->links["$parent"]["$key"] = array($text, $url); - } + $this->focusKeys[] = $key; } - // ################################################################### /** - * Sets the focus for either a tab or link - * - * @param string Scope operator - * @param string Unique key in scope - * @param string Parent operator (links only) - */ - public function setFocus($scope, $key, $parent) + * Adds a section to display. The order in which sections are added is the order + * in which they are painted + * + * @param string Key + */ + public function addSection($key) { - if ($scope == 'tab') - { - if (isset($this->tabs["$key"])) - { - $this->focus["$scope"] = $key; - } - else - { - throw new Exception('Invalid key for scope'); - } - } - else if ($scope == 'link') - { - if (isset($this->links["$parent"]["$key"])) - { - $this->focus["$scope"] = $key; - } - else - { - throw new Exception('Invalid key for scope'); - } - } - else - { - throw new Exception('BSPrinterNavigation::setFocus() only allows setting of focus for tab and link scopes'); - } + $this->displaySections[] = $key; } - - // ################################################################### + /** - * Generates the header HTML that is called in BSPrinterRootElementPage - * to setup the navigation frame - * - * @return string Generated HTML content - */ + * Generates the header HTML that is called in BSPrinterRootElementPage + * to setup the navigation frame + * + * @return string Generated HTML content + */ public function constructHeaderHtml() { $output = '' . "\n\n"; @@ -171,9 +102,10 @@ class BSPrinterNavigation // ------------------------------------------------------------------- $output2 = array(); - foreach ($this->toplinks AS $href => $text) + foreach ($this->structure->links->link as $link) { - $output2[] = '' . $text . ''; + $attrs = $link->attributes(); + $output2[] = '' . $link . ''; } $output .= "\n" . '