X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FMembers%2FAttributeTypes.pm;h=17540997f4f96ce4294ec09e3574968747eb7f40;hb=2614e07e1e2e6386b5f91e65f127940072e54d4d;hp=3a05268c350f0b63b75c997fb0248e720d40a85b;hpb=9a54047b6d10eb4b553ad29c6130a1e276252fe5;p=koha.git diff --git a/C4/Members/AttributeTypes.pm b/C4/Members/AttributeTypes.pm index 3a05268c35..17540997f4 100644 --- a/C4/Members/AttributeTypes.pm +++ b/C4/Members/AttributeTypes.pm @@ -25,7 +25,7 @@ use vars qw($VERSION); BEGIN { # set the version for version checking - $VERSION = 3.00; + $VERSION = 3.07.00.049; } =head1 NAME @@ -69,12 +69,24 @@ If $all_fields is true, then each hashref also contains the other fields from bo =cut sub GetAttributeTypes { - my ($all) = @_; - my $select = $all ? '*' : 'code, description'; + my $all = @_ ? shift : 0; + my $no_branch_limit = @_ ? shift : 0; + my $branch_limit = $no_branch_limit + ? 0 + : C4::Context->userenv ? C4::Context->userenv->{"branch"} : 0; + my $select = $all ? '*' : 'DISTINCT(code), description, class'; + my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("SELECT $select FROM borrower_attribute_types ORDER by code"); - $sth->execute(); + my $query = "SELECT $select FROM borrower_attribute_types"; + $query .= qq{ + LEFT JOIN borrower_attribute_types_branches ON bat_code = code + WHERE b_branchcode = ? OR b_branchcode IS NULL + } if $branch_limit; + $query .= " ORDER BY code"; + my $sth = $dbh->prepare($query); + $sth->execute( $branch_limit ? $branch_limit : () ); my $results = $sth->fetchall_arrayref({}); + $sth->finish; return @$results; } @@ -118,7 +130,11 @@ sub new { $self->{'opac_display'} = 0; $self->{'password_allowed'} = 0; $self->{'staff_searchable'} = 0; + $self->{'display_checkout'} = 0; $self->{'authorised_value_category'} = ''; + $self->{'category_code'} = ''; + $self->{'category_description'} = ''; + $self->{'class'} = ''; bless $self, $class; return $self; @@ -139,11 +155,15 @@ sub fetch { my $self = {}; my $dbh = C4::Context->dbh(); - my $sth = $dbh->prepare_cached("SELECT * FROM borrower_attribute_types WHERE code = ?"); + my $sth = $dbh->prepare_cached(" + SELECT borrower_attribute_types.*, categories.description AS category_description + FROM borrower_attribute_types + LEFT JOIN categories ON borrower_attribute_types.category_code=categories.categorycode + WHERE code =?"); $sth->execute($code); my $row = $sth->fetchrow_hashref; $sth->finish(); - return undef unless defined $row; + return unless defined $row; $self->{'code'} = $row->{'code'}; $self->{'description'} = $row->{'description'}; @@ -152,7 +172,18 @@ sub fetch { $self->{'opac_display'} = $row->{'opac_display'}; $self->{'password_allowed'} = $row->{'password_allowed'}; $self->{'staff_searchable'} = $row->{'staff_searchable'}; + $self->{'display_checkout'} = $row->{'display_checkout'}; $self->{'authorised_value_category'} = $row->{'authorised_value_category'}; + $self->{'category_code'} = $row->{'category_code'}; + $self->{'category_description'} = $row->{'category_description'}; + $self->{'class'} = $row->{'class'}; + + $sth = $dbh->prepare("SELECT branchcode, branchname FROM borrower_attribute_types_branches, branches WHERE b_branchcode = branchcode AND bat_code = ?;"); + $sth->execute( $code ); + while ( my $data = $sth->fetchrow_hashref ) { + push @{ $self->{branches} }, $data; + } + $sth->finish(); bless $self, $class; return $self; @@ -182,14 +213,17 @@ sub store { opac_display = ?, password_allowed = ?, staff_searchable = ?, - authorised_value_category = ? + authorised_value_category = ?, + display_checkout = ?, + category_code = ?, + class = ? WHERE code = ?"); } else { $sth = $dbh->prepare_cached("INSERT INTO borrower_attribute_types (description, repeatable, unique_id, opac_display, password_allowed, - staff_searchable, authorised_value_category, code) + staff_searchable, authorised_value_category, display_checkout, category_code, class, code) VALUES (?, ?, ?, ?, ?, - ?, ?, ?)"); + ?, ?, ?, ?, ?, ?)"); } $sth->bind_param(1, $self->{'description'}); $sth->bind_param(2, $self->{'repeatable'}); @@ -198,9 +232,28 @@ sub store { $sth->bind_param(5, $self->{'password_allowed'}); $sth->bind_param(6, $self->{'staff_searchable'}); $sth->bind_param(7, $self->{'authorised_value_category'}); - $sth->bind_param(8, $self->{'code'}); + $sth->bind_param(8, $self->{'display_checkout'}); + $sth->bind_param(9, $self->{'category_code'} || undef); + $sth->bind_param(10, $self->{'class'}); + $sth->bind_param(11, $self->{'code'}); $sth->execute; + if ( defined $$self{branches} ) { + $sth = $dbh->prepare("DELETE FROM borrower_attribute_types_branches WHERE bat_code = ?"); + $sth->execute( $$self{code} ); + $sth = $dbh->prepare( + "INSERT INTO borrower_attribute_types_branches + ( bat_code, b_branchcode ) + VALUES ( ?, ? )" + ); + for my $branchcode ( @{$$self{branches}} ) { + next if not $branchcode; + $sth->bind_param( 1, $$self{code} ); + $sth->bind_param( 2, $branchcode ); + $sth->execute; + } + } + $sth->finish; } =head2 code @@ -232,6 +285,20 @@ sub description { @_ ? $self->{'description'} = shift : $self->{'description'}; } +=head2 branches + +my $branches = $attr_type->branches(); +$attr_type->branches($branches); + +Accessor. + +=cut + +sub branches { + my $self = shift; + @_ ? $self->{branches} = shift : $self->{branches}; +} + =head2 repeatable my $repeatable = $attr_type->repeatable(); @@ -304,6 +371,21 @@ sub staff_searchable { @_ ? $self->{'staff_searchable'} = ((shift) ? 1 : 0) : $self->{'staff_searchable'}; } +=head2 display_checkout + +my $display_checkout = $attr_type->display_checkout(); +$attr_type->display_checkout($display_checkout); + +Accessor. The C<$display_checkout> argument +is interpreted as a Perl boolean. + +=cut + +sub display_checkout { + my $self = shift; + @_ ? $self->{'display_checkout'} = ((shift) ? 1 : 0) : $self->{'display_checkout'}; +} + =head2 authorised_value_category my $authorised_value_category = $attr_type->authorised_value_category(); @@ -318,6 +400,49 @@ sub authorised_value_category { @_ ? $self->{'authorised_value_category'} = shift : $self->{'authorised_value_category'}; } +=head2 category_code + +my $category_code = $attr_type->category_code(); +$attr_type->category_code($category_code); + +Accessor. + +=cut + +sub category_code { + my $self = shift; + @_ ? $self->{'category_code'} = shift : $self->{'category_code'}; +} + +=head2 category_description + +my $category_description = $attr_type->category_description(); +$attr_type->category_description($category_description); + +Accessor. + +=cut + +sub category_description { + my $self = shift; + @_ ? $self->{'category_description'} = shift : $self->{'category_description'}; +} + +=head2 class + +my $class = $attr_type->class(); +$attr_type->class($class); + +Accessor. + +=cut + +sub class { + my $self = shift; + @_ ? $self->{'class'} = shift : $self->{'class'}; +} + + =head2 delete $attr_type->delete(); @@ -340,6 +465,7 @@ sub delete { my $dbh = C4::Context->dbh; my $sth = $dbh->prepare_cached("DELETE FROM borrower_attribute_types WHERE code = ?"); $sth->execute($code); + $sth->finish; } =head2 num_patrons