From ead75b4299620f752e5e6d94ae4c2f6325af7dea Mon Sep 17 00:00:00 2001 From: michael Date: Mon, 6 Jan 2003 12:15:19 +0000 Subject: [PATCH] finished and tested sitemap implementation --- lib/SiteMap.inc | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 77 insertions(+), 16 deletions(-) diff --git a/lib/SiteMap.inc b/lib/SiteMap.inc index c1c9ed0..fa3d81a 100644 --- a/lib/SiteMap.inc +++ b/lib/SiteMap.inc @@ -8,10 +8,23 @@ * @author michael@jamwarehouse.com * @package dms */ + class SiteMap { /** - * Adds a site mapping entry. + * The underlying site map storage array + */ + var $siteMapArray; + + /** + * Constructs a new SiteMap, initialising the array. + */ + function SiteMap() { + $this->siteMapArray = array(); + } + + /** + * Adds a site page mapping entry. * * @param $action * the controller action @@ -22,11 +35,44 @@ class SiteMap { * @param $userClass * the user class with access to this page */ - function addMap($action, $page, $sectionName, $userClass) { - global $default; - - $realAction = $_ACTIONS[$action]; - // add to map impl. + function addPage($action, $page, $sectionName, $userClass) { + // add to map + $this->siteMapArray[$sectionName][$userClass][$action] = $page; + } + + /** + * Returns the page mapped to the action, userClass pair. + * + * @param $action + * the action to lookup pages for + * @param $userClass + * the userclass to perform page level validation against + * @return + * the page to redirect to, or false if the user class doesn't + * have access to the page + */ + function getPage($action, $userClass) { + // TODO: need to accomodate SA having all the access of the userclasses below it + // map incoming userClass to number + $uc = constant($userClass); + echo "userclass = $userClass; uc=$uc\n"; + // iterate through multidim sitemap array + foreach ($this->siteMapArray as $section => $valArr) { + foreach ($valArr as $userAccess => $pageArr) { + echo "userAccess=($userAccess)" . constant($userAccess) . "; uc=$uc\n"; + if ($uc <= constant($userAccess)) { + // now loop through pages until we find the right one + foreach ($pageArr as $ackshin => $page) { + if ($ackshin == $action) { + return $page; + } + } + } + } + } + // if the function hasn't returned already then the specified + // userClass does not have access to the action + return false; } /** @@ -41,20 +87,35 @@ class SiteMap { * an array containing the actions for the specified section */ function getSection($sectionName, $userClass) { + // check if the section exists + if (is_array($this->siteMapArray[$sectionName])) { + // initialise result array + $results = array(); + // need to loop through all user class arrays in this section + foreach ($this->siteMapArray[$sectionName] as $uc => $pages) { + if (constant($userClass) <= constant($uc)) { + // add this array to the resultset array + $results = array_merge($results, $this->siteMapArray[$sectionName][$uc]); + } + } + // now check if we have anything in the results array before returning it + if (count($results) > 0) { + return $results; + } else { + return false; + } + } else { + // supplied section not in sitemap + // TODO: internal error code? + return false; + } } /** - * Returns the page mapped to the action, userClass pair. - * - * @param $action - * the action to lookup pages for - * @param $userClass - * the userclass to perform page level validation against - * @return - * the page to redirect to, or false if the user class doesn't - * have access to the page + * Prints the current site map */ - function getPage($action, $userClass) { + function printMap() { + print_r($this->siteMapArray); } } ?> -- libgit2 0.21.4