Commit a20ac1cff7ad77aa0aaadafc65f2235157b976ad

Authored by Michael Joseph
1 parent 4390cf9d

added getDefaultAction method and updated sitemap array handling to support this


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@426 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 37 additions and 3 deletions
lib/session/SiteMap.inc
@@ -35,7 +35,7 @@ class SiteMap { @@ -35,7 +35,7 @@ class SiteMap {
35 */ 35 */
36 function addPage($action, $page, $sectionName, $groupName) { 36 function addPage($action, $page, $sectionName, $groupName) {
37 // add to map 37 // add to map
38 - $this->siteMapArray[$sectionName][$groupName][$action] = $page; 38 + $this->siteMapArray[$sectionName][$groupName][$action] = array ("page" =>$page, "default" => false);
39 } 39 }
40 40
41 /** 41 /**
@@ -47,8 +47,9 @@ class SiteMap { @@ -47,8 +47,9 @@ class SiteMap {
47 * @param string the user group with access to this page 47 * @param string the user group with access to this page
48 */ 48 */
49 function addDefaultPage($action, $page, $sectionName, $groupName) { 49 function addDefaultPage($action, $page, $sectionName, $groupName) {
  50 + $this->siteMapArray[$sectionName][$groupName][$action] = array ("page" =>$page, "default" => true);
50 } 51 }
51 - 52 +
52 /** 53 /**
53 * Returns the section name of the supplied page 54 * Returns the section name of the supplied page
54 * 55 *
@@ -136,7 +137,7 @@ class SiteMap { @@ -136,7 +137,7 @@ class SiteMap {
136 if ( ($requiredGroupName == "Anonymous") || 137 if ( ($requiredGroupName == "Anonymous") ||
137 ( Permission::userIsInGroupName($requiredGroupName) || 138 ( Permission::userIsInGroupName($requiredGroupName) ||
138 Permission::userIsInGroupName("System Administrators") ) ) { 139 Permission::userIsInGroupName("System Administrators") ) ) {
139 - return $page; 140 + return $page["page"];
140 } 141 }
141 } 142 }
142 } 143 }
@@ -148,6 +149,39 @@ class SiteMap { @@ -148,6 +149,39 @@ class SiteMap {
148 return false; 149 return false;
149 } 150 }
150 151
  152 +
  153 + /**
  154 + * Returns the default action for the supplied section
  155 + *
  156 + * @param string the section name to return the default action for
  157 + * @return string the controller action for the default page for this section
  158 + */
  159 + function getDefaultAction($sectionName) {
  160 + global $default;
  161 + // check if the section exists
  162 + if (is_array($this->siteMapArray[$sectionName])) {
  163 + // initialise result array
  164 + $results = array();
  165 + // need to loop through all (groupName, page) arrays in this section
  166 + foreach ($this->siteMapArray[$sectionName] as $requiredGroupName => $pages) {
  167 + // don't need to check the permissions here, when the controller tries to
  168 + // retrieve the page from the action, the perms will be checked
  169 + $default->log->debug("Sitemap::getDefaultAction: (section=$sectionName, reqGrp=$requiredGroupName); pages=" . arrayToString($pages));
  170 + foreach ($pages as $action => $pageArray) {
  171 + $default->log->debug("Sitemap::getDefaultAction: action=$action; pageArray" . arrayToString($pageArray));
  172 + if ($pageArray["default"]) {
  173 + return $action;
  174 + }
  175 + }
  176 + }
  177 + } else {
  178 + // supplied section not in sitemap
  179 + // TODO: internal error code?
  180 + $_SESSION["errorMessage"] = "$sectionName not in SiteMap!";
  181 + return false;
  182 + }
  183 + }
  184 +
151 /** 185 /**
152 * Returns the pages in the specified section accessible to the 186 * Returns the pages in the specified section accessible to the
153 * specified userClass. 187 * specified userClass.