| 1 | package Vee::Schema::Threads; |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | use base 'DBIx::Class'; |
|---|
| 6 | |
|---|
| 7 | =head1 NAME |
|---|
| 8 | |
|---|
| 9 | Vee::Schema::Threads - DBIC class for the C<threads> table |
|---|
| 10 | |
|---|
| 11 | =cut |
|---|
| 12 | |
|---|
| 13 | __PACKAGE__->load_components(qw/ ResultSetManager Core /); |
|---|
| 14 | __PACKAGE__->table('threads'); |
|---|
| 15 | __PACKAGE__->add_columns(qw/ |
|---|
| 16 | id forumid subject blurb firstpostid lastpostid lasttime postct hitct flags |
|---|
| 17 | /); |
|---|
| 18 | __PACKAGE__->set_primary_key('id'); |
|---|
| 19 | |
|---|
| 20 | __PACKAGE__->belongs_to(forum => 'Vee::Schema::Forums', 'forumid'); |
|---|
| 21 | __PACKAGE__->has_many(posts => 'Vee::Schema::Posts', 'threadid'); |
|---|
| 22 | __PACKAGE__->belongs_to(lastpost => 'Vee::Schema::Posts', 'lastpostid'); |
|---|
| 23 | __PACKAGE__->belongs_to(firstpost => 'Vee::Schema::Posts', 'firstpostid'); |
|---|
| 24 | __PACKAGE__->has_many(thread_views => 'Vee::Schema::ThreadViews', 'thread_id', { join_type => 'LEFT' }); |
|---|
| 25 | |
|---|
| 26 | =head1 METHODS |
|---|
| 27 | |
|---|
| 28 | =head2 search_announcements |
|---|
| 29 | |
|---|
| 30 | Returns a resultset of all the threads flagged as announcements. |
|---|
| 31 | |
|---|
| 32 | =cut |
|---|
| 33 | |
|---|
| 34 | sub search_announcements : ResultSet { |
|---|
| 35 | my ($self) = @_; |
|---|
| 36 | |
|---|
| 37 | return $self->search( |
|---|
| 38 | [ \ 'FIND_IN_SET("announcement", me.flags) AND NOT FIND_IN_SET("deleted", me.flags)' ], |
|---|
| 39 | { prefetch => [ 'forum', { firstpost => 'user', lastpost => 'user' } ] } |
|---|
| 40 | ); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | =head2 read_ids($user) |
|---|
| 44 | |
|---|
| 45 | Returns a list of all thread ids the given user has read. |
|---|
| 46 | |
|---|
| 47 | =cut |
|---|
| 48 | |
|---|
| 49 | sub read_ids : ResultSet { |
|---|
| 50 | my ($self, $user) = @_; |
|---|
| 51 | |
|---|
| 52 | return $self->search( { |
|---|
| 53 | 'thread_views.last_viewed' => \'>= me.lasttime', |
|---|
| 54 | 'thread_views.user_id' => $user->id, |
|---|
| 55 | }, { |
|---|
| 56 | join => 'thread_views', |
|---|
| 57 | columns => [qw[ id ]], |
|---|
| 58 | } )->get_column('id')->all; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | =head1 SEE ALSO |
|---|
| 62 | |
|---|
| 63 | L<Vee::Schema>, L<DBIx::Class> |
|---|
| 64 | |
|---|
| 65 | =head1 AUTHOR |
|---|
| 66 | |
|---|
| 67 | Maintainer: Alex "Eevee" Munroe (C<veekun@veekun.com>) |
|---|
| 68 | |
|---|
| 69 | See the included F<AUTHORS> file for a full list of contributers. |
|---|
| 70 | |
|---|
| 71 | =head1 LICENSE |
|---|
| 72 | |
|---|
| 73 | See the included F<LICENSE> file. |
|---|
| 74 | |
|---|
| 75 | =cut |
|---|
| 76 | |
|---|
| 77 | 1; |
|---|