]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Circ/NonCat.pm
c1219834139a3b5baa5c640a1d5bbb2da1ae106b
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Circ / NonCat.pm
1 package OpenILS::Application::Circ::NonCat;
2 use base 'OpenSRF::Application';
3 use strict; use warnings;
4 use OpenSRF::EX qw(:try);
5 use Data::Dumper;
6 use OpenSRF::Utils::Logger qw(:logger);
7 use OpenILS::Application::AppUtils;
8 use OpenILS::Utils::Fieldmapper;
9 $Data::Dumper::Indent = 0;
10
11 my $U = "OpenILS::Application::AppUtils";
12
13
14 # returns ( $newid, $evt ).  If $evt, then there was an error
15 sub create_non_cat_circ {
16         my( $staffid, $patronid, $circ_lib, $noncat_type, $circ_time ) = @_;
17
18         my( $id, $evt );
19         $circ_time |= 'now';
20         my $circ = Fieldmapper::action::non_cataloged_circulation->new;
21
22         $logger->activity("Creating non-cataloged circulation for ".
23                 "staff $staffid, patron $patronid, location $circ_lib, and non-cat type $noncat_type");
24
25         $circ->patron($patronid);
26         $circ->staff($staffid);
27         $circ->circ_lib($circ_lib);
28         $circ->item_type($noncat_type);
29         $circ->circ_time($circ_time);
30
31         $id = $U->simplereq(
32                 'open-ils.storage',
33                 'open-ils.storage.direct.action.non_cataloged_circulation.create', $circ );
34         $evt = $U->DB_UPDATE_FAILED($circ) unless $id;
35
36         return( $id, $evt );
37 }
38
39
40 __PACKAGE__->register_method(
41         method  => "create_noncat_type",
42         api_name        => "open-ils.circ.non_cat_type.create",
43         notes           => q/
44                 Creates a new non cataloged item type
45                 @param authtoken The login session key
46                 @param name The name of the new type
47                 @param orgId The location where the type will live
48                 @return The type object on success and the corresponding
49                 event on failure
50         /);
51
52 sub create_noncat_type {
53         my( $self, $client, $authtoken, $name, $orgId ) = @_;
54         my( $staff, $evt ) = $U->checkses($authtoken);
55         return $evt if $evt;
56
57         # grab all of "my" non-cat types and see if one with 
58         # the requested name already exists
59         my $types = $self->retrieve_noncat_types_all($client, $orgId);
60         if(ref($types)) {
61                 for(@$types) {
62                         return OpenILS::Event->new('NON_CAT_TYPE_EXISTS') if $_->name eq $name;
63                 }
64         }
65
66         $evt = $U->check_perms( $staff->id, $orgId, 'CREATE_NON_CAT_TYPE' );
67         return $evt if $evt;
68
69         my $type = Fieldmapper::config::non_cataloged_type->new;
70         $type->name($name);
71         $type->owning_lib($orgId);
72
73         my $id = $U->simplereq(
74                 'open-ils.storage',
75                 'open-ils.storage.direct.config.non_cataloged_type.create', $type );
76
77         return $U->DB_UPDATE_FAILED($type) unless $id;
78         $type->id($id);
79         return $type;
80 }
81
82 __PACKAGE__->register_method(
83         method  => "update_noncat_type",
84         api_name        => "open-ils.circ.non_cat_type.update",
85         notes           => q/
86                 Updates a non-cataloged type object
87                 @param authtoken The login session key
88                 @param type The updated type object
89                 @return The result of the DB update call unless a preceeding event occurs, 
90                         in which case the event will be returned
91         /);
92
93 sub update_noncat_type {
94         my( $self, $client, $authtoken, $type ) = @_;
95         my( $staff, $evt ) = $U->checkses($authtoken);
96         return $evt if $evt;
97
98         my $otype;
99         ($otype, $evt) = $U->fetch_non_cat_type($type->id);
100         return $evt if $evt;
101
102         $type->owning_lib($otype->owning_lib); # do not allow them to "move" the object
103
104         $evt = $U->check_perms( $staff->id, $type->owning_lib, 'UPDATE_NON_CAT_TYPE' );
105         return $evt if $evt;
106
107         return $U->simplereq(
108                 'open-ils.storage',
109                 'open-ils.storage.direct.config.non_cataloged_type.update', $type );
110 }
111
112 __PACKAGE__->register_method(
113         method  => "retrieve_noncat_types_all",
114         api_name        => "open-ils.circ.non_cat_types.retrieve.all",
115         notes           => q/
116                 Retrieves the non-cat types at the requested location as well
117                 as those above and below the requested location in the org tree
118                 @param orgId The base location at which to retrieve the type objects
119                 @param depth Optional parameter to limit the depth of the tree
120                 @return An array of non cat type objects or an event if an error occurs
121         /);
122
123 sub retrieve_noncat_types_all {
124         my( $self, $client, $orgId, $depth ) = @_;
125         my $meth = 'open-ils.storage.ranged.config.non_cataloged_type.retrieve.atomic';
126         my $svc = 'open-ils.storage';
127         return $U->simplereq($svc, $meth, $orgId, $depth) if defined($depth);
128         return $U->simplereq($svc, $meth, $orgId);
129 }
130
131
132
133 1;