class.category.php
4.17 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?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.ns_tree.php');
class category_q extends ns_tree_q{
/**
* Фильтр по номеру алиасу категории
*
* @var: int $v - номер категории
* @return: bool
*/
public function where_alias($v){
if ( empty($v) || ! sys_is_alias($v) ){
return FALSE;
}
return $this -> set_where( $this -> alias.'.c_alias',$v);
}
/**
* Фильтр по номеру категории
*
* @var: int $v - номер категории
* @return: bool
*/
public function where_cid($v){
$v = intval($v);
if ( empty($v) ){
return FALSE;
}
return $this -> set_where( $this -> alias.'.c_id',$v);
}
public function where_name($v){
return $this -> set_where( $this -> alias.'.c_name',$v);
}
protected function c_parent_id($v){
return category::get_parent($v,$this -> table,$this -> alias);
}
static function upl_img($v){
// загрузка аватарки
$a = new upload_img('image');
// 500 кб
$a -> set_max_size( 5000000 );
// результирующий файл
$a -> set_file($v);
// сюда будем грузить
$a -> set_path( 'market/img');
// полный путь к папке
$a -> set_base( MAIN_URL.'/media/market/img');
return $a -> get('img',1,'c_image');
}
static function category_url($v){
return sprintf(URL_CATEGORY,$v);
}
static function image_src($v){
return MAIN_URL.'/media/market/img/'.$v;
}
} //end class
class category extends ns_tree{
protected function __construct( $array=array(),$table,$alias ){
$this -> table = $table;
$this -> alias = $alias;
$this -> info = $array;
$this -> main_key = $array['c_id'];
}
// загружаем указанный
static function load_id($id,$table='system_category',$alias='c',$row = false){
if ( false!==$res ){
$n = new category_q( $table,$alias);
if ( false==$n -> where_id($id) ){
return false;
}
$n -> get('*',false);
$row = $n -> row();
if ( false===$row ){
return false;
}
}
return new category($row,$table,$alias);
}
// создаём новый объект
static function create($table,$alias){
return new category(array('c_id'=>0),$table,$alias);
}
public function error(){
return $this -> last_error;
}
public function get($k){
if ( isset($this -> info[$k]) ){
return $this -> info[$k];
}
$this -> make_error(ERROR_500, sprintf(A_NOT_VAR,$k));
}
public function set($k,$v){
if ( method_exists($this,'set_'.$k) ){
$f = 'set_'.$k;
return $this -> $f($v);
}
$this -> set_info[$k] = $v;
return true;
}
public function set_c_alias($v){
$v= category::make_alias($v,$this -> table,$this -> alias);
if ( empty($v) ){
$this -> make_error(E_NSTREE_EMPTY_ALIAS);
return false;
}
$this -> set_info['c_alias']=$v;
return true;
}
public function id(){
return $this -> info['c_id'];
}
static function make_alias($v,$table,$alias){
$v = sys_translit($v);
if ( !category::is_exists($v,$table,$alias) ){
return $v;
}
return category::make_alias($v.'-'.time(),$table,$alias );
}
function make_error($msg){
$this -> last_error = $msg;
}
// проверяем существование новость по траснлит адресу
static function is_exists($v,$table,$alias){
$n = new category_q($table,$alias);
if ( !$n -> where_alias($v) ){
return false;
}
$n -> get('COUNT(*)');
list($count) = $n -> row();
if ( $count >0 ){
return true;
}
return false;
}
static function get_path($id,$table,$alias='a'){
$p = new ns_tree_q($table,$alias);
$p -> where_up($id);
$p -> order_left('ASC');
// $p -> set_debug(1);
$p -> get('c_alias,c_name');
$rows= array();
while( list($c_alias,$c_name) = $p -> row() ){
$rows[$c_alias]=$c_name;
}
return $rows;
}
}//end class
?>