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