1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: 18: 19: 20: 21: 22:
23: class cApiNavSubCollection extends ItemCollection {
24:
25: 26: 27:
28: public function __construct() {
29: global $cfg;
30: parent::__construct($cfg['tab']['nav_sub'], 'idnavs');
31: $this->_setItemClass('cApiNavSub');
32:
33:
34: $this->_setJoinPartner('cApiNavMainCollection');
35: $this->_setJoinPartner('cApiAreaCollection');
36: }
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:
91: public function getSubnavigationsByAreaName($area, $level = 1, $online = 1) {
92: global $cfg;
93:
94: $level = (int) $level;
95: $online = (1 == $online) ? 1 : 0;
96:
97: $areasNsRs = array();
98:
99: $nav = new cGuiNavigation();
100:
101: $sql = "SELECT
102: ns.location AS location,
103: a.name AS name,
104: a.menuless AS menuless
105: FROM
106: " . $cfg['tab']['area'] . " AS a,
107: " . $this->table . " AS ns
108: WHERE
109: a.idarea = ns.idarea
110: AND
111: ns.level = " . $level . "
112: AND
113: ns.online = " . $online . "
114: AND (
115: a.parent_id = '" . $this->db->escape($area) . "'
116: OR
117: a.name = '" . $this->db->escape($area) . "'
118: )
119: ORDER BY
120: a.parent_id ASC,
121: ns.idnavs ASC";
122:
123: $this->db->query($sql);
124:
125: while ($this->db->nextRecord()) {
126: $rs = $this->db->toArray();
127: $rs['caption'] = $nav->getName($rs['location']);
128: $areasNsRs[] = $rs;
129: }
130:
131: return $areasNsRs;
132: }
133:
134: }
135:
136: 137: 138: 139: 140: 141:
142: class cApiNavSub extends Item {
143:
144: 145: 146: 147: 148: 149:
150: public function __construct($mId = false) {
151: global $cfg;
152: parent::__construct($cfg['tab']['nav_sub'], 'idnavs');
153: $this->setFilters(array(
154: 'addslashes'
155: ), array(
156: 'stripslashes'
157: ));
158: if ($mId !== false) {
159: $this->loadByPrimaryKey($mId);
160: }
161: }
162:
163: 164: 165: 166: 167: 168: 169: 170: 171:
172: public function setField($name, $value, $bSafe = true) {
173: switch ($name) {
174: case 'idarea':
175: case 'idnavm':
176: case 'level':
177: $value = (int) $value;
178: break;
179: case 'online':
180: $value = (1 == $value) ? 1 : 0;
181: break;
182: }
183:
184: return parent::setField($name, $value, $bSafe);
185: }
186:
187: }
188: