1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23:
24: class cApiNavSubCollection extends ItemCollection {
25:
26: 27: 28:
29: public function __construct() {
30: global $cfg;
31: parent::__construct($cfg['tab']['nav_sub'], 'idnavs');
32: $this->_setItemClass('cApiNavSub');
33:
34:
35: $this->_setJoinPartner('cApiNavMainCollection');
36: $this->_setJoinPartner('cApiAreaCollection');
37: }
38:
39: 40: 41: 42: 43: 44: 45: 46: 47: 48:
49: public function create($navm, $area, $level, $location, $online = 1) {
50: $item = $this->createNewItem();
51:
52: if (is_string($area)) {
53: $c = new cApiArea();
54: $c->loadBy('name', $area);
55:
56: if ($c->isLoaded()) {
57: $area = $c->get('idarea');
58: } else {
59: $area = 0;
60: cWarning(__FILE__, __LINE__, "Could not resolve area [$area] passed to method [create], assuming 0");
61: }
62: }
63:
64: $item->set('idnavm', $navm);
65: $item->set('idarea', $area);
66: $item->set('level', $level);
67: $item->set('location', $location);
68: $item->set('online', $online);
69:
70: $item->store();
71:
72: return $item;
73: }
74:
75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89:
90: public function getSubnavigationsByAreaName($area, $level = 1, $online = 1) {
91: global $cfg;
92:
93: $level = (int) $level;
94: $online = (1 == $online) ? 1 : 0;
95:
96: $areasNsRs = array();
97:
98: $nav = new cGuiNavigation();
99:
100: $sql = "SELECT
101: ns.location AS location,
102: a.name AS name,
103: a.menuless AS menuless
104: FROM
105: " . $cfg['tab']['area'] . " AS a,
106: " . $this->table . " AS ns
107: WHERE
108: a.idarea = ns.idarea
109: AND
110: ns.level = " . $level . "
111: AND
112: ns.online = " . $online . "
113: AND (
114: a.parent_id = '" . $this->db->escape($area) . "'
115: OR
116: a.name = '" . $this->db->escape($area) . "'
117: )
118: ORDER BY
119: a.parent_id ASC,
120: ns.idnavs ASC";
121:
122: $this->db->query($sql);
123:
124: while ($this->db->nextRecord()) {
125: $rs = $this->db->toArray();
126: $rs['caption'] = $nav->getName($rs['location']);
127: $areasNsRs[] = $rs;
128: }
129:
130: return $areasNsRs;
131: }
132:
133: }
134:
135: 136: 137: 138: 139: 140:
141: class cApiNavSub extends Item {
142:
143: 144: 145: 146: 147:
148: public function __construct($mId = false) {
149: global $cfg;
150: parent::__construct($cfg['tab']['nav_sub'], 'idnavs');
151: $this->setFilters(array(
152: 'addslashes'
153: ), array(
154: 'stripslashes'
155: ));
156: if ($mId !== false) {
157: $this->loadByPrimaryKey($mId);
158: }
159: }
160:
161: 162: 163: 164: 165: 166: 167:
168: public function setField($name, $value, $bSafe = true) {
169: switch ($name) {
170: case 'idarea':
171: case 'idnavm':
172: case 'level':
173: $value = (int) $value;
174: break;
175: case 'online':
176: $value = (1 == $value) ? 1 : 0;
177: break;
178: }
179:
180: return parent::setField($name, $value, $bSafe);
181: }
182:
183: }
184: