lib/Rapi/Blog/DB/ResultSet/User.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 67 CC 5 SCAR 24.8
CC
5
Cov
0%
list_users
30.0
enabled
2.0
authors
2.0
CRAP 12.0
1 package Rapi::Blog::DB::ResultSet::User;
2  
3 use strict;
4 use warnings;
5  
6 use Moo;
7 extends 'DBIx::Class::ResultSet';
8  
9 use RapidApp::Util ':all';
10  
11 sub enabled {
12 (shift)
13 ->search_rs({ 'me.disabled' => 0 })
14 }
15  
16 sub authors {
17 (shift)
18 ->search_rs({ -or => [{ 'me.author' => 1 },{ 'me.admin' => 1 }]})
19 }
20  
21 sub commenters {
22 (shift)
23 ->search_rs({ -or => [{ 'me.comment' => 1 },{ 'me.admin' => 1 }]})
24 }
25  
26 __PACKAGE__->load_components('+Rapi::Blog::DB::Component::ResultSet::ListAPI');
27  
28 sub _api_default_params {{ limit => 200, only => 'authors' }}
29 sub _api_param_arg_order { [qw/search only/] }
30  
31 # Method exposed to templates:
32 sub list_users {
33 my ($self, @args) = @_;
34
35 my $P = $self->_list_api_params(@args);
36
37 my $Rs = $self;
38
39 if($P->{only}) {
40 if($P->{only} eq 'authors') {
41 $Rs = $Rs->authors;
42 }
43 elsif($P->{only} eq 'commenters') {
44 $Rs = $Rs->commenters;
45 }
46 }
47
48 $Rs = $Rs->search_rs({ -or => [
49 { 'me.username' => { like => join('','%',$P->{search},'%') } },
50 { 'me.full_name' => { like => join('','%',$P->{search},'%') } },
51 ]}) if ($P->{search});
52
53 return $Rs->_list_api;
54 }
55  
56  
57 1;