Line # Revision Author
1 234 ahitrov package blogs::Record;
2
3 use base "Contenido::Document";
4 use Encode;
5 use Contenido::Globals;
6
7 sub extra_properties
8 {
9 return (
10 { 'attr' => 'name', 'type' => 'string', 'rusname' => 'Сабж / настроение' },
11 { 'attr' => 'status', 'type' => 'status', 'rusname' => 'Статус записи',
12 'cases' => [
13 [0, 'Запись неактивна'],
14 [1, 'Запись активна'],
15 [2, 'Запись вынесена в топ блога'],
16 [3, 'Запись вынесена на главную страницу'],
17 ],
18 },
19 { 'attr' => 'abstr', 'type' => 'wysiwyg', 'rusname' => 'Начало записи', 'rows' => 10 },
20 { 'attr' => 'body', 'type' => 'wysiwyg', 'rusname' => 'Текст под катом', 'rows' => 30 },
21 { 'attr' => 'author', 'type' => 'string', 'rusname' => 'Имя автора сообщения', },
22 { 'attr' => 'video', 'type' => 'text', 'rusname' => 'Поле для вставки HTML-кода видео', 'rows' => 10 },
23 { 'attr' => 'pictures', 'type' => 'images', 'rusname' => 'Список картинок', preview => ['300x300','250x250','200x200','150x150','120x120','100x100'] },
24 )
25 }
26
27 sub class_name
28 {
29 return 'Запись блога';
30 }
31
32 sub class_description
33 {
34 return 'Запись блога';
35 }
36
37
38 sub class_table
39 {
40 return 'blogs::SQL::RecordsTable';
41 }
42
43 sub contenido_status_style
44 {
45 my $self = shift;
46 if ( $self->status == 2 ) {
47 return 'color:green;';
48 } elsif ( $self->status == 3 ) {
49 return 'color:olive;';
50 } elsif ( $self->status == 4 ) {
51 return 'color:green;';
52 } elsif ( $self->status == 5 ) {
53 return 'color:red;';
54 }
55 }
56
57 sub search_fields
58 {
59 return ('tags', 'name');
60 }
61
62 sub table_links
63 {
64 return [
65 { name => 'Комменты', class => 'blogs::Comment', filter => 'record_id', field => 'record_id' },
66 ];
67 }
68
69 sub pre_store
70 {
71 my $self = shift;
72
73 if ( !$self->id && !$self->uid ) {
74 if ( ref $session && exists $session->{id} && $session->{id} ) {
75 $self->uid( $session->{id} );
76 } elsif ( ref $user ) {
77 $self->uid( $user->id );
78 }
79 }
80
81 my $default_section = $project->s_alias->{blog_records} if ref $project->s_alias eq 'HASH' && exists $project->s_alias->{blog_records};
82 if ( $default_section ) {
83 my $sections = $self->{sections};
84 if ( ref $sections eq 'ARRAY' && scalar @$sections ) {
85 my @new_sects = grep { $_ != $default_section } @$sections;
86 push @new_sects, $default_section;
87 $self->sections(@new_sects);
88 } elsif ( $sections && !ref $sections && $sections != $default_section ) {
89 my @new_sects = ($default_section, $sections);
90 $self->sections(@new_sects);
91 } else {
92 $self->sections($default_section);
93 }
94 }
95
96 return 1;
97 }
98
99
100 sub post_store
101 {
102 my $self = shift;
103
104 my @links = $self->keeper->get_links(
105 class => 'blogs::TagCloud',
106 dest_id => $self->id,
107 );
108 foreach my $link ( @links ) {
109 $link->delete();
110 }
111 if ( $self->tags ) {
112 my @tags = map { encode('utf-8', lc($_)) } split /[\t\ ]*,[\t\ ]*/, decode("utf-8", $self->tags);
113 foreach my $tag ( @tags ) {
114 my ($tid) = $self->keeper->get_documents(
115 name => $tag,
116 ilike => 1,
117 class => 'blogs::Tag',
118 ids => 1,
119 limit => 1,
120 );
121 unless ( $tid ) {
122 my $tobj = blogs::Tag->new( $self->keeper );
123 $tobj->name( $tag );
124 $tobj->status( 1 );
125 $tobj->store;
126 $tid = $tobj->id;
127 }
128 my $link = blogs::TagCloud->new( $keeper );
129 $link->status( 1 );
130 $link->source_id( $tid );
131 $link->source_class( 'blogs::Tag' );
132 $link->dest_id( $self->id );
133 $link->dest_class( $self->class );
134 $link->store;
135 }
136 }
137
138 1;
139 }
140
141
142 sub pre_delete
143 {
144 my $self = shift;
145
146 my $comments_db_table = blogs::SQL::CommentsTable->db_table;
147 my $sthcom = $self->keeper->SQL->prepare( "delete from $comments_db_table where record_id = ?" );
148 $sthcom->execute( $self->id );
149 $sthcom->finish;
150
151 my $tags_db_table = blogs::SQL::TagsTable->db_table;
152 my $sthtag = $self->keeper->SQL->prepare( "delete from $comments_db_table where dest_id = ? and dest_class = ?" );
153 $sthtag->execute( $self->id, $self->class );
154 $sthtag->finish;
155
156 1;
157 }
158
159 1;