]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm
added method to get org_unit descendants
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Storage / Publisher / actor.pm
1 package OpenILS::Application::Storage::Publisher::actor;
2 use base qw/OpenILS::Application::Storage/;
3 use OpenILS::Application::Storage::CDBI::actor;
4 use OpenSRF::Utils::Logger qw/:level/;
5 use OpenILS::Utils::Fieldmapper;
6
7 my $log = 'OpenSRF::Utils::Logger';
8
9 sub org_unit_list {
10         my $self = shift;
11         my $client = shift;
12
13         my $select =<<" SQL";
14         SELECT  *
15           FROM  actor.org_unit
16           ORDER BY CASE WHEN parent_ou IS NULL THEN 0 ELSE 1 END, name;
17         SQL
18
19         my $sth = actor::org_unit->db_Main->prepare_cached($select);
20         $sth->execute;
21
22         my @fms;
23         push @fms, $_->to_fieldmapper for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
24
25         return \@fms;
26 }
27 __PACKAGE__->register_method(
28         api_name        => 'open-ils.storage.direct.actor.org_unit.retrieve.all',
29         api_level       => 1,
30         method          => 'org_unit_list',
31 );
32
33 sub org_unit_type_list {
34         my $self = shift;
35         my $client = shift;
36
37         my $select =<<" SQL";
38         SELECT  *
39           FROM  actor.org_unit_type
40           ORDER BY depth, name;
41         SQL
42
43         my $sth = actor::org_unit_type->db_Main->prepare_cached($select);
44         $sth->execute;
45
46         my @fms;
47         push @fms, $_->to_fieldmapper for ( map { actor::org_unit_type->construct($_) } $sth->fetchall_hash );
48
49         return \@fms;
50 }
51 __PACKAGE__->register_method(
52         api_name        => 'open-ils.storage.direct.actor.org_unit_type.retrieve.all',
53         api_level       => 1,
54         method          => 'org_unit_type_list',
55 );
56
57 sub org_unit_descendants {
58         my $self = shift;
59         my $client = shift;
60         my $id = shift;
61
62         return undef unless ($id);
63
64         my $select =<<" SQL";
65         SELECT  a.*
66           FROM  connectby('actor.org_unit','id','parent_ou','name',?,'100','.')
67                         as t(keyid text, parent_keyid text, level int, branch text,pos int),
68                 actor.org_unit a
69           WHERE t.keyid = a.id
70           ORDER BY t.pos;
71         SQL
72
73         my $sth = actor::org_unit->db_Main->prepare_cached($select);
74         $sth->execute($id);
75
76         my @fms;
77         push @fms, $_->to_fieldmapper for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
78
79         return \@fms;
80 }
81 __PACKAGE__->register_method(
82         api_name        => 'open-ils.storage.actor.org_unit.descendants',
83         api_level       => 1,
84         method          => 'org_unit_descendants',
85 );
86
87
88 1;