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

89 lines
1.9 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 {
2021-03-20 12:09:50 +00:00
my $self = shift;
my $id = shift;
my $include_ignored = shift;
my $include_imported = shift;
2017-11-13 13:30:33 +00:00
2021-03-20 12:09:50 +00:00
return $self->find($id)->search_related(
'values',
{
( $include_ignored ? () : ( ignore_value => 0 ) ),
( $include_imported ? () : ( transaction_id => undef ) ),
},
{
order_by => { '-asc' => 'id' },
},
);
2017-11-13 13:30:33 +00:00
}
sub _unordered_get_values {
2021-03-20 12:09:50 +00:00
my $self = shift;
my $id = shift;
my $include_ignored = shift;
my $include_imported = shift;
2021-03-20 12:09:50 +00:00
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 {
2021-03-20 23:26:52 +00:00
my ( $self, $set_id ) = @_;
2017-11-13 13:30:33 +00:00
2021-03-20 19:53:38 +00:00
return $self->_unordered_get_values($set_id)->search(
2021-03-20 12:09:50 +00:00
{},
{
group_by => 'user_name',
columns => [qw/ user_name /],
},
);
2017-11-13 13:30:33 +00:00
}
sub get_orgs {
2021-03-20 19:53:38 +00:00
my ( $self, $set_id ) = shift;
2021-03-20 12:09:50 +00:00
2021-03-20 19:53:38 +00:00
return $self->_unordered_get_values($set_id)->search(
2021-03-20 12:09:50 +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 {
2021-03-20 12:09:50 +00:00
my $self = shift;
my $id = shift;
2017-11-13 19:00:34 +00:00
2021-03-20 12:09:50 +00:00
my $lookup_rs = $self->find($id)->search_related(
'lookups',
undef,
{
prefetch => { entity => [qw/ organisation customer /] },
order_by => { '-asc' => 'me.id' },
},
);
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;