1
+ <?php if ( ! defined ('BASEPATH ' )) exit ('No direct script access allowed ' );
2
+ /**
3
+ * Model used by navigation library.
4
+ * This facilitates reading navigation information stored in the
5
+ * database. It does not perform any edits or additions.
6
+ * User: danielwaghorn
7
+ * Date: 11/06/15
8
+ * Time: 09:05
9
+ */
10
+
11
+ class Nav_model extends CI_Model {
12
+
13
+ var $ title = '' ;
14
+ var $ content = '' ;
15
+ var $ date = '' ;
16
+
17
+ function __construct ()
18
+ {
19
+ // Call the Model constructor
20
+ parent ::__construct ();
21
+ $ this ->load ->database ();
22
+ }
23
+
24
+ public function getMenuID ($ menu_name ) {
25
+ /**
26
+ * Returns the id from associated menu handle
27
+ * @param $menu_name : string name associated to menu defined in CI-Nav-Menus
28
+ * @returns int menu ID otherwise -1;
29
+ */
30
+
31
+ $ query = $ this ->db ->query ('SELECT `MenuName` FROM `CI-Nav-Menus` WHERE `MenuID` = ' . $ menu_name );
32
+ $ row = $ query ->row ();
33
+ return $ row ->MenuName ;
34
+ }
35
+
36
+ public function getTopLevelNav_byName ($ menu_name ) {
37
+ /**
38
+ * Returns the top level of a menu
39
+ * @param $menu_name : String handle of menu e.g. 'public'
40
+ * as defined in CI-Nav-Menus
41
+ * @returns : Query with result, if invalid NULL
42
+ */
43
+
44
+ // Check $nav_name is not null
45
+ if (isset ($ menu_name ) && (strcmp (preg_replace ("/[^a-zA-Z0-9]+/ " , "" , $ menu_name ),$ menu_name ))) {
46
+ // Get ID
47
+ $ menu_ID = $ this ->getMenuID ($ menu_name );
48
+ // Return Menu
49
+ return $ this ->getTopLevelNav_byID ((int ) $ menu_ID );
50
+ }
51
+
52
+ return NULL ;
53
+ }
54
+
55
+ public function getTopLevelNav_byID ($ menu_ID ) {
56
+ /**
57
+ * Returns the top level of a menu
58
+ * @param $menu_ID : int ID of menu as defined in CI-Nav-Menus
59
+ * @returns : Query with result
60
+ */
61
+
62
+ if (isset ($ menu_ID ) && $ menu_ID != -1 && is_int ($ menu_ID )) {
63
+
64
+ $ query = $ this ->db ->query ('SELECT `ItemName`, `ItemHumanName`, `ItemLink`
65
+ FROM `CI-Nav-Items` AS I
66
+ INNER JOIN `CI-Nav-InMenu` AS C
67
+ ON C.`ItemID` = I.`ItemID`
68
+ WHERE C.`MenuID` = ' . $ menu_ID );
69
+
70
+ return $ query ;
71
+
72
+ }
73
+ return NULL ;
74
+ }
75
+
76
+ public function getSubItems ($ item_ID ) {
77
+ /**
78
+ * Returns sub items under a menu item where ParentItem
79
+ * refs ItemID in CI-Nav-Items
80
+ * @param $item_ID : int ID of menu item as defined in
81
+ * CI-Nav-Items
82
+ * @returns : Query with result of MenuItems
83
+ */
84
+
85
+ if (isset ($ item_ID ) && is_int ($ item_ID )) {
86
+
87
+ $ query = $ this ->db ->query ('SELECT `ItemName`, `ItemHumanName`, `ItemLink`
88
+ FROM `CI-Nav-Items`
89
+ WHERE `ParentItem` = ' . $ item_ID );
90
+ return $ query ;
91
+
92
+ }
93
+ return NULL ;
94
+ }
95
+
96
+ }
0 commit comments