Lines 48-55
BEGIN {
Link Here
|
48 |
require Exporter; |
48 |
require Exporter; |
49 |
@ISA = qw( Exporter ); |
49 |
@ISA = qw( Exporter ); |
50 |
@EXPORT = qw( |
50 |
@EXPORT = qw( |
51 |
UpdateCollection |
|
|
52 |
|
53 |
GetItemsInCollection |
51 |
GetItemsInCollection |
54 |
|
52 |
|
55 |
AddItemToCollection |
53 |
AddItemToCollection |
Lines 60-118
BEGIN {
Link Here
|
60 |
); |
58 |
); |
61 |
} |
59 |
} |
62 |
|
60 |
|
63 |
=head2 UpdateCollection |
|
|
64 |
|
65 |
( $success, $errorcode, $errormessage ) = UpdateCollection( $colId, $title, $description ); |
66 |
|
67 |
Updates a collection |
68 |
|
69 |
Input: |
70 |
$colId: id of the collection to be updated |
71 |
$title: short description of the club or service |
72 |
$description: long description of the club or service |
73 |
|
74 |
Output: |
75 |
$success: 1 if all database operations were successful, 0 otherwise |
76 |
$errorCode: Code for reason of failure, good for translating errors in templates |
77 |
$errorMessage: English description of error |
78 |
|
79 |
=cut |
80 |
|
81 |
sub UpdateCollection { |
82 |
my ( $colId, $title, $description ) = @_; |
83 |
|
84 |
my $schema = Koha::Database->new()->schema(); |
85 |
my $duplicate_titles = $schema->resultset('Collection')->count({ colTitle => $title, -not => { colId => $colId } }); |
86 |
|
87 |
## Check for all necessary parameters |
88 |
if ( !$colId ) { |
89 |
return ( 0, 1, "NO_ID" ); |
90 |
} |
91 |
if ( !$title ) { |
92 |
return ( 0, 2, "NO_TITLE" ); |
93 |
} |
94 |
if ( $duplicate_titles ) { |
95 |
return ( 0, 3, "DUPLICATE_TITLE" ); |
96 |
} |
97 |
|
98 |
my $dbh = C4::Context->dbh; |
99 |
|
100 |
$description ||= q{}; |
101 |
|
102 |
my $sth; |
103 |
$sth = $dbh->prepare( |
104 |
"UPDATE collections |
105 |
SET |
106 |
colTitle = ?, colDesc = ? |
107 |
WHERE colId = ?" |
108 |
); |
109 |
$sth->execute( $title, $description, $colId ) |
110 |
or return ( 0, 4, $sth->errstr() ); |
111 |
|
112 |
return 1; |
113 |
|
114 |
} |
115 |
|
116 |
=head2 GetItemsInCollection |
61 |
=head2 GetItemsInCollection |
117 |
|
62 |
|
118 |
( $results, $success, $errorcode, $errormessage ) = GetItemsInCollection( $colId ); |
63 |
( $results, $success, $errorcode, $errormessage ) = GetItemsInCollection( $colId ); |