Added resultset for leaderboard for more consice code
This commit is contained in:
parent
7e11fc50bd
commit
5e06f0a69b
3 changed files with 323 additions and 0 deletions
42
lib/Pear/LocalLoop/Schema/ResultSet/Leaderboard.pm
Normal file
42
lib/Pear/LocalLoop/Schema/ResultSet/Leaderboard.pm
Normal file
|
@ -0,0 +1,42 @@
|
|||
package Pear::LocalLoop::Schema::ResultSet::Leaderboard;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base 'DBIx::Class::ResultSet';
|
||||
|
||||
sub get_latest {
|
||||
my $self = shift;
|
||||
my $type = shift;
|
||||
|
||||
my $type_result = $self->find_by_type( $type );
|
||||
|
||||
return undef unless defined $type_result;
|
||||
|
||||
my $latest = $type_result->search_related('sets', {}, {
|
||||
order_by => { -desc => 'date' },
|
||||
})->first;
|
||||
|
||||
return $latest;
|
||||
}
|
||||
|
||||
sub create_new {
|
||||
my $self = shift;
|
||||
my $type = shift;
|
||||
my $date = shift;
|
||||
|
||||
my $type_result = $self->find_by_type($type);
|
||||
|
||||
return undef unless $type_result;
|
||||
|
||||
return $type_result->create_new($date);
|
||||
}
|
||||
|
||||
sub find_by_type {
|
||||
my $self = shift;
|
||||
my $type = shift;
|
||||
|
||||
return $self->find({ type => $type });
|
||||
}
|
||||
|
||||
1;
|
Reference in a new issue