@@ -, +, @@ it only for the specified category with a new category 'PA_CLASS' to fill class list) category_code class --- C4/Members/AttributeTypes.pm | 83 +++++++++- C4/Members/Attributes.pm | 4 +- admin/patron-attr-types.pl | 41 +++++- installer/data/mysql/kohastructure.sql | 2 + installer/data/mysql/updatedatabase.pl | 13 ++ .../prog/en/modules/admin/patron-attr-types.tt | 73 +++++++-- .../prog/en/modules/members/memberentrygen.tt | 170 ++++++++++++-------- .../prog/en/modules/members/moremember.tt | 43 ++++-- members/memberentry.pl | 21 ++- members/moremember.pl | 21 ++- 10 files changed, 360 insertions(+), 111 deletions(-) --- a/C4/Members/AttributeTypes.pm +++ a/C4/Members/AttributeTypes.pm @@ -70,7 +70,7 @@ If $all_fields is true, then each hashref also contains the other fields from bo sub GetAttributeTypes { my ($all) = @_; - my $select = $all ? '*' : 'code, description'; + my $select = $all ? '*' : 'code, description, class'; my $dbh = C4::Context->dbh; my $sth = $dbh->prepare("SELECT $select FROM borrower_attribute_types ORDER by code"); $sth->execute(); @@ -120,6 +120,9 @@ sub new { $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; @@ -140,11 +143,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 undef unless defined $row; $self->{'code'} = $row->{'code'}; $self->{'description'} = $row->{'description'}; @@ -155,6 +162,9 @@ sub fetch { $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'}; bless $self, $class; return $self; @@ -185,14 +195,16 @@ sub store { password_allowed = ?, staff_searchable = ?, authorised_value_category = ?, - display_checkout = ? + 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, display_checkout, 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'}); @@ -202,7 +214,9 @@ sub store { $sth->bind_param(6, $self->{'staff_searchable'}); $sth->bind_param(7, $self->{'authorised_value_category'}); $sth->bind_param(8, $self->{'display_checkout'}); - $sth->bind_param(9, $self->{'code'}); + $sth->bind_param(9, $self->{'category_code'} || undef); + $sth->bind_param(10, $self->{'class'}); + $sth->bind_param(11, $self->{'code'}); $sth->execute; } @@ -341,6 +355,61 @@ sub authorised_value_category { @_ ? $self->{'authorised_value_category'} = shift : $self->{'authorised_value_category'}; } +=head2 category_code + +=over 4 + +my $category_code = $attr_type->category_code(); +$attr_type->category_code($category_code); + +=back + +Accessor. + +=cut + +sub category_code { + my $self = shift; + @_ ? $self->{'category_code'} = shift : $self->{'category_code'}; +} + +=head2 category_description + +=over 4 + +my $category_description = $attr_type->category_description(); +$attr_type->category_description($category_description); + +=back + +Accessor. + +=cut + +sub category_description { + my $self = shift; + @_ ? $self->{'category_description'} = shift : $self->{'category_description'}; +} + +=head2 class + +=over 4 + +my $class = $attr_type->class(); +$attr_type->class($class); + +=back + +Accessor. + +=cut + +sub class { + my $self = shift; + @_ ? $self->{'class'} = shift : $self->{'class'}; +} + + =head2 delete $attr_type->delete(); --- a/C4/Members/Attributes.pm +++ a/C4/Members/Attributes.pm @@ -72,7 +72,7 @@ sub GetBorrowerAttributes { my $opac_only = @_ ? shift : 0; my $dbh = C4::Context->dbh(); - my $query = "SELECT code, description, attribute, lib, password, display_checkout + my $query = "SELECT code, description, attribute, lib, password, display_checkout, category_type, class FROM borrower_attributes JOIN borrower_attribute_types USING (code) LEFT JOIN authorised_values ON (category = authorised_value_category AND attribute = authorised_value) @@ -90,6 +90,8 @@ sub GetBorrowerAttributes { value_description => $row->{'lib'}, password => $row->{'password'}, display_checkout => $row->{'display_checkout'}, + category_type => $row->{'category_type'}, + class => $row->{'class'}, } } return \@results; --- a/admin/patron-attr-types.pl +++ a/admin/patron-attr-types.pl @@ -22,10 +22,13 @@ use strict; use warnings; use CGI; +use List::MoreUtils qw/uniq/; + use C4::Auth; use C4::Context; use C4::Output; use C4::Koha; +use C4::Members qw/GetBorrowercategoryList/; use C4::Members::AttributeTypes; my $script_name = "/cgi-bin/koha/admin/patron-attr-types.pl"; @@ -82,8 +85,10 @@ sub add_attribute_type_form { $template->param( attribute_type_form => 1, confirm_op => 'add_attribute_type_confirmed', + categories => GetBorrowercategoryList, ); authorised_value_category_list($template); + pa_classes($template); } sub error_add_attribute_type_form { @@ -110,6 +115,9 @@ sub error_add_attribute_type_form { $template->param(display_checkout_checked => 'checked="checked"'); } + $template->param( category_code => $input->param('category_code') ); + $template->param( class => $input->param('class') ); + $template->param( attribute_type_form => 1, confirm_op => 'add_attribute_type_confirmed', @@ -152,6 +160,8 @@ sub add_update_attribute_type { $attr_type->password_allowed($password_allowed); my $display_checkout = $input->param('display_checkout'); $attr_type->display_checkout($display_checkout); + $attr_type->category_code($input->param('category_code')); + $attr_type->class($input->param('class')); if ($op eq 'edit') { $template->param(edited_attribute_type => $attr_type->code()); @@ -209,6 +219,7 @@ sub edit_attribute_type_form { $template->param(code => $code); $template->param(description => $attr_type->description()); + $template->param(class => $attr_type->class()); if ($attr_type->repeatable()) { $template->param(repeatable_checked => 1); @@ -231,20 +242,39 @@ sub edit_attribute_type_form { $template->param(display_checkout_checked => 'checked="checked"'); } authorised_value_category_list($template, $attr_type->authorised_value_category()); + pa_classes( $template, $attr_type->class ); + + $template->param ( category_code => $attr_type->category_code ); + $template->param ( category_description => $attr_type->category_description ); $template->param( attribute_type_form => 1, edit_attribute_type => 1, confirm_op => 'edit_attribute_type_confirmed', + categories => GetBorrowercategoryList, ); } sub patron_attribute_type_list { my $template = shift; - + my @attr_types = C4::Members::AttributeTypes::GetAttributeTypes(); - $template->param(available_attribute_types => \@attr_types); + my @classes = uniq( map {$_->{class}} @attr_types ); + @classes = sort @classes; + + my @attributes_loop; + for my $class (@classes) { + my @items; + for my $attr (@attr_types) { + push @items, $attr if $attr->{class} eq $class + } + push @attributes_loop, { + class => $class, + items => \@items + }; + } + $template->param(available_attribute_types => \@attributes_loop); $template->param(display_list => 1); } @@ -261,3 +291,10 @@ sub authorised_value_category_list { } $template->param(authorised_value_categories => \@list); } + +sub pa_classes { + my $template = shift; + my $selected = @_ ? shift : ''; + + $template->param(classes_val_loop => GetAuthorisedValues( 'PA_CLASS', $selected ) ); +} --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -286,6 +286,8 @@ CREATE TABLE `borrower_attribute_types` ( -- definitions for custom patron field `staff_searchable` tinyint(1) NOT NULL default 0, -- defines if this field is searchable via the patron search in the staff client (1 for yes, 0 for no) `authorised_value_category` varchar(10) default NULL, -- foreign key from authorised_values that links this custom field to an authorized value category `display_checkout` tinyint(1) NOT NULL default 0,-- defines if this field displays in checkout screens + `category_code` VARCHAR(1) NOT NULL DEFAULT '',-- defines a category for an attribute_type + `class` VARCHAR(255) NOT NULL DEFAULT '',-- defines a class for an attribute_type PRIMARY KEY (`code`), KEY `auth_val_cat_idx` (`authorised_value_category`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -4932,6 +4932,19 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { SetVersion($DBversion); } + + + + +$DBversion = "3.07.00.XXX"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE borrower_attribute_types ADD COLUMN category_code VARCHAR(10) NULL DEFAULT NULL AFTER `display_checkout`"); + $dbh->do("ALTER TABLE borrower_attribute_types ADD COLUMN class VARCHAR(255) NOT NULL DEFAULT '' AFTER `category_code`"); + $dbh->do("ALTER TABLE borrower_attribute_types ADD CONSTRAINT category_code_fk FOREIGN KEY (category_code) REFERENCES categories(categorycode)"); + print "Upgrade to $DBversion done (New fields category_code and class in borrower_attribute_types table)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 DropAllForeignKeys($table) --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt @@ -186,6 +186,34 @@ function CheckAttributeTypeForm(f) { to be chosen from the authorized value list. However, an authorized value list is not enforced during batch patron import. +