]> git.imager.perl.org - bse.git/blame - site/cgi-bin/modules/Article.pm
0.12_09 commit
[bse.git] / site / cgi-bin / modules / Article.pm
CommitLineData
41b9d8ec 1package Article;
9d29b58f 2use strict;
41b9d8ec
TC
3# represents an article from the database
4use Squirrel::Row;
5use vars qw/@ISA/;
6@ISA = qw/Squirrel::Row/;
7
8sub columns {
9 return qw/id parentid displayOrder title titleImage body
10 thumbImage thumbWidth thumbHeight imagePos
11 release expire keyword template link admin threshold
12 summaryLength generator level listed lastModified/;
13}
14
9d29b58f
TC
15sub step_parents {
16 my ($self) = @_;
17
18 Articles->getSpecial('stepParents', $self->{id});
19}
20
99ef7979
TC
21sub visible_step_parents {
22 my ($self) = @_;
23
24 use BSE::Util::SQL qw/now_datetime/;
25 my $now = now_datetime();
26 grep $_->{release} le $now && $now le $_->{expire}, $self->step_parents;
27}
28
29sub stepkids {
30 my ($self) = @_;
31
32 if ($self->{generator} eq 'Generate::Catalog') {
33 require 'Products.pm';
34 return Products->getSpecial('stepProducts', $self->{id});
35 }
721cd24c
TC
36 else {
37 return Articles->getSpecial('stepKids', $self->{id});
38 }
99ef7979
TC
39 return ();
40}
41
42sub visible_stepkids {
43 my ($self) = @_;
44
721cd24c
TC
45 use BSE::Util::SQL qw/now_sqldate/;
46 my $today = now_sqldate();
47
99ef7979 48 if ($self->{generator} eq 'Generate::Catalog') {
99ef7979 49 require 'Products.pm';
99ef7979
TC
50
51 return Products->getSpecial('visibleStep', $self->{id}, $today);
52 }
721cd24c
TC
53 else {
54 return Articles->getSpecial('visibleStepKids', $self->{id}, $today);
55 }
99ef7979
TC
56
57 return ();
58}
59
60# returns a list of all children in the correct sort order
61# this is a bit messy
62sub allkids {
63 my ($self) = @_;
64
65 require 'OtherParents.pm';
66
67 my @otherlinks = OtherParents->getBy(parentId=>$self->{id});
99d2c4a9 68 my @normalkids = Articles->children($self->{id});
99ef7979
TC
69 my %order = (
70 (map { $_->{id}, $_->{displayOrder} } @normalkids ),
71 (map { $_->{childId}, $_->{parentDisplayOrder} } @otherlinks),
72 );
73 my @stepkids = $self->stepkids;
74 my %kids = map { $_->{id}, $_ } @stepkids, @normalkids;
75
76 return @kids{ sort { $order{$b} <=> $order{$a} } keys %kids };
77}
78
79# returns a list of all visible children in the correct sort order
80# this is a bit messy
81sub all_visible_kids {
82 my ($self) = @_;
83
84 require 'OtherParents.pm';
85
86 my @otherlinks = OtherParents->getBy(parentId=>$self->{id});
99d2c4a9 87 my @normalkids = Articles->listedChildren($self->{id});
99ef7979
TC
88 my %order = (
89 (map { $_->{id}, $_->{displayOrder} } @normalkids ),
99d2c4a9 90 (map { $_->{childId}, $_->{parentDisplayOrder} } @otherlinks),
99ef7979
TC
91 );
92 my @stepkids = $self->visible_stepkids;
93 my %kids = map { $_->{id}, $_ } @stepkids, @normalkids;
94
95 return @kids{ sort { $order{$b} <=> $order{$a} } keys %kids };
96}
97
ca9aa2bf
TC
98sub images {
99 my ($self) = @_;
100 require Images;
101 Images->getBy(articleId=>$self->{id});
102}
103
104sub children {
105 my ($self) = @_;
106
107 return sort { $b->{displayOrder} <=> $b->{displayOrder} }
108 Articles->children($self->{id});
109}
110
111sub files {
112 my ($self) = @_;
113
114 require ArticleFiles;
115 return ArticleFiles->getBy(articleId=>$self->{id});
116}
117
08123550
TC
118sub parent {
119 my ($self) = @_;
120 $self->{parentid} == -1 and return;
121 return Articles->getByPkey($self->{parentid});
122}
123
41b9d8ec 1241;