1 |
234 |
ahitrov |
package blogs::SQL::BlogsTable; |
2 |
|
|
|
3 |
|
|
use strict; |
4 |
|
|
use base 'SQL::DocumentTable'; |
5 |
|
|
|
6 |
|
|
sub db_table |
7 |
|
|
{ |
8 |
|
|
return 'blogs'; |
9 |
|
|
} |
10 |
|
|
|
11 |
|
|
sub available_filters { |
12 |
|
|
my @available_filters = qw( |
13 |
|
|
_class_filter |
14 |
|
|
_status_filter |
15 |
|
|
_in_id_filter |
16 |
|
|
_id_filter |
17 |
|
|
_name_filter |
18 |
|
|
_class_excludes_filter |
19 |
|
|
_sfilter_filter |
20 |
|
|
_datetime_filter |
21 |
|
|
_date_equal_filter |
22 |
|
|
_date_filter |
23 |
|
|
_previous_days_filter |
24 |
|
|
_s_filter |
25 |
|
|
|
26 |
|
|
_excludes_filter |
27 |
|
|
_link_filter |
28 |
|
|
_uid_filter |
29 |
|
|
_type_filter |
30 |
235 |
ahitrov |
_alias_filter |
31 |
234 |
ahitrov |
); |
32 |
|
|
return \@available_filters; |
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
# ---------------------------------------------------------------------------- |
36 |
|
|
# Свойства храним в массивах, потому что порядок важен! |
37 |
|
|
# Это общие свойства - одинаковые для всех документов. |
38 |
|
|
# |
39 |
|
|
# attr - обязательный параметр, название атрибута; |
40 |
|
|
# type - тип аттрибута, требуется для отображдения; |
41 |
|
|
# rusname - русское название, опять же требуется для отображения; |
42 |
|
|
# hidden - равен 1, когда |
43 |
|
|
# readonly - инициализации при записи только без изменения в дальнейшем |
44 |
|
|
# db_field - поле в таблице |
45 |
|
|
# default - значение по умолчанию (поле всегда имеет это значение) |
46 |
|
|
# ---------------------------------------------------------------------------- |
47 |
|
|
sub required_properties |
48 |
|
|
{ |
49 |
|
|
my $self = shift; |
50 |
|
|
|
51 |
|
|
my @parent_properties = $self->SUPER::required_properties; |
52 |
|
|
return ( |
53 |
|
|
@parent_properties, |
54 |
235 |
ahitrov |
{ |
55 |
|
|
'attr' => 'alias', |
56 |
|
|
'type' => 'string', |
57 |
|
|
'rusname' => 'Web-алиас', |
58 |
|
|
'db_field' => 'alias', |
59 |
|
|
'db_type' => 'varchar(64)', |
60 |
|
|
}, |
61 |
234 |
ahitrov |
{ # Тип блога... |
62 |
|
|
'attr' => 'type', |
63 |
|
|
'type' => 'status', |
64 |
|
|
'cases' => [ |
65 |
|
|
[0, 'Личный блог'], |
66 |
|
|
[1, 'Групповой блог'], |
67 |
|
|
], |
68 |
|
|
'rusname' => 'Пользователь', |
69 |
|
|
'db_field' => 'type', |
70 |
|
|
'db_type' => 'integer', |
71 |
|
|
'db_opts' => 'default 0', |
72 |
|
|
}, |
73 |
|
|
{ # Пользователь... |
74 |
|
|
'attr' => 'uid', |
75 |
|
|
'type' => 'integer', |
76 |
|
|
'rusname' => 'Пользователь', |
77 |
|
|
'db_field' => 'uid', |
78 |
|
|
'db_type' => 'integer', |
79 |
|
|
'db_opts' => 'not null', |
80 |
|
|
}, |
81 |
|
|
{ # Количество записей... |
82 |
|
|
'attr' => 'records', |
83 |
|
|
'type' => 'checkbox', |
84 |
|
|
'rusname' => 'Количество записей в блоге', |
85 |
|
|
'hidden' => 1, |
86 |
|
|
'db_field' => 'records', |
87 |
|
|
'db_type' => 'integer', |
88 |
|
|
'db_opts' => 'not null', |
89 |
|
|
}, |
90 |
|
|
{ # Участники... |
91 |
|
|
'attr' => 'members', |
92 |
|
|
'type' => 'text', |
93 |
|
|
'rusname' => 'Участники', |
94 |
|
|
'hidden' => 1, |
95 |
|
|
'db_field' => 'members', |
96 |
|
|
'db_type' => 'integer[]', |
97 |
|
|
}, |
98 |
|
|
{ # Читатели... |
99 |
|
|
'attr' => 'readers', |
100 |
|
|
'type' => 'text', |
101 |
|
|
'rusname' => 'Читатели', |
102 |
|
|
'hidden' => 1, |
103 |
|
|
'db_field' => 'readers', |
104 |
|
|
'db_type' => 'integer[]', |
105 |
|
|
}, |
106 |
|
|
{ # Модераторы... |
107 |
|
|
'attr' => 'moderators', |
108 |
|
|
'type' => 'checkbox', |
109 |
|
|
'rusname' => 'Модераторы', |
110 |
|
|
'hidden' => 1, |
111 |
|
|
'db_field' => 'moderators', |
112 |
|
|
'db_type' => 'integer[]', |
113 |
|
|
}, |
114 |
|
|
); |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
sub _uid_filter { |
118 |
|
|
my ($self,%opts)=@_; |
119 |
|
|
return undef unless ( exists $opts{uid} && $opts{uid} ); |
120 |
|
|
return &SQL::Common::_generic_int_filter('d.uid', $opts{uid}); |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
sub _type_filter { |
124 |
|
|
my ($self,%opts)=@_; |
125 |
|
|
return undef unless ( exists $opts{type} ); |
126 |
|
|
return &SQL::Common::_generic_int_filter('d.type', $opts{type}); |
127 |
|
|
} |
128 |
|
|
|
129 |
235 |
ahitrov |
sub _alias_filter { |
130 |
|
|
my ($self,%opts)=@_; |
131 |
|
|
return undef unless ( exists $opts{alias} ); |
132 |
|
|
return &SQL::Common::_generic_text_filter('d.alias', $opts{alias}); |
133 |
|
|
} |
134 |
234 |
ahitrov |
|
135 |
235 |
ahitrov |
|
136 |
234 |
ahitrov |
sub _link_filter { |
137 |
|
|
my ($self,%opts)=@_; |
138 |
|
|
|
139 |
|
|
my @wheres=(); |
140 |
|
|
my @binds=(); |
141 |
|
|
|
142 |
|
|
# Связь определенного класса |
143 |
|
|
if (exists($opts{lclass})) { |
144 |
|
|
my ($where, $values) = SQL::Common::_generic_text_filter('l.class', $opts{lclass}); |
145 |
|
|
push (@wheres, $where); |
146 |
|
|
push @binds, (ref $values ? @$values : $values) if defined $values; |
147 |
|
|
} |
148 |
|
|
|
149 |
|
|
my $lclass = $opts{lclass} || 'Contenido::Link'; |
150 |
|
|
my $link_table = $lclass->_get_table->db_table(); |
151 |
|
|
|
152 |
|
|
# Ограничение по статусу связи |
153 |
|
|
if ( exists $opts{lstatus} ) { |
154 |
|
|
my ($where, $values) = SQL::Common::_generic_int_filter('l.status', $opts{lstatus}); |
155 |
|
|
push (@wheres, $where); |
156 |
|
|
push (@binds, ref($values) ? @$values:$values) if (defined $values); |
157 |
|
|
} |
158 |
|
|
|
159 |
|
|
# Связь с определенным документ(ом/тами) по цели линка |
160 |
|
|
if ( exists $opts{ldest} ) { |
161 |
|
|
my ($where, $values) = SQL::Common::_generic_int_filter('l.dest_id', $opts{ldest}); |
162 |
|
|
push (@wheres, $where); |
163 |
|
|
push (@binds, ref($values) ? @$values:$values) if (defined $values); |
164 |
|
|
if ( $self->_single_class || $opts{lclass} eq 'blogs::MemberLink' ) { |
165 |
|
|
return (\@wheres, \@binds, " join $link_table as l on l.source_id=d.id"); |
166 |
|
|
} else { |
167 |
|
|
return (\@wheres, \@binds, " join $link_table as l on l.source_id=d.id and l.source_class=d.class"); |
168 |
|
|
} |
169 |
|
|
} |
170 |
|
|
|
171 |
|
|
# Связь с определенным документ(ом/тами) по источнику линка |
172 |
|
|
if ( exists $opts{lsource} ) { |
173 |
|
|
my ($where, $values) = SQL::Common::_generic_int_filter('l.source_id', $opts{lsource}); |
174 |
|
|
push (@wheres, $where); |
175 |
|
|
push (@binds, ref($values) ? @$values:$values) if (defined $values); |
176 |
|
|
if ( $self->_single_class || $opts{lclass} eq 'blogs::MemberLink' ) { |
177 |
|
|
return (\@wheres, \@binds, " join $link_table as l on l.dest_id=d.id"); |
178 |
|
|
} else { |
179 |
|
|
return (\@wheres, \@binds, " join $link_table as l on l.dest_id=d.id and l.dest_class=d.class"); |
180 |
|
|
} |
181 |
|
|
} |
182 |
|
|
|
183 |
|
|
return (undef); |
184 |
|
|
} |
185 |
|
|
|
186 |
|
|
|
187 |
|
|
1; |
188 |
|
|
|