Highway to PSR2
[openemr.git] / interface / main / tabs / menu / menu_db.php
blob6dc0d7524b704a8685066fe4702b875a2ede5f81
1 <?php
2 /**
3 * Copyright (C) 2016 Kevin Yeh <kevin.y@integralemr.com>
5 * LICENSE: This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 3
8 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
16 * @package OpenEMR
17 * @author Kevin Yeh <kevin.y@integralemr.com>
18 * @link http://www.open-emr.org
21 function menu_entry_to_object($row)
23 $retval=new stdClass();
24 foreach ($row as $key => $value) {
25 $retval->$key=$value;
28 $retval->requirement=intval($retval->requirement);
29 $retval->children=array();
30 if ($retval->url==null) {
31 unset($retval->url);
34 return $retval;
36 function load_menu($menu_set)
39 $menuTables=" SHOW TABLES LIKE ?";
40 $res=sqlQuery($menuTables, array("menu_trees"));
41 if ($res===false) {
42 return array();
45 $menuQuery=" SELECT * FROM menu_trees, menu_entries WHERE menu_trees.entry_id=menu_entries.id AND menu_set=? ORDER BY parent, seq";
46 $res=sqlStatement($menuQuery, array($menu_set));
48 $retval=array();
49 $entries=array();
50 $parent_not_found=array();
51 while ($row= sqlFetchArray($res)) {
52 $entries[$row['entry_id']]=menu_entry_to_object($row);
53 if (empty($row['parent'])) {
54 array_push($retval, $entries[$row['entry_id']]);
55 } else {
56 if (isset($entries[$row['parent']])) {
57 $parent=$entries[$row['parent']];
58 array_push($parent->children, $entries[$row['entry_id']]);
59 } else {
60 array_push($parent_not_found, $entries[$row['entry_id']]);
65 foreach ($parent_not_found as $row) {
66 if (isset($entries[$row->parent])) {
67 $parent=$entries[$row->parent];
69 array_push($parent->children, $row);
70 } else {
71 array_push($parent_not_found2, $row);
75 return json_decode(json_encode($retval));