class.comments.php
5.74 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<?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 poremotnu
*/
class filedsGetPoremontuCommentsQuery
{
static function time_add($v){
return date('d.m.Y h:i',$v);
}
static function profile_url($v){
include_once(MAIN_SOURCE_PATH.'/modules/users/inc/url.php');
return sys_url(URL_USER_PROFILE,$v);
}
static function avatar_url($v){
global $MAIN_PAGE;
include_once(MAIN_SOURCE_PATH.'/modules/users/inc/cache.php');
if ( !empty($v) ){
return MAIN_RF_URL.'/source/modules/ajax/tmp/crop_'.$v;
}else{
return MAIN_RF_URL.$MAIN_PAGE -> config('user_default_avatar');
}
}
/*static function row_class($v){
return !empty($v) ? 'body2' : 'body_red';
}*/
static function c_comment($v){
return sys_convert_br($v);
}
/*static function comment_url($v,$row){
if ( empty($row['module']) || empty($row['n_id']) || empty($v) ){
sys_error(500);
}
// подключаем класс комментариев модуля
include_once(MAIN_SOURCE_PATH.'/modules/'.$row['module'].'/inc/class.comments.php');
$class = $row['module'].'_comments';
// return $class::comment_url($v,$row['n_id']);
}*/
// получаем общее количество комментов
static function count_all(){
$s = new comments_q( $this -> table ,'c' );
$s -> get('COUNT(*)');
list($count) = $s -> row();
return $count;
}
// получаем количество комментов за сегодня
static function count_on_day(){
$time = mktime(0,0,0,date('m',MAIN_TIME),date('d',MAIN_TIME),date('Y',MAIN_TIME) );
$s = new comments_q( $this -> table ,'c' );
$s -> set_anothe_where('c.c_time_add>='.$time);
$s -> set_anothe_where('c.c_time_add<='.MAIN_TIME);
$s -> get('COUNT(*)');
list($count) = $s -> row();
return $count;
}
// получаем количество комментов на модерации
static function count_wait(){
$s = new comments_q( $this -> table ,'c' );
$s -> where_active(0);
//$n -> set_debug(1);
$s -> get('COUNT(*)',false);
list($count) = $s -> row();
return $count;
}
}
class filedsSetPoremontuCommentsQuery
{
static function c_message($v){
if ( empty($v) ){
throw new Exception(E_COMMENTS_EMPTY_MESSAGE);
}
return $v;
}
static function u_id($v=-1){
if ( false===$v ){
$this -> set_info['u_id']=0;
}elseif( $v==-1 ){
throw new Exception( E_COMMENTS_EMPTY_ID );
}else{
return intval($v);
}
return true;
}
public function u_login($v=-1){
if ( false===$v ){
$this -> set_info['u_login']='';
}elseif( $v==-1 ){
throw new Exception( E_COMMENTS_EMPTY_LOGIN );
}else{
return $v;
}
return true;
}
public function n_id($v){
$v = intval($v);
if ( empty($v) ){
throw new Exception( E_COMMENTS_EMPTY_OBJ );
}
return $v;
}
public function c_active($v){
if ( !isset($v) ){
return false;
}
if ( !empty($v) ){
return 1;
}else{
return 0;
}
return true;
}
}
class poremontuCommentsQuery extends query
{
var $fields_get = 'filedsGetPoremontuCommentsQuery';
public function __construct($table,$alias)
{
$this -> set_table($table);
$this -> set_alias($alias);
}
/**
* Подключаем таблицу пользователей
*
* @var: string $alias Алиас для исплользования в mysql запросе
* @var: string $cols нужные столбцы
*/
public function include_users($alias,$cols=false){
$this -> include_table( MAIN_USERS_TBL ,$alias,'u_id',$cols );
}
public function where_id($v){
$v = intval($v);
if ( empty($v) ){
return FALSE;
}
return $this -> set_where( $this -> alias.'.c_id',$v);
}
public function where_obj($v){
$v = intval($v);
if ( empty($v) ){
return FALSE;
}
return $this -> set_where( $this -> alias.'.n_id',$v);
}
public function where_active($v){
$v = intval($v);
if (!empty($v) ){
$v = 1;
}
return $this -> set_where( $this -> alias.'.c_active',$v);
}
public function where_login($v){
if ( false!==users::error_login($v) ){
return false;
}
return $this -> set_where( $this -> alias.'.u_login',$v);
}
public function where_uid($v){
$v = intval($v);
if ( empty($v) ){
return false;
}
return $this -> set_where( $this -> alias.'.u_id',$v);
}
public function orderby_module($v,$alias=true){
if ( $alias ){
return $this -> set_orderby($this -> alias.'.module_name ',$v);
}else{
return $this -> set_orderby('module_name ',$v);
}
}
public function orderby_id($v,$alias=true){
if ( $alias ){
return $this -> set_orderby($this -> alias.'.c_id',$v);
}else{
return $this -> set_orderby('c_id',$v);
}
}
public function orderby_ulogin($v,$alias=true){
if ( $alias ){
return $this -> set_orderby($this -> alias.'.u_login',$v);
}else{
return $this -> set_orderby('u_login',$v);
}
}
public function orderby_time_add($v,$alias=true){
if ( $alias ){
return $this -> set_orderby($this -> alias.'.c_time_add',$v);
}else{
return $this -> set_orderby('c_time_add',$v);
}
}
}
class poremontuComments extends objects
{
public $table = "comments";
public $key = "c_id";
public $fields = 'filedsSetPoremontuCommentsQuery';
static function query($table,$a){
return new poremontuCommentsQuery($table,$a);
}
static function load_id($table,$id){
$u = self::query($table,'u');
if ( !$u -> where_id($id) ){
return FALSE;
}
if ( !$u -> get('u.*') ){
return FALSE;
}
if ( $u -> get_count_rows()==0 ){
return FALSE;
}
$c = new self( $id,$u -> row() );
$c -> table = $table;
return $c;
}
}
?>