]> git.imager.perl.org - bse.git/blob - site/cgi-bin/modules/Article.pm
7d18a8d280c4e0f40f954ecd47ae4ea00d0c099e
[bse.git] / site / cgi-bin / modules / Article.pm
1 package Article;
2 use strict;
3 # represents an article from the database
4 use Squirrel::Row;
5 use vars qw/@ISA/;
6 @ISA = qw/Squirrel::Row/;
7
8 sub 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 flags/;
13 }
14
15 sub step_parents {
16   my ($self) = @_;
17
18   Articles->getSpecial('stepParents', $self->{id});
19 }
20
21 sub 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
29 sub stepkids {
30   my ($self) = @_;
31
32   if ($self->{generator} eq 'Generate::Catalog') {
33     require 'Products.pm';
34     return Products->getSpecial('stepProducts', $self->{id});
35   }
36   else {
37     return Articles->getSpecial('stepKids', $self->{id});
38   }
39   return ();
40 }
41
42 sub visible_stepkids {
43   my ($self) = @_;
44
45   use BSE::Util::SQL qw/now_sqldate/;
46   my $today = now_sqldate();
47
48   if ($self->{generator} eq 'Generate::Catalog') {
49     require 'Products.pm';
50
51     return Products->getSpecial('visibleStep', $self->{id}, $today);
52   }
53   else {
54     return Articles->getSpecial('visibleStepKids', $self->{id}, $today);
55   }
56   
57   return ();
58 }
59
60 # returns a list of all children in the correct sort order
61 # this is a bit messy
62 sub allkids {
63   my ($self) = @_;
64
65   require 'OtherParents.pm';
66
67   my @otherlinks = OtherParents->getBy(parentId=>$self->{id});
68   my @normalkids = Articles->children($self->{id});
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
81 sub all_visible_kids {
82   my ($self) = @_;
83
84   Articles->all_visible_kids($self->{id});
85 }
86
87 sub images {
88   my ($self) = @_;
89   require Images;
90   Images->getBy(articleId=>$self->{id});
91 }
92
93 sub children {
94   my ($self) = @_;
95
96   return sort { $b->{displayOrder} <=> $b->{displayOrder} } 
97     Articles->children($self->{id});
98 }
99
100 sub files {
101   my ($self) = @_;
102
103   require ArticleFiles;
104   return ArticleFiles->getBy(articleId=>$self->{id});
105 }
106
107 sub parent {
108   my ($self) = @_;
109   $self->{parentid} == -1 and return;
110   return Articles->getByPkey($self->{parentid});
111 }
112
113 1;