1 package Koha::Patron::Attribute::Type;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use Koha::Exceptions::Patron::Attribute::Type;
23 use base qw(Koha::Object Koha::Object::Limit::Library);
27 Koha::Patron::Attribute::Type - Koha::Patron::Attribute::Type Object class
37 my $attribute = Koha::Patron::Attribute->new({ code => 'a_code', ... });
38 try { $attribute->store }
39 catch { handle_exception };
47 $self->check_repeatables;
48 $self->check_unique_ids;
50 return $self->SUPER::store();
59 my $attributes_rs = $self->_result->borrower_attributes;
60 Koha::Patron::Attributes->_new_from_dbic($attributes_rs);
63 =head2 Internal Methods
67 =head3 check_repeatables
71 sub check_repeatables {
74 return $self if $self->repeatable;
76 my $count = $self->attributes->search(
79 select => [ { count => 'id', '-as' => 'c' } ],
80 group_by => 'borrowernumber',
81 having => { c => { '>' => 1 } }
85 Koha::Exceptions::Patron::Attribute::Type::CannotChangeProperty->throw(
86 property => 'repeatable' )
92 =head3 check_unique_ids
96 sub check_unique_ids {
99 return $self unless $self->unique_id;
101 my $count = $self->attributes->search(
104 select => [ { count => 'id', '-as' => 'c' } ],
105 group_by => 'attribute',
106 having => { c => { '>' => 1 } }
110 Koha::Exceptions::Patron::Attribute::Type::CannotChangeProperty->throw(
111 property => 'unique_id' )
124 return 'BorrowerAttributeType';
127 =head3 _library_limits
131 sub _library_limits {
133 class => 'BorrowerAttributeTypesBranch',
135 library => 'b_branchcode'