X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=C4%2FMembers%2FAttributeTypes.pm;h=8c96e54c0f63e446e689067c195dc6146d3063fa;hb=0486d0c6b781fbda73df19eb825ef330bdc4544a;hp=9fb39e0e773f346cf42f3d02319c1269a65b5119;hpb=7c0e441d50d8587ba496d3031d79bde3b0ec6a57;p=koha_fer diff --git a/C4/Members/AttributeTypes.pm b/C4/Members/AttributeTypes.pm index 9fb39e0e77..8c96e54c0f 100644 --- a/C4/Members/AttributeTypes.pm +++ b/C4/Members/AttributeTypes.pm @@ -34,51 +34,43 @@ C4::Members::AttributeTypes - mananage extended patron attribute types =head1 SYNOPSIS -=over 4 - -my @attribute_types = C4::Members::AttributeTypes::GetAttributeTypes(); - -my $attr_type = C4::Members::AttributeTypes->new($code, $description); -$attr_type->code($code); -$attr_type->description($description); -$attr_type->repeatable($repeatable); -$attr_type->unique_id($unique_id); -$attr_type->opac_display($opac_display); -$attr_type->password_allowed($password_allowed); -$attr_type->staff_searchable($staff_searchable); -$attr_type->authorised_value_category($authorised_value_category); -$attr_type->store(); -$attr_type->delete(); - -my $attr_type = C4::Members::AttributeTypes->fetch($code); -$attr_type = C4::Members::AttributeTypes->delete($code); - -=back + my @attribute_types = C4::Members::AttributeTypes::GetAttributeTypes(); + + my $attr_type = C4::Members::AttributeTypes->new($code, $description); + $attr_type->code($code); + $attr_type->description($description); + $attr_type->repeatable($repeatable); + $attr_type->unique_id($unique_id); + $attr_type->opac_display($opac_display); + $attr_type->password_allowed($password_allowed); + $attr_type->staff_searchable($staff_searchable); + $attr_type->authorised_value_category($authorised_value_category); + $attr_type->store(); + $attr_type->delete(); + + my $attr_type = C4::Members::AttributeTypes->fetch($code); + $attr_type = C4::Members::AttributeTypes->delete($code); =head1 FUNCTIONS =head2 GetAttributeTypes -=over 4 - -my @attribute_types = C4::Members::AttributeTypes::GetAttributeTypes($all_fields); - -=back + my @attribute_types = C4::Members::AttributeTypes::GetAttributeTypes($all_fields); Returns an array of hashrefs of each attribute type defined in the database. The array is sorted by code. Each hashref contains at least the following fields: -code -description + - code + - description If $all_fields is true, then each hashref also contains the other fields from borrower_attribute_types. =cut sub GetAttributeTypes { - my $all = @_ ? shift : 0; - my $select = $all ? '*' : 'code, description'; + my ($all) = @_; + 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(); @@ -91,13 +83,25 @@ sub GetAttributeTypes_hashref { return \%hash; } -=head1 METHODS +=head2 AttributeTypeExists -=over 4 + my $have_attr_xyz = C4::Members::AttributeTypes::AttributeTypeExists($code) -my $attr_type = C4::Members::AttributeTypes->new($code, $description); +Returns true if we have attribute type C<$code> +in the database. -=back +=cut + +sub AttributeTypeExists { + my ($code) = @_; + my $dbh = C4::Context->dbh; + my $exists = $dbh->selectrow_array("SELECT code FROM borrower_attribute_types WHERE code = ?", undef, $code); + return $exists; +} + +=head1 METHODS + + my $attr_type = C4::Members::AttributeTypes->new($code, $description); Create a new attribute type. @@ -114,7 +118,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; @@ -122,11 +130,7 @@ sub new { =head2 fetch -=over 4 - -my $attr_type = C4::Members::AttributeTypes->fetch($code); - -=back + my $attr_type = C4::Members::AttributeTypes->fetch($code); Fetches an attribute type from the database. If no type with the given C<$code> exists, returns undef. @@ -139,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'}; @@ -152,7 +160,11 @@ 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'}; bless $self, $class; return $self; @@ -160,11 +172,7 @@ sub fetch { =head2 store -=over 4 - -$attr_type->store(); - -=back + $attr_type->store(); Stores attribute type in the database. If the type previously retrieved from the database via the fetch() @@ -186,14 +194,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'}); @@ -202,19 +213,18 @@ 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; } =head2 code -=over 4 - -my $code = $attr_type->code(); -$attr_type->code($code); - -=back + my $code = $attr_type->code(); + $attr_type->code($code); Accessor. Note that the code is immutable once a type is created or fetched from the database. @@ -228,12 +238,8 @@ sub code { =head2 description -=over 4 - -my $description = $attr_type->description(); -$attr_type->description($description); - -=back + my $description = $attr_type->description(); + $attr_type->description($description); Accessor. @@ -246,12 +252,8 @@ sub description { =head2 repeatable -=over 4 - -my $repeatable = $attr_type->repeatable(); -$attr_type->repeatable($repeatable); - -=back + my $repeatable = $attr_type->repeatable(); + $attr_type->repeatable($repeatable); Accessor. The C<$repeatable> argument is interpreted as a Perl boolean. @@ -265,12 +267,8 @@ sub repeatable { =head2 unique_id -=over 4 - -my $unique_id = $attr_type->unique_id(); -$attr_type->unique_id($unique_id); - -=back + my $unique_id = $attr_type->unique_id(); + $attr_type->unique_id($unique_id); Accessor. The C<$unique_id> argument is interpreted as a Perl boolean. @@ -283,12 +281,8 @@ sub unique_id { } =head2 opac_display -=over 4 - -my $opac_display = $attr_type->opac_display(); -$attr_type->opac_display($opac_display); - -=back + my $opac_display = $attr_type->opac_display(); + $attr_type->opac_display($opac_display); Accessor. The C<$opac_display> argument is interpreted as a Perl boolean. @@ -301,12 +295,8 @@ sub opac_display { } =head2 password_allowed -=over 4 - -my $password_allowed = $attr_type->password_allowed(); -$attr_type->password_allowed($password_allowed); - -=back + my $password_allowed = $attr_type->password_allowed(); + $attr_type->password_allowed($password_allowed); Accessor. The C<$password_allowed> argument is interpreted as a Perl boolean. @@ -319,12 +309,8 @@ sub password_allowed { } =head2 staff_searchable -=over 4 - -my $staff_searchable = $attr_type->staff_searchable(); -$attr_type->staff_searchable($staff_searchable); - -=back + my $staff_searchable = $attr_type->staff_searchable(); + $attr_type->staff_searchable($staff_searchable); Accessor. The C<$staff_searchable> argument is interpreted as a Perl boolean. @@ -336,15 +322,30 @@ sub staff_searchable { @_ ? $self->{'staff_searchable'} = ((shift) ? 1 : 0) : $self->{'staff_searchable'}; } -=head2 authorised_value_category +=head2 display_checkout =over 4 -my $authorised_value_category = $attr_type->authorised_value_category(); -$attr_type->authorised_value_category($authorised_value_category); +my $display_checkout = $attr_type->display_checkout(); +$attr_type->display_checkout($display_checkout); =back +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(); + $attr_type->authorised_value_category($authorised_value_category); + Accessor. =cut @@ -354,15 +355,66 @@ sub authorised_value_category { @_ ? $self->{'authorised_value_category'} = shift : $self->{'authorised_value_category'}; } -=head2 delete +=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 -$attr_type->delete(); -C4::Members::AttributeTypes->delete($code); +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(); + C4::Members::AttributeTypes->delete($code); + Delete an attribute type from the database. The attribute type may be specified either by an object or by a code. @@ -384,11 +436,7 @@ sub delete { =head2 num_patrons -=over 4 - -my $count = $attr_type->num_patrons(); - -=back + my $count = $attr_type->num_patrons(); Returns the number of patron records that use this attribute type. @@ -410,11 +458,7 @@ sub num_patrons { =head2 get_patrons -=over 4 - -my @borrowernumbers = $attr_type->get_patrons($attribute); - -=back + my @borrowernumbers = $attr_type->get_patrons($attribute); Returns the borrowernumber of the patron records that have an attribute with the specifie value.