Skip to content

Commit 0310f36

Browse files
committed
Added navigation model.
1 parent 19f18c8 commit 0310f36

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ The folders in this repo are as follows:
99

1010
`sql` contains an SQL dump which should be run against a database to create the required schema. *This is in MySQL format.*
1111

12+
`config` contains the config files that can be used for library. **Copy into your `application` directory.**
13+
1214
`libraries` contains the PHP files for the library. **Copy into your `application` directory.**
1315

1416
`models` contains required models for the library. **Copy into your `application` directory.**

models/nav_model.php

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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

Comments
 (0)