-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiMenu.php
161 lines (97 loc) · 3.69 KB
/
MultiMenu.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php defined('DIRECT') OR exit('No direct script access allowed');
/*
* Menu Plugin
*
* A.Aziz TEMEL - <[email protected]>
*
*/
class MultiMenu {
public $ayarlar = array();
public $menuId;
public $menuLink;
public $menuAdi;
public $menuUstid;
public $ulAc = '<ul class="ust">';
public $AltulAc = '<ul class="alt">';
public $liAc = '<li class="ust">';
public $AltliAc = '<li class="alt">';
public $menu = array('ustMenu' => array(), 'altMenu' => array());
public function init($ayarlar){
$this->ayarlar = $ayarlar;
try {
// Veritabanı menü id sütun adı
if(array_key_exists('menuId', $this->ayarlar)){
$this->menuId = $ayarlar['menuId'];
}else{
throw new Exception('Veritabanında yer alan menü id\'nize ait sütun adını belirtiniz.');
}
// Veritabanı menü linki sütun adı
if(array_key_exists('menuLink', $this->ayarlar)){
$this->menuLink = $ayarlar['menuLink'];
}else{
throw new Exception('Veritabanında yer alan menü linkinize ait sütun adını belirtiniz.');
}
// Veritabanı menü adı sütun adı
if(array_key_exists('menuAdi', $this->ayarlar)){
$this->menuAdi = $ayarlar['menuAdi'];
}else{
throw new Exception('Veritabanında yer alan menü adınıza ait sütun adını belirtiniz.');
}
// Veritabanı menü üst id değeri sütun adı
if(array_key_exists('menuUstid', $this->ayarlar)){
$this->menuUstid = $ayarlar['menuUstid'];
}else{
throw new Exception('Veritabanında yer alan menü üst id\'nize ait sütun adını belirtiniz.');
}
} catch(Exception $e) {
echo $e->getMessage();
}
// Menü ul html tag aç
if(array_key_exists('ulAc', $this->ayarlar)){
$this->ulAc = $this->ayarlar['ulAc'];
}
// Alt Menü ul html tag aç
if(array_key_exists('AltulAc', $this->ayarlar)){
$this->AltulAc = $this->ayarlar['AltulAc'];
}
// Menü li html tag aç
if(array_key_exists('liAc', $this->ayarlar)){
$this->liAc = $this->ayarlar['liAc'];
}
// Alt menü li html tag aç
if(array_key_exists('AltliAc', $this->ayarlar)){
$this->AltliAc = $this->ayarlar['AltliAc'];
}
}
public function olustur($data, $ustId = 0){
if(array_key_exists('menuId', $this->ayarlar) && array_key_exists('menuLink', $this->ayarlar) && array_key_exists('menuAdi', $this->ayarlar) && array_key_exists('menuUstid', $this->ayarlar)){
foreach ($data AS $veri) {
$this->menu['ustMenu'][$veri[$this->menuId]] = $veri;
$this->menu['altMenu'][$veri[$this->menuUstid]][] = $veri[$this->menuId];
}
return $this->menuler($this->menu, $ustId);
}
}
private function menuler($data, $ustId = 0) {
// Veritabanı data döngü işlemi...
$return = "";
if (isset($data['altMenu'][$ustId])) {
if($ustId == 0){
$return .= "\n{$this->ulAc}\n";
}else{
$return .= "\n{$this->AltulAc}\n";
}
foreach ($data['altMenu'][$ustId] as $menuId) {
if (!isset($data['altMenu'][$menuId])) {
$return .= "{$this->AltliAc}\n <a href=\"{$data['ustMenu'][$menuId][$this->menuLink]}\">{$data['ustMenu'][$menuId][$this->menuAdi]}</a>\n</li>\n";
}else{
$return .= "{$this->liAc}\n <a href=\"{$data['ustMenu'][$menuId][$this->menuLink]}\">{$data['ustMenu'][$menuId][$this->menuAdi]}</a>\n";
$return .= $this->menuler($data,$menuId);
$return .= "</li>\n";
}
}
$return .= "</ul>\n";
}
return $return;
}
}