Commit ead75b4299620f752e5e6d94ae4c2f6325af7dea
1 parent
6e45a427
finished and tested sitemap implementation
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@47 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
77 additions
and
16 deletions
lib/SiteMap.inc
| @@ -8,10 +8,23 @@ | @@ -8,10 +8,23 @@ | ||
| 8 | * @author michael@jamwarehouse.com | 8 | * @author michael@jamwarehouse.com |
| 9 | * @package dms | 9 | * @package dms |
| 10 | */ | 10 | */ |
| 11 | + | ||
| 11 | class SiteMap { | 12 | class SiteMap { |
| 12 | 13 | ||
| 13 | /** | 14 | /** |
| 14 | - * Adds a site mapping entry. | 15 | + * The underlying site map storage array |
| 16 | + */ | ||
| 17 | + var $siteMapArray; | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * Constructs a new SiteMap, initialising the array. | ||
| 21 | + */ | ||
| 22 | + function SiteMap() { | ||
| 23 | + $this->siteMapArray = array(); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * Adds a site page mapping entry. | ||
| 15 | * | 28 | * |
| 16 | * @param $action | 29 | * @param $action |
| 17 | * the controller action | 30 | * the controller action |
| @@ -22,11 +35,44 @@ class SiteMap { | @@ -22,11 +35,44 @@ class SiteMap { | ||
| 22 | * @param $userClass | 35 | * @param $userClass |
| 23 | * the user class with access to this page | 36 | * the user class with access to this page |
| 24 | */ | 37 | */ |
| 25 | - function addMap($action, $page, $sectionName, $userClass) { | ||
| 26 | - global $default; | ||
| 27 | - | ||
| 28 | - $realAction = $_ACTIONS[$action]; | ||
| 29 | - // add to map impl. | 38 | + function addPage($action, $page, $sectionName, $userClass) { |
| 39 | + // add to map | ||
| 40 | + $this->siteMapArray[$sectionName][$userClass][$action] = $page; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * Returns the page mapped to the action, userClass pair. | ||
| 45 | + * | ||
| 46 | + * @param $action | ||
| 47 | + * the action to lookup pages for | ||
| 48 | + * @param $userClass | ||
| 49 | + * the userclass to perform page level validation against | ||
| 50 | + * @return | ||
| 51 | + * the page to redirect to, or false if the user class doesn't | ||
| 52 | + * have access to the page | ||
| 53 | + */ | ||
| 54 | + function getPage($action, $userClass) { | ||
| 55 | + // TODO: need to accomodate SA having all the access of the userclasses below it | ||
| 56 | + // map incoming userClass to number | ||
| 57 | + $uc = constant($userClass); | ||
| 58 | + echo "userclass = $userClass; uc=$uc\n"; | ||
| 59 | + // iterate through multidim sitemap array | ||
| 60 | + foreach ($this->siteMapArray as $section => $valArr) { | ||
| 61 | + foreach ($valArr as $userAccess => $pageArr) { | ||
| 62 | + echo "userAccess=($userAccess)" . constant($userAccess) . "; uc=$uc\n"; | ||
| 63 | + if ($uc <= constant($userAccess)) { | ||
| 64 | + // now loop through pages until we find the right one | ||
| 65 | + foreach ($pageArr as $ackshin => $page) { | ||
| 66 | + if ($ackshin == $action) { | ||
| 67 | + return $page; | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | + } | ||
| 71 | + } | ||
| 72 | + } | ||
| 73 | + // if the function hasn't returned already then the specified | ||
| 74 | + // userClass does not have access to the action | ||
| 75 | + return false; | ||
| 30 | } | 76 | } |
| 31 | 77 | ||
| 32 | /** | 78 | /** |
| @@ -41,20 +87,35 @@ class SiteMap { | @@ -41,20 +87,35 @@ class SiteMap { | ||
| 41 | * an array containing the actions for the specified section | 87 | * an array containing the actions for the specified section |
| 42 | */ | 88 | */ |
| 43 | function getSection($sectionName, $userClass) { | 89 | function getSection($sectionName, $userClass) { |
| 90 | + // check if the section exists | ||
| 91 | + if (is_array($this->siteMapArray[$sectionName])) { | ||
| 92 | + // initialise result array | ||
| 93 | + $results = array(); | ||
| 94 | + // need to loop through all user class arrays in this section | ||
| 95 | + foreach ($this->siteMapArray[$sectionName] as $uc => $pages) { | ||
| 96 | + if (constant($userClass) <= constant($uc)) { | ||
| 97 | + // add this array to the resultset array | ||
| 98 | + $results = array_merge($results, $this->siteMapArray[$sectionName][$uc]); | ||
| 99 | + } | ||
| 100 | + } | ||
| 101 | + // now check if we have anything in the results array before returning it | ||
| 102 | + if (count($results) > 0) { | ||
| 103 | + return $results; | ||
| 104 | + } else { | ||
| 105 | + return false; | ||
| 106 | + } | ||
| 107 | + } else { | ||
| 108 | + // supplied section not in sitemap | ||
| 109 | + // TODO: internal error code? | ||
| 110 | + return false; | ||
| 111 | + } | ||
| 44 | } | 112 | } |
| 45 | 113 | ||
| 46 | /** | 114 | /** |
| 47 | - * Returns the page mapped to the action, userClass pair. | ||
| 48 | - * | ||
| 49 | - * @param $action | ||
| 50 | - * the action to lookup pages for | ||
| 51 | - * @param $userClass | ||
| 52 | - * the userclass to perform page level validation against | ||
| 53 | - * @return | ||
| 54 | - * the page to redirect to, or false if the user class doesn't | ||
| 55 | - * have access to the page | 115 | + * Prints the current site map |
| 56 | */ | 116 | */ |
| 57 | - function getPage($action, $userClass) { | 117 | + function printMap() { |
| 118 | + print_r($this->siteMapArray); | ||
| 58 | } | 119 | } |
| 59 | } | 120 | } |
| 60 | ?> | 121 | ?> |