]> git.imager.perl.org - bse.git/blob - site/cgi-bin/modules/Article.pm
various changes
[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/;
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   return ();
37 }
38
39 sub visible_stepkids {
40   my ($self) = @_;
41
42   if ($self->{generator} eq 'Generate::Catalog') {
43     use BSE::Util::SQL qw/now_sqldate/;
44     require 'Products.pm';
45     my $today = now_sqldate();
46
47     return Products->getSpecial('visibleStep', $self->{id}, $today);
48   }
49   
50   return ();
51 }
52
53 # returns a list of all children in the correct sort order
54 # this is a bit messy
55 sub allkids {
56   my ($self) = @_;
57
58   require 'OtherParents.pm';
59
60   my @otherlinks = OtherParents->getBy(parentId=>$self->{id});
61   my @normalkids = Articles->children($self->{id});
62   my %order = (
63                (map { $_->{id}, $_->{displayOrder} } @normalkids ),
64                (map { $_->{childId}, $_->{parentDisplayOrder} } @otherlinks),
65               );
66   my @stepkids = $self->stepkids;
67   my %kids = map { $_->{id}, $_ } @stepkids, @normalkids;
68
69   return @kids{ sort { $order{$b} <=> $order{$a} } keys %kids };
70 }
71
72 # returns a list of all visible children in the correct sort order
73 # this is a bit messy
74 sub all_visible_kids {
75   my ($self) = @_;
76
77   require 'OtherParents.pm';
78
79   my @otherlinks = OtherParents->getBy(parentId=>$self->{id});
80   my @normalkids = Articles->listedChildren($self->{id});
81   my %order = (
82                (map { $_->{id}, $_->{displayOrder} } @normalkids ),
83                (map { $_->{childId}, $_->{parentDisplayOrder} } @otherlinks),
84               );
85   my @stepkids = $self->visible_stepkids;
86   my %kids = map { $_->{id}, $_ } @stepkids, @normalkids;
87
88   return @kids{ sort { $order{$b} <=> $order{$a} } keys %kids };
89 }
90
91 1;