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