This repository has been archived on 2023-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
Foodloop-Server/lib/Pear/LocalLoop/Schema/ResultSet/ImportSet.pm

87 lines
1.6 KiB
Perl
Raw Permalink Normal View History

2017-11-13 13:30:33 +00:00
package Pear::LocalLoop::Schema::ResultSet::ImportSet;
use strict;
use warnings;
use base 'DBIx::Class::ResultSet';
sub get_values {
my $self = shift;
my $id = shift;
my $include_ignored = shift;
2017-11-15 18:22:49 +00:00
my $include_imported = shift;
2017-11-13 13:30:33 +00:00
return $self->find($id)->search_related(
'values',
2017-11-15 18:22:49 +00:00
{
( $include_ignored ? () : ( ignore_value => 0 ) ),
( $include_imported ? () : ( transaction_id => undef ) ),
},
2017-11-13 13:30:33 +00:00
{
2017-11-13 19:00:34 +00:00
order_by => { '-asc' => 'id' },
2017-11-13 13:30:33 +00:00
},
);
}
sub _unordered_get_values {
my $self = shift;
my $id = shift;
my $include_ignored = shift;
my $include_imported = shift;
return $self->find($id)->search_related(
'values',
{
( $include_ignored ? () : ( ignore_value => 0 ) ),
( $include_imported ? () : ( transaction_id => undef ) ),
},
);
}
2017-11-13 13:30:33 +00:00
sub get_users {
my $self = shift;
return $self->_unordered_get_values(@_)->search({},
2017-11-13 13:30:33 +00:00
{
group_by => 'user_name',
columns => [ qw/ user_name / ],
2017-11-13 13:30:33 +00:00
},
);
}
sub get_orgs {
my $self = shift;
return $self->_unordered_get_values(@_)->search({},
2017-11-13 13:30:33 +00:00
{
group_by => 'org_name',
columns => [ qw/ org_name / ],
2017-11-13 13:30:33 +00:00
},
);
}
2017-11-13 19:00:34 +00:00
sub get_lookups {
my $self = shift;
my $id = shift;
2017-11-15 18:22:49 +00:00
my $lookup_rs = $self->find($id)->search_related(
2017-11-13 19:00:34 +00:00
'lookups',
undef,
{
2017-11-15 18:22:49 +00:00
prefetch => { entity => [ qw/ organisation customer / ] },
order_by => { '-asc' => 'me.id' },
2017-11-13 19:00:34 +00:00
},
);
2017-11-15 18:22:49 +00:00
my $lookup_map = {
map {
$_->name => {
entity_id => $_->entity->id,
name => $_->entity->name,
},
} $lookup_rs->all
};
return $lookup_map;
2017-11-13 19:00:34 +00:00
}
2017-11-13 13:30:33 +00:00
1;