Lines 20-25
package C4::Members::AttributeTypes;
Link Here
|
20 |
use strict; |
20 |
use strict; |
21 |
#use warnings; FIXME - Bug 2505 |
21 |
#use warnings; FIXME - Bug 2505 |
22 |
use C4::Context; |
22 |
use C4::Context; |
|
|
23 |
use Koha::Database; |
23 |
|
24 |
|
24 |
use vars qw($VERSION); |
25 |
use vars qw($VERSION); |
25 |
|
26 |
|
Lines 135-140
sub new {
Link Here
|
135 |
$self->{'category_code'} = ''; |
136 |
$self->{'category_code'} = ''; |
136 |
$self->{'category_description'} = ''; |
137 |
$self->{'category_description'} = ''; |
137 |
$self->{'class'} = ''; |
138 |
$self->{'class'} = ''; |
|
|
139 |
$self->{'backup_for'} = ''; |
138 |
|
140 |
|
139 |
bless $self, $class; |
141 |
bless $self, $class; |
140 |
return $self; |
142 |
return $self; |
Lines 177-182
sub fetch {
Link Here
|
177 |
$self->{'category_code'} = $row->{'category_code'}; |
179 |
$self->{'category_code'} = $row->{'category_code'}; |
178 |
$self->{'category_description'} = $row->{'category_description'}; |
180 |
$self->{'category_description'} = $row->{'category_description'}; |
179 |
$self->{'class'} = $row->{'class'}; |
181 |
$self->{'class'} = $row->{'class'}; |
|
|
182 |
$self->{'backup_for'} = $row->{'backup_for'}; |
180 |
|
183 |
|
181 |
$sth = $dbh->prepare("SELECT branchcode, branchname FROM borrower_attribute_types_branches, branches WHERE b_branchcode = branchcode AND bat_code = ?;"); |
184 |
$sth = $dbh->prepare("SELECT branchcode, branchname FROM borrower_attribute_types_branches, branches WHERE b_branchcode = branchcode AND bat_code = ?;"); |
182 |
$sth->execute( $code ); |
185 |
$sth->execute( $code ); |
Lines 202-259
method, the DB representation of the type is replaced.
Link Here
|
202 |
sub store { |
205 |
sub store { |
203 |
my $self = shift; |
206 |
my $self = shift; |
204 |
|
207 |
|
205 |
my $dbh = C4::Context->dbh; |
208 |
my $schema = Koha::Database->new()->schema(); |
206 |
my $sth; |
209 |
|
207 |
my $existing = __PACKAGE__->fetch($self->{'code'}); |
210 |
my $type = $schema->resultset('BorrowerAttributeType')->update_or_create( |
208 |
if (defined $existing) { |
211 |
{ |
209 |
$sth = $dbh->prepare_cached("UPDATE borrower_attribute_types |
212 |
|
210 |
SET description = ?, |
213 |
code => $self->{'code'}, |
211 |
repeatable = ?, |
214 |
description => $self->{'description'}, |
212 |
unique_id = ?, |
215 |
repeatable => $self->{'repeatable'}, |
213 |
opac_display = ?, |
216 |
unique_id => $self->{'unique_id'}, |
214 |
password_allowed = ?, |
217 |
opac_display => $self->{'opac_display'}, |
215 |
staff_searchable = ?, |
218 |
password_allowed => $self->{'password_allowed'}, |
216 |
authorised_value_category = ?, |
219 |
staff_searchable => $self->{'staff_searchable'}, |
217 |
display_checkout = ?, |
220 |
authorised_value_category => $self->{'authorised_value_category'}, |
218 |
category_code = ?, |
221 |
display_checkout => $self->{'display_checkout'}, |
219 |
class = ? |
222 |
category_code => $self->{'category_code'} || undef, |
220 |
WHERE code = ?"); |
223 |
class => $self->{'class'}, |
221 |
} else { |
224 |
backup_for => $self->{'backup_for'} || undef, |
222 |
$sth = $dbh->prepare_cached("INSERT INTO borrower_attribute_types |
225 |
} |
223 |
(description, repeatable, unique_id, opac_display, password_allowed, |
226 |
); |
224 |
staff_searchable, authorised_value_category, display_checkout, category_code, class, code) |
227 |
|
225 |
VALUES (?, ?, ?, ?, ?, |
228 |
if ( defined $self->{branches} ) { |
226 |
?, ?, ?, ?, ?, ?)"); |
229 |
$type->borrower_attribute_types_branches()->delete(); |
227 |
} |
230 |
|
228 |
$sth->bind_param(1, $self->{'description'}); |
231 |
my $rs = $schema->resultset('BorrowerAttributeTypesBranch'); |
229 |
$sth->bind_param(2, $self->{'repeatable'}); |
232 |
|
230 |
$sth->bind_param(3, $self->{'unique_id'}); |
233 |
for my $branchcode ( @{ $$self{branches} } ) { |
231 |
$sth->bind_param(4, $self->{'opac_display'}); |
234 |
next unless $branchcode; |
232 |
$sth->bind_param(5, $self->{'password_allowed'}); |
235 |
$rs->create( { bat_code => $self->{code}, b_branchcode => $branchcode } ); |
233 |
$sth->bind_param(6, $self->{'staff_searchable'}); |
|
|
234 |
$sth->bind_param(7, $self->{'authorised_value_category'}); |
235 |
$sth->bind_param(8, $self->{'display_checkout'}); |
236 |
$sth->bind_param(9, $self->{'category_code'} || undef); |
237 |
$sth->bind_param(10, $self->{'class'}); |
238 |
$sth->bind_param(11, $self->{'code'}); |
239 |
$sth->execute; |
240 |
|
241 |
if ( defined $$self{branches} ) { |
242 |
$sth = $dbh->prepare("DELETE FROM borrower_attribute_types_branches WHERE bat_code = ?"); |
243 |
$sth->execute( $$self{code} ); |
244 |
$sth = $dbh->prepare( |
245 |
"INSERT INTO borrower_attribute_types_branches |
246 |
( bat_code, b_branchcode ) |
247 |
VALUES ( ?, ? )" |
248 |
); |
249 |
for my $branchcode ( @{$$self{branches}} ) { |
250 |
next if not $branchcode; |
251 |
$sth->bind_param( 1, $$self{code} ); |
252 |
$sth->bind_param( 2, $branchcode ); |
253 |
$sth->execute; |
254 |
} |
236 |
} |
255 |
} |
237 |
} |
256 |
$sth->finish; |
|
|
257 |
} |
238 |
} |
258 |
|
239 |
|
259 |
=head2 code |
240 |
=head2 code |
Lines 442-447
sub class {
Link Here
|
442 |
@_ ? $self->{'class'} = shift : $self->{'class'}; |
423 |
@_ ? $self->{'class'} = shift : $self->{'class'}; |
443 |
} |
424 |
} |
444 |
|
425 |
|
|
|
426 |
=head2 backup_for |
427 |
|
428 |
my $backup_for = $attr_type->backup_for(); |
429 |
$attr_type->backup_for($backup_for); |
430 |
|
431 |
Accessor. |
432 |
|
433 |
=cut |
434 |
|
435 |
sub backup_for { |
436 |
my $self = shift; |
437 |
@_ ? $self->{'backup_for'} = shift : $self->{'backup_for'}; |
438 |
} |
439 |
|
445 |
|
440 |
|
446 |
=head2 delete |
441 |
=head2 delete |
447 |
|
442 |
|