1 |
234 |
ahitrov |
package blogs::SQL::TagsTable; |
2 |
|
|
|
3 |
|
|
use strict; |
4 |
|
|
use base 'SQL::DocumentTable'; |
5 |
|
|
|
6 |
|
|
sub db_table |
7 |
|
|
{ |
8 |
|
|
return 'blog_tags'; |
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 |
|
|
_s_filter |
21 |
|
|
|
22 |
|
|
_excludes_filter |
23 |
|
|
_link_filter |
24 |
|
|
_uid_filter |
25 |
|
|
); |
26 |
|
|
return \@available_filters; |
27 |
|
|
} |
28 |
|
|
|
29 |
|
|
# ---------------------------------------------------------------------------- |
30 |
|
|
# Свойства храним в массивах, потому что порядок важен! |
31 |
|
|
# Это общие свойства - одинаковые для всех документов. |
32 |
|
|
# |
33 |
|
|
# attr - обязательный параметр, название атрибута; |
34 |
|
|
# type - тип аттрибута, требуется для отображдения; |
35 |
|
|
# rusname - русское название, опять же требуется для отображения; |
36 |
|
|
# hidden - равен 1, когда |
37 |
|
|
# readonly - инициализации при записи только без изменения в дальнейшем |
38 |
|
|
# db_field - поле в таблице |
39 |
|
|
# default - значение по умолчанию (поле всегда имеет это значение) |
40 |
|
|
# ---------------------------------------------------------------------------- |
41 |
|
|
sub required_properties |
42 |
|
|
{ |
43 |
|
|
my $self = shift; |
44 |
|
|
|
45 |
|
|
my @parent_properties = grep { $_->{attr} ne 'dtime' && $_->{attr} ne 'sections' } $self->SUPER::required_properties; |
46 |
|
|
return ( |
47 |
|
|
@parent_properties, |
48 |
|
|
{ # Пользователь... |
49 |
|
|
'attr' => 'uid', |
50 |
|
|
'type' => 'integer', |
51 |
|
|
'rusname' => 'Пользователь', |
52 |
|
|
'hidden' => 1, |
53 |
|
|
'db_field' => 'uid', |
54 |
|
|
'db_type' => 'integer', |
55 |
|
|
'db_opts' => 'not null', |
56 |
|
|
}, |
57 |
|
|
{ # Количество записей... |
58 |
|
|
'attr' => 'rate', |
59 |
|
|
'type' => 'checkbox', |
60 |
|
|
'rusname' => 'Количество упоминаний в блогах', |
61 |
|
|
'hidden' => 1, |
62 |
|
|
'default' => 0, |
63 |
|
|
'db_field' => 'rate', |
64 |
|
|
'db_type' => 'integer', |
65 |
|
|
'db_opts' => 'default 0', |
66 |
|
|
}, |
67 |
|
|
{ # Массив секций, обрабатывается специальным образом... |
68 |
|
|
'attr' => 'sections', |
69 |
|
|
'type' => 'sections_list', |
70 |
|
|
'rusname' => 'Секции', |
71 |
|
|
'hidden' => 1, |
72 |
|
|
'db_field' => 'sections', |
73 |
|
|
'db_type' => 'integer', |
74 |
|
|
}, |
75 |
|
|
); |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
|
79 |
|
|
sub _uid_filter { |
80 |
|
|
my ($self,%opts)=@_; |
81 |
|
|
return undef unless ( exists $opts{uid} && $opts{uid} ); |
82 |
|
|
return &SQL::Common::_generic_int_filter('d.uid', $opts{uid}); |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
|
86 |
|
|
sub _s_filter { |
87 |
|
|
my ($self,%opts)=@_; |
88 |
|
|
return undef unless ( exists $opts{s} ); |
89 |
|
|
return &SQL::Common::_generic_int_filter('d.sections', $opts{s}); |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
|
93 |
|
|
sub _link_filter { |
94 |
|
|
my ($self,%opts)=@_; |
95 |
|
|
|
96 |
|
|
my @wheres=(); |
97 |
|
|
my @binds=(); |
98 |
|
|
|
99 |
|
|
# Связь определенного класса |
100 |
|
|
if (exists($opts{lclass})) { |
101 |
|
|
my ($where, $values) = SQL::Common::_generic_text_filter('l.class', $opts{lclass}); |
102 |
|
|
push (@wheres, $where); |
103 |
|
|
push @binds, (ref $values ? @$values : $values) if defined $values; |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
my $lclass = $opts{lclass} || 'Contenido::Link'; |
107 |
|
|
my $link_table = $lclass->_get_table->db_table(); |
108 |
|
|
|
109 |
|
|
# Ограничение по статусу связи |
110 |
|
|
if ( exists $opts{lstatus} ) { |
111 |
|
|
my ($where, $values) = SQL::Common::_generic_int_filter('l.status', $opts{lstatus}); |
112 |
|
|
push (@wheres, $where); |
113 |
|
|
push (@binds, ref($values) ? @$values:$values) if (defined $values); |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
# Связь с определенным документ(ом/тами) по цели линка |
117 |
|
|
if ( exists $opts{ldest} ) { |
118 |
|
|
my ($where, $values) = SQL::Common::_generic_int_filter('l.dest_id', $opts{ldest}); |
119 |
|
|
push (@wheres, $where); |
120 |
|
|
push (@binds, ref($values) ? @$values:$values) if (defined $values); |
121 |
|
|
if ( $self->_single_class || $opts{lclass} eq 'blogs::TagCloud' ) { |
122 |
|
|
return (\@wheres, \@binds, " join $link_table as l on l.source_id=d.id"); |
123 |
|
|
} else { |
124 |
|
|
return (\@wheres, \@binds, " join $link_table as l on l.source_id=d.id and l.source_class=d.class"); |
125 |
|
|
} |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
# Связь с определенным документ(ом/тами) по источнику линка |
129 |
|
|
if ( exists $opts{lsource} ) { |
130 |
|
|
my ($where, $values) = SQL::Common::_generic_int_filter('l.source_id', $opts{lsource}); |
131 |
|
|
push (@wheres, $where); |
132 |
|
|
push (@binds, ref($values) ? @$values:$values) if (defined $values); |
133 |
|
|
if ( $self->_single_class || $opts{lclass} eq 'blogs::TagCloud' ) { |
134 |
|
|
return (\@wheres, \@binds, " join $link_table as l on l.dest_id=d.id"); |
135 |
|
|
} else { |
136 |
|
|
return (\@wheres, \@binds, " join $link_table as l on l.dest_id=d.id and l.dest_class=d.class"); |
137 |
|
|
} |
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
return (undef); |
141 |
|
|
} |
142 |
|
|
|
143 |
|
|
|
144 |
|
|
1; |
145 |
|
|
|