/[Frey]/trunk/lib/Frey/DBIC/Browser.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/Frey/DBIC/Browser.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1015 - (show annotations)
Sun Jan 25 15:20:40 2009 UTC (15 years, 3 months ago) by dpavlin
File size: 1764 byte(s)
configurable attributes, display only published items using join
1 package Frey::DBIC::Browser;
2 use Moose;
3
4 extends 'Frey';
5 with 'Frey::Web';
6 with 'Frey::Config';
7 #with 'Frey::Storage';
8
9 has dbic_class => (
10 is => 'rw',
11 isa => 'Str',
12 requried => 1,
13 default => 'Reblog',
14 );
15
16 has dsn => (
17 is => 'rw',
18 isa => 'Str',
19 required => 1,
20 default => 'DBI:mysql:database=reblog;host=127.0.0.1;port=13306',
21 );
22
23 has table => (
24 is => 'rw',
25 isa => 'Str',
26 required => 1,
27 default => 'Items',
28 );
29
30 has order_by => (
31 is => 'rw',
32 isa => 'Str',
33 required => 1,
34 default => 'timestamp desc',
35 );
36
37 has page => (
38 is => 'rw',
39 isa => 'Int',
40 required => 1,
41 default => 1,
42 );
43
44 sub as_sponge {
45 my ($self) = @_;
46
47 my $dbic_class = $self->dbic_class;
48 my $dsn = $self->dsn;
49 my $schema;
50
51 my $code = qq{
52 use $dbic_class ;
53 \$schema = $dbic_class->connect("$dsn", '', '');
54 };
55
56 eval $code;
57 die $@ if $@;
58
59 $schema->storage->debug(1); # XXX dump storage generated SQL
60
61 my $attrs;
62
63 $attrs->{ $_ } = $self->$_ foreach ( grep { $self->$_ } ( qw/page order_by/ ) );
64 warn "# attrs ", $self->dump( $attrs );
65
66
67 my $rs = $schema->resultset( $self->table )
68 # ->search( undef, $attrs )
69 ->search({
70 'userdata.label' => 'published',
71 'userdata.value_numeric' => 1,
72 }, {
73 join => [ 'userdata' ],
74 %$attrs
75 })
76 ;
77
78 my @rows;
79 my @name;
80 my $name_pos;
81
82 while ( my $feed = $rs->next ) {
83 my %row = $feed->get_columns;
84
85 my @row;
86
87 foreach my $name ( $feed->columns ) {
88 if ( ! defined $name_pos->{$name} ) {
89 push @name, $name;
90 $name_pos->{$name} = $#name;
91 warn "## name_pos: ", $self->dump( $name_pos ) if $self->debug;
92 }
93
94 my $pos = $name_pos->{$name};
95 $row[$pos] = $row{$name};
96 }
97
98 push @rows, [ @row ];
99 }
100
101 return {
102 rows => \@rows,
103 NAME => \@name,
104 total_entries => $rs->pager->total_entries,
105 }
106 }
107
108 1;

  ViewVC Help
Powered by ViewVC 1.1.26