class.menu.php
4.01 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
/**
* @author: Bunzia Alexander <nifus@mail.ru> <http://www.weblancer.net/users/nifus/>
* @copyright: Copyright (c) 2010, Bunzia Alexander
* @version: 1.0
* @license: http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @package: HiLO CMS
*/
include_once(MAIN_SOURCE_PATH.'/inc/class.nsTree.php');
include_once(MAIN_SOURCE_PATH.'/inc/class.query.php');
include_once(MAIN_SOURCE_PATH.'/inc/class.objects.php');
include_once(MAIN_SOURCE_PATH.'/modules/menu/inc/url.php');
class filedsSetMenu
{
//static $id = false; // адрес новости
/*static function u_login($v,$obj){
$e = news::error_login($v);
if ( !empty($e) ){
throw new Exception($e);
}
if ( news::exists_login($v,$obj -> id() ) ){
throw new Exception(U_EXISTS_LOGIN);
}
return $v;
}*/
// родитель не может быть пустым
static function c_parent($v,$obj){
$v = intval($v);
if ( empty($v) ){
throw new Exception(E_NSTREE_BAD_PARENT);
}
$obj -> parent_id = $v;
return false;
}
static function c_name($v,$obj){
$v = trim($v);
if ( empty($v) ){
throw new Exception('Ошибка: нужно заполнить поле "Заголовок"');
}
return $v;
}
}
class filedsGetMenu extends filedsGetnsTree
{
static $__var = array(); // для хранения временных переменных
static function url_item($v){
return sys_url(URL_MENU_CONTROL_ITEMS,$v);
}
// строим дерево меню
static function menu_select($v){
$v = menu::getParent($v);
$p = menu::query('f');
$p -> where_more('c_level',1);
$p -> where_down($_GET['menu_id']);
$p -> where_main_rows();
$p -> order_left('ASC');
$p -> get('c_id,c_name,c_level',false);
$s = new select_box();
$s -> block_id($v);
$s -> selected_id($v);
$s -> empty_record(true,$_GET['menu_id'],'В основание');
while( list($c_id,$c_name,$c_level) = $p -> row() ){
$c_name = str_repeat('---',($c_level-1)).' '.$c_name;
$s -> set($c_id,$c_name);
}
return $s -> get();
}
static function lang_links($v){
if ( false===MAIN_MULTILANG){
return false;
}
$langs = explode(',',MAIN_LANGS);
$result = array();
foreach( $langs as $l ){
$q = menu::query('q');
//$q -> set_debug(1);
$q -> where_link($v);
$q -> where_lang($l);
$q -> get('COUNT(*)');
list($count) = $q -> row();
$result[] = array('lang'=>$l,'exists'=> (( $count ) ? 1 : 0) );
}
return $result;
}
static function active($v){
if ( preg_match('#^'. $v .'#iUs',$_SERVER['REQUEST_URI']) ){
return true;
}
return false;
}
static function name($v,$row){
return str_repeat('---',($row['c_level']-2)).' '.$v;
}
}
class menuQuery extends nsTreeQuery{
var $fields_get = 'filedsGetMenu';
/**
* @var string $alias Алиас для исплользования в mysql запросе
*/
public function __construct($alias){
parent::__construct( "menu" ,$alias,$fields=array('id'=>'c_id','left'=>'c_left','right'=>'c_right','level'=>'c_level') );
}
} // end class
class menu extends nsTree{
public $table = "menu";
public $key = "c_id";
public $fields = 'filedsSetMenu';
static $s_table= "menu";
static function load_id($id){
$u = self::query('u');
if ( !$u -> where_id($id) ){
return FALSE;
}
if ( !$u -> get('u.*') ){
return FALSE;
}
if ( $u -> get_count_rows()==0 ){
return FALSE;
}
return new self( $id,$u -> row() );
}
static function create(){
return new self( 0,array('c_id'=>0) );
}
static function query($alias){
return new menuQuery( $alias,array('id'=>self::$id,'left'=>self::$left,'right'=>self::$right,'level'=>self::$level) );
}
static function getParent($id){
return parent::getParent( self::$s_table,$id );
}
static function getServiceInfo($id){
return parent::getServiceInfo( self::$s_table,$id );
}
static function order($one,$two){
return parent::order( self::$s_table,$one,$two );
}
} // end class