| 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 |
|
|
); |
| 31 |
|
|
return \@available_filters; |
| 32 |
|
|
} |
| 33 |
|
|
|
| 34 |
|
|
# ---------------------------------------------------------------------------- |
| 35 |
|
|
# Свойства храним в массивах, потому что порядок важен! |
| 36 |
|
|
# Это общие свойства - одинаковые для всех документов. |
| 37 |
|
|
# |
| 38 |
|
|
# attr - обязательный параметр, название атрибута; |
| 39 |
|
|
# type - тип аттрибута, требуется для отображдения; |
| 40 |
|
|
# rusname - русское название, опять же требуется для отображения; |
| 41 |
|
|
# hidden - равен 1, когда |
| 42 |
|
|
# readonly - инициализации при записи только без изменения в дальнейшем |
| 43 |
|
|
# db_field - поле в таблице |
| 44 |
|
|
# default - значение по умолчанию (поле всегда имеет это значение) |
| 45 |
|
|
# ---------------------------------------------------------------------------- |
| 46 |
|
|
sub required_properties |
| 47 |
|
|
{ |
| 48 |
|
|
my $self = shift; |
| 49 |
|
|
|
| 50 |
|
|
my @parent_properties = $self->SUPER::required_properties; |
| 51 |
|
|
return ( |
| 52 |
|
|
@parent_properties, |
| 53 |
|
|
{ # Тип блога... |
| 54 |
|
|
'attr' => 'type', |
| 55 |
|
|
'type' => 'status', |
| 56 |
|
|
'cases' => [ |
| 57 |
|
|
[0, 'Личный блог'], |
| 58 |
|
|
[1, 'Групповой блог'], |
| 59 |
|
|
], |
| 60 |
|
|
'rusname' => 'Пользователь', |
| 61 |
|
|
'db_field' => 'type', |
| 62 |
|
|
'db_type' => 'integer', |
| 63 |
|
|
'db_opts' => 'default 0', |
| 64 |
|
|
}, |
| 65 |
|
|
{ # Пользователь... |
| 66 |
|
|
'attr' => 'uid', |
| 67 |
|
|
'type' => 'integer', |
| 68 |
|
|
'rusname' => 'Пользователь', |
| 69 |
|
|
'db_field' => 'uid', |
| 70 |
|
|
'db_type' => 'integer', |
| 71 |
|
|
'db_opts' => 'not null', |
| 72 |
|
|
}, |
| 73 |
|
|
{ # Количество записей... |
| 74 |
|
|
'attr' => 'records', |
| 75 |
|
|
'type' => 'checkbox', |
| 76 |
|
|
'rusname' => 'Количество записей в блоге', |
| 77 |
|
|
'hidden' => 1, |
| 78 |
|
|
'db_field' => 'records', |
| 79 |
|
|
'db_type' => 'integer', |
| 80 |
|
|
'db_opts' => 'not null', |
| 81 |
|
|
}, |
| 82 |
|
|
{ # Участники... |
| 83 |
|
|
'attr' => 'members', |
| 84 |
|
|
'type' => 'text', |
| 85 |
|
|
'rusname' => 'Участники', |
| 86 |
|
|
'hidden' => 1, |
| 87 |
|
|
'db_field' => 'members', |
| 88 |
|
|
'db_type' => 'integer[]', |
| 89 |
|
|
}, |
| 90 |
|
|
{ # Читатели... |
| 91 |
|
|
'attr' => 'readers', |
| 92 |
|
|
'type' => 'text', |
| 93 |
|
|
'rusname' => 'Читатели', |
| 94 |
|
|
'hidden' => 1, |
| 95 |
|
|
'db_field' => 'readers', |
| 96 |
|
|
'db_type' => 'integer[]', |
| 97 |
|
|
}, |
| 98 |
|
|
{ # Модераторы... |
| 99 |
|
|
'attr' => 'moderators', |
| 100 |
|
|
'type' => 'checkbox', |
| 101 |
|
|
'rusname' => 'Модераторы', |
| 102 |
|
|
'hidden' => 1, |
| 103 |
|
|
'db_field' => 'moderators', |
| 104 |
|
|
'db_type' => 'integer[]', |
| 105 |
|
|
}, |
| 106 |
|
|
); |
| 107 |
|
|
} |
| 108 |
|
|
|
| 109 |
|
|
sub _uid_filter { |
| 110 |
|
|
my ($self,%opts)=@_; |
| 111 |
|
|
return undef unless ( exists $opts{uid} && $opts{uid} ); |
| 112 |
|
|
return &SQL::Common::_generic_int_filter('d.uid', $opts{uid}); |
| 113 |
|
|
} |
| 114 |
|
|
|
| 115 |
|
|
sub _type_filter { |
| 116 |
|
|
my ($self,%opts)=@_; |
| 117 |
|
|
return undef unless ( exists $opts{type} ); |
| 118 |
|
|
return &SQL::Common::_generic_int_filter('d.type', $opts{type}); |
| 119 |
|
|
} |
| 120 |
|
|
|
| 121 |
|
|
|
| 122 |
|
|
sub _link_filter { |
| 123 |
|
|
my ($self,%opts)=@_; |
| 124 |
|
|
|
| 125 |
|
|
my @wheres=(); |
| 126 |
|
|
my @binds=(); |
| 127 |
|
|
|
| 128 |
|
|
# Связь определенного класса |
| 129 |
|
|
if (exists($opts{lclass})) { |
| 130 |
|
|
my ($where, $values) = SQL::Common::_generic_text_filter('l.class', $opts{lclass}); |
| 131 |
|
|
push (@wheres, $where); |
| 132 |
|
|
push @binds, (ref $values ? @$values : $values) if defined $values; |
| 133 |
|
|
} |
| 134 |
|
|
|
| 135 |
|
|
my $lclass = $opts{lclass} || 'Contenido::Link'; |
| 136 |
|
|
my $link_table = $lclass->_get_table->db_table(); |
| 137 |
|
|
|
| 138 |
|
|
# Ограничение по статусу связи |
| 139 |
|
|
if ( exists $opts{lstatus} ) { |
| 140 |
|
|
my ($where, $values) = SQL::Common::_generic_int_filter('l.status', $opts{lstatus}); |
| 141 |
|
|
push (@wheres, $where); |
| 142 |
|
|
push (@binds, ref($values) ? @$values:$values) if (defined $values); |
| 143 |
|
|
} |
| 144 |
|
|
|
| 145 |
|
|
# Связь с определенным документ(ом/тами) по цели линка |
| 146 |
|
|
if ( exists $opts{ldest} ) { |
| 147 |
|
|
my ($where, $values) = SQL::Common::_generic_int_filter('l.dest_id', $opts{ldest}); |
| 148 |
|
|
push (@wheres, $where); |
| 149 |
|
|
push (@binds, ref($values) ? @$values:$values) if (defined $values); |
| 150 |
|
|
if ( $self->_single_class || $opts{lclass} eq 'blogs::MemberLink' ) { |
| 151 |
|
|
return (\@wheres, \@binds, " join $link_table as l on l.source_id=d.id"); |
| 152 |
|
|
} else { |
| 153 |
|
|
return (\@wheres, \@binds, " join $link_table as l on l.source_id=d.id and l.source_class=d.class"); |
| 154 |
|
|
} |
| 155 |
|
|
} |
| 156 |
|
|
|
| 157 |
|
|
# Связь с определенным документ(ом/тами) по источнику линка |
| 158 |
|
|
if ( exists $opts{lsource} ) { |
| 159 |
|
|
my ($where, $values) = SQL::Common::_generic_int_filter('l.source_id', $opts{lsource}); |
| 160 |
|
|
push (@wheres, $where); |
| 161 |
|
|
push (@binds, ref($values) ? @$values:$values) if (defined $values); |
| 162 |
|
|
if ( $self->_single_class || $opts{lclass} eq 'blogs::MemberLink' ) { |
| 163 |
|
|
return (\@wheres, \@binds, " join $link_table as l on l.dest_id=d.id"); |
| 164 |
|
|
} else { |
| 165 |
|
|
return (\@wheres, \@binds, " join $link_table as l on l.dest_id=d.id and l.dest_class=d.class"); |
| 166 |
|
|
} |
| 167 |
|
|
} |
| 168 |
|
|
|
| 169 |
|
|
return (undef); |
| 170 |
|
|
} |
| 171 |
|
|
|
| 172 |
|
|
|
| 173 |
|
|
1; |
| 174 |
|
|
|