Lines 48-62
BEGIN {
Link Here
|
48 |
require Exporter; |
48 |
require Exporter; |
49 |
@ISA = qw( Exporter ); |
49 |
@ISA = qw( Exporter ); |
50 |
@EXPORT = qw( |
50 |
@EXPORT = qw( |
51 |
CreateCollection |
|
|
52 |
UpdateCollection |
53 |
DeleteCollection |
54 |
|
55 |
GetItemsInCollection |
51 |
GetItemsInCollection |
56 |
|
52 |
|
57 |
GetCollection |
|
|
58 |
GetCollections |
59 |
|
60 |
AddItemToCollection |
53 |
AddItemToCollection |
61 |
RemoveItemFromCollection |
54 |
RemoveItemFromCollection |
62 |
TransferCollection |
55 |
TransferCollection |
Lines 65-230
BEGIN {
Link Here
|
65 |
); |
58 |
); |
66 |
} |
59 |
} |
67 |
|
60 |
|
68 |
=head2 CreateCollection |
|
|
69 |
( $success, $errorcode, $errormessage ) = CreateCollection( $title, $description ); |
70 |
Creates a new collection |
71 |
|
72 |
Input: |
73 |
$title: short description of the club or service |
74 |
$description: long description of the club or service |
75 |
|
76 |
Output: |
77 |
$success: 1 if all database operations were successful, 0 otherwise |
78 |
$errorCode: Code for reason of failure, good for translating errors in templates |
79 |
$errorMessage: English description of error |
80 |
|
81 |
=cut |
82 |
|
83 |
sub CreateCollection { |
84 |
my ( $title, $description ) = @_; |
85 |
|
86 |
my $schema = Koha::Database->new()->schema(); |
87 |
my $duplicate_titles = $schema->resultset('Collection')->count({ colTitle => $title }); |
88 |
|
89 |
## Check for all necessary parameters |
90 |
if ( !$title ) { |
91 |
return ( 0, 1, "NO_TITLE" ); |
92 |
} elsif ( $duplicate_titles ) { |
93 |
return ( 0, 2, "DUPLICATE_TITLE" ); |
94 |
} |
95 |
|
96 |
$description ||= q{}; |
97 |
|
98 |
my $success = 1; |
99 |
|
100 |
my $dbh = C4::Context->dbh; |
101 |
|
102 |
my $sth; |
103 |
$sth = $dbh->prepare( |
104 |
"INSERT INTO collections ( colId, colTitle, colDesc ) |
105 |
VALUES ( NULL, ?, ? )" |
106 |
); |
107 |
$sth->execute( $title, $description ) or return ( 0, 3, $sth->errstr() ); |
108 |
|
109 |
return 1; |
110 |
|
111 |
} |
112 |
|
113 |
=head2 UpdateCollection |
114 |
|
115 |
( $success, $errorcode, $errormessage ) = UpdateCollection( $colId, $title, $description ); |
116 |
|
117 |
Updates a collection |
118 |
|
119 |
Input: |
120 |
$colId: id of the collection to be updated |
121 |
$title: short description of the club or service |
122 |
$description: long description of the club or service |
123 |
|
124 |
Output: |
125 |
$success: 1 if all database operations were successful, 0 otherwise |
126 |
$errorCode: Code for reason of failure, good for translating errors in templates |
127 |
$errorMessage: English description of error |
128 |
|
129 |
=cut |
130 |
|
131 |
sub UpdateCollection { |
132 |
my ( $colId, $title, $description ) = @_; |
133 |
|
134 |
my $schema = Koha::Database->new()->schema(); |
135 |
my $duplicate_titles = $schema->resultset('Collection')->count({ colTitle => $title, -not => { colId => $colId } }); |
136 |
|
137 |
## Check for all necessary parameters |
138 |
if ( !$colId ) { |
139 |
return ( 0, 1, "NO_ID" ); |
140 |
} |
141 |
if ( !$title ) { |
142 |
return ( 0, 2, "NO_TITLE" ); |
143 |
} |
144 |
if ( $duplicate_titles ) { |
145 |
return ( 0, 3, "DUPLICATE_TITLE" ); |
146 |
} |
147 |
|
148 |
my $dbh = C4::Context->dbh; |
149 |
|
150 |
$description ||= q{}; |
151 |
|
152 |
my $sth; |
153 |
$sth = $dbh->prepare( |
154 |
"UPDATE collections |
155 |
SET |
156 |
colTitle = ?, colDesc = ? |
157 |
WHERE colId = ?" |
158 |
); |
159 |
$sth->execute( $title, $description, $colId ) |
160 |
or return ( 0, 4, $sth->errstr() ); |
161 |
|
162 |
return 1; |
163 |
|
164 |
} |
165 |
|
166 |
=head2 DeleteCollection |
167 |
|
168 |
( $success, $errorcode, $errormessage ) = DeleteCollection( $colId ); |
169 |
Deletes a collection of the given id |
170 |
|
171 |
Input: |
172 |
$colId : id of the Archetype to be deleted |
173 |
|
174 |
Output: |
175 |
$success: 1 if all database operations were successful, 0 otherwise |
176 |
$errorCode: Code for reason of failure, good for translating errors in templates |
177 |
$errorMessage: English description of error |
178 |
|
179 |
=cut |
180 |
|
181 |
sub DeleteCollection { |
182 |
my ($colId) = @_; |
183 |
|
184 |
## Parameter check |
185 |
if ( !$colId ) { |
186 |
return ( 0, 1, "NO_ID" ); |
187 |
} |
188 |
|
189 |
my $dbh = C4::Context->dbh; |
190 |
|
191 |
my $sth; |
192 |
|
193 |
$sth = $dbh->prepare("DELETE FROM collections WHERE colId = ?"); |
194 |
$sth->execute($colId) or return ( 0, 4, $sth->errstr() ); |
195 |
|
196 |
return 1; |
197 |
} |
198 |
|
199 |
=head2 GetCollections |
200 |
|
201 |
$collections = GetCollections(); |
202 |
Returns data about all collections |
203 |
|
204 |
Output: |
205 |
On Success: |
206 |
$results: Reference to an array of associated arrays |
207 |
On Failure: |
208 |
$errorCode: Code for reason of failure, good for translating errors in templates |
209 |
$errorMessage: English description of error |
210 |
|
211 |
=cut |
212 |
|
213 |
sub GetCollections { |
214 |
|
215 |
my $dbh = C4::Context->dbh; |
216 |
|
217 |
my $sth = $dbh->prepare("SELECT * FROM collections"); |
218 |
$sth->execute() or return ( 1, $sth->errstr() ); |
219 |
|
220 |
my @results; |
221 |
while ( my $row = $sth->fetchrow_hashref ) { |
222 |
push( @results, $row ); |
223 |
} |
224 |
|
225 |
return \@results; |
226 |
} |
227 |
|
228 |
=head2 GetItemsInCollection |
61 |
=head2 GetItemsInCollection |
229 |
|
62 |
|
230 |
( $results, $success, $errorcode, $errormessage ) = GetItemsInCollection( $colId ); |
63 |
( $results, $success, $errorcode, $errormessage ) = GetItemsInCollection( $colId ); |
Lines 274-310
sub GetItemsInCollection {
Link Here
|
274 |
return \@results; |
107 |
return \@results; |
275 |
} |
108 |
} |
276 |
|
109 |
|
277 |
=head2 GetCollection |
|
|
278 |
|
279 |
( $colId, $colTitle, $colDesc, $colBranchcode ) = GetCollection( $colId ); |
280 |
|
281 |
Returns information about a collection |
282 |
|
283 |
Input: |
284 |
$colId: Id of the collection |
285 |
Output: |
286 |
$colId, $colTitle, $colDesc, $colBranchcode |
287 |
|
288 |
=cut |
289 |
|
290 |
sub GetCollection { |
291 |
my ($colId) = @_; |
292 |
|
293 |
my $dbh = C4::Context->dbh; |
294 |
|
295 |
my ( $sth, @results ); |
296 |
$sth = $dbh->prepare("SELECT * FROM collections WHERE colId = ?"); |
297 |
$sth->execute($colId) or return 0; |
298 |
|
299 |
my $row = $sth->fetchrow_hashref; |
300 |
|
301 |
return ( |
302 |
$$row{'colId'}, $$row{'colTitle'}, |
303 |
$$row{'colDesc'}, $$row{'colBranchcode'} |
304 |
); |
305 |
|
306 |
} |
307 |
|
308 |
=head2 AddItemToCollection |
110 |
=head2 AddItemToCollection |
309 |
|
111 |
|
310 |
( $success, $errorcode, $errormessage ) = AddItemToCollection( $colId, $itemnumber ); |
112 |
( $success, $errorcode, $errormessage ) = AddItemToCollection( $colId, $itemnumber ); |