*/
private $_menuData = array();
+ /**
+ * Array for faster check which call is allowed
+ *
+ * @var array
+ */
+ private $_allowedPageRequests = array();
+
/**
* GoreNest constructor.
*
}
/**
- * Get the menu data for given area and category.
- * This shows only entries which have a category set.
- * No category can be used for hidden entries.
+ * Load the complete menu
*
- * @param string $category
- * @param bool $reload
- * @return array
+ * @return void
*/
- public function get($category,$reload=false) {
-
- if(empty($category)) return false;
-
- if(empty($reload) && isset($this->_menuData[$category])) {
- return $this->_menuData[$category];
- }
-
+ public function loadMenu() {
# reset the menu
- $this->_menuData[$category] = array();
+ $this->_menuData = array();
$queryStr = "SELECT id, text, action, icon, category
FROM `".DB_PREFIX."_menu`
- WHERE ".$this->_User->getSQLRightsString()."
- AND `category` = '".$this->_DB->real_escape_string($category)."'
+ WHERE ".$this->_User->getSQLRightsString()."
ORDER BY position";
+ if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true));
try {
$query = $this->_DB->query($queryStr);
if($query !== false && $query->num_rows > 0) {
while(($result = $query->fetch_assoc()) != false) {
$this->_menuData[$result['category']][$result['id']] = $result;
+ $this->_allowedPageRequests[$result['action']] = $result['action'];
}
}
}
catch (Exception $e) {
error_log("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage());
}
+ }
+
+ /**
+ * Get the menu data for given area and category.
+ * This shows only entries which have a category set.
+ * No category can be used for hidden entries.
+ *
+ * @param string $category
+ * @param bool $reload
+ * @return array
+ */
+ public function get($category,$reload=false) {
+
+ if(empty($category)) return false;
+
+ if(empty($reload) && isset($this->_menuData[$category])) {
+ return $this->_menuData[$category];
+ }
+ $this->loadMenu($reload);
return $this->_menuData[$category];
}
/**
- * Allowed page requests based on the menu entries and user
+ * Return allowed page requests
*
* @return array
*/
public function allowedPageRequests() {
- $ret = array();
- $queryStr = "SELECT id, action
- FROM `".DB_PREFIX."_menu`
- WHERE ".$this->_User->getSQLRightsString()."";
- try {
- $query = $this->_DB->query($queryStr);
- if($query !== false && $query->num_rows > 0) {
- while(($result = $query->fetch_assoc()) != false) {
- $ret[$result['action']] = $result['action'];
- }
- }
- }
- catch (Exception $e) {
- error_log("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage());
- }
-
- return $ret;
+ return $this->_allowedPageRequests;
}
}