root/veekun/trunk/lib/Vee/Controller/Index.pm @ 406

Revision 406, 4.0 KB (checked in by eevee, 22 months ago)

Database refactoring. Renamed columns and tables to be more consistent and more readable. (#58)

Line 
1package Vee::Controller::Index;
2
3use strict;
4use warnings;
5use base 'Catalyst::Controller';
6
7use DateTime;
8
9__PACKAGE__->config->{namespace} = '';
10
11=head1 NAME
12
13Vee::Controller::Index - Index Controller
14
15=head1 SYNOPSIS
16
17See L<Vee>.
18
19=head1 DESCRIPTION
20
21Catalyst Controller for the index page.
22
23=head1 METHODS
24
25=cut
26
27=head2 root
28
29=cut
30
31my $shoutbox_fields = {
32    name => { type => 'text', size => 20, maxlength => 20 },
33    content => { type => 'textarea', rows => 3, cols => 20 },
34};
35
36sub index : Path {
37    my ($self, $c) = @_;
38
39    my $s = $c->stash;
40    $s->{page_title} = 'Home/News';
41    $s->{link_name}  = 'main';
42    $s->{extra_css}  = [ 'index', 'bbcode' ];
43
44    my $news_forum = $c->model('DBIC::Forums')->find( $c->site_opts->{special_forums}{news} );
45    my $page_sizes = $c->site_opts->{page_sizes}{index};
46
47    $s->{recent_news}   = $news_forum->threads( undef, { prefetch => 'first_post', order_by => 'me.id DESC', rows => $page_sizes->{news} } );
48    $s->{recent_news}   = $s->{recent_news}->search(\ 'NOT FIND_IN_SET("deleted", me.flags)') unless $c->can_i(override_thread_deleted => $news_forum->id);
49
50    $s->{recent_shouts} = $c->model('DBIC::Shoutbox')->search( undef, { order_by => 'me.time DESC', rows => $page_sizes->{shoutbox} } );
51    $s->{recent_art}    = $c->model('DBIC::Gallery')->search( undef, { order_by => 'me.time DESC', rows => $page_sizes->{gallery} } );
52
53    # TODO: break this off into a "new posts" sort of page, and just put NEW THREADS here
54    my $threads_rs     = $c->model('DBIC::Threads')->search;
55    $threads_rs        = $threads_rs->search({ 'me.flags' => { '!=', 'deleted' } }) unless $c->can_i('override_thread_deleted');
56    $s->{recent_posts} = $threads_rs->search( undef, {
57        order_by => 'last_post.time DESC',
58        rows => $page_sizes->{forum},
59        prefetch => { last_post => 'user' },
60    } );
61
62    # NOT FIND_IN_SET breaks here; why?
63    $s->{recent_posts}  = $s->{recent_posts}->search({ 'last_post.flags' => { '!=', 'deleted' } }) unless $c->can_i('override_thread_deleted');
64
65    # Grab a list of unread threads
66    if ($c->user) {
67        my @unread_ids  = $threads_rs->unread_ids($c->user->obj);
68        my %unread_hash = map { $_ => 1 } @unread_ids;
69
70        $s->{is_unread} = sub { $unread_hash{$_[0]->id} };
71    }
72       
73    # check for latest subversion revision every 15 minutes or so
74    if (not $c->cache->{svn} or $c->cache->{svn}{last_checked} < time - 15 * 60) {
75        eval {
76            open my $svn_fh, '-|', 'svn', 'log', '--limit' => 1, '--incremental', $c->site_opts->{svn_url};
77            my (undef, $details, undef, @log) = <$svn_fh>;
78            close $svn_fh;
79            my ($rev, $user, $time, undef) = split / \| /, $details;
80            $rev =~ s/^r//;
81            my ($yr, $mo, $day, $hr, $min, $sec, $tz) = split /[- :]/, $time, 7;
82
83            $c->cache->{svn} = {
84                revision     => $rev,
85                user         => $user,
86                time         => new DateTime(
87                    year   => $yr,
88                    month  => $mo,
89                    day    => $day,
90                    hour   => $hr,
91                    minute => $min,
92                    second => $sec,
93                    time_zone => substr $tz, 0, 5,
94                ),
95                last_checked => time,
96                log          => join '', @log,
97            }
98        };
99    }
100
101    $s->{recent_revision} = $c->cache->{svn};
102
103    $s->{recent_users} = $c->model('DBIC::Users')->search(
104        { time_active => { '>', time - $c->site_opts->{user_activity_timeout} } },
105        { order_by => 'me.time_active DESC' }
106    );   
107
108    my $shoutbox_form = Vee::Form->new(
109        id => 'shoutbox',
110        fields => $shoutbox_fields,
111        params => $c->req->params,
112    );
113
114    if ($c->user) {
115        $shoutbox_form->force( name => $c->user->name );
116    }
117    $s->{shoutbox_form} = $shoutbox_form;
118
119    $s->{template} = 'index.tt';
120}
121
122=head1 AUTHOR
123
124Maintainer: Alex "Eevee" Munroe (C<veekun@veekun.com>)
125
126See the included F<AUTHORS> file for a full list of contributers.
127
128=head1 LICENSE
129
130See the included F<LICENSE> file.
131
132=cut
133
1341;
Note: See TracBrowser for help on using the browser.