|
Lines 18-23
package Koha::Patron::Attribute;
Link Here
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Koha::Database; |
20 |
use Koha::Database; |
|
|
21 |
use Koha::Exceptions; |
| 21 |
use Koha::Exceptions::Patron::Attribute; |
22 |
use Koha::Exceptions::Patron::Attribute; |
| 22 |
use Koha::Patron::Attribute::Types; |
23 |
use Koha::Patron::Attribute::Types; |
| 23 |
use Koha::AuthorisedValues; |
24 |
use Koha::AuthorisedValues; |
|
Lines 46-52
sub store {
Link Here
|
| 46 |
|
47 |
|
| 47 |
my $self = shift; |
48 |
my $self = shift; |
| 48 |
|
49 |
|
| 49 |
my $type = $self->type; |
50 |
my $type; |
|
|
51 |
|
| 52 |
if ( $self->in_storage ) { |
| 53 |
$type = $self->type; |
| 54 |
} |
| 55 |
else { |
| 56 |
$type = Koha::Patron::Attribute::Types->find( $self->code ); |
| 57 |
} |
| 50 |
|
58 |
|
| 51 |
Koha::Exceptions::Patron::Attribute::InvalidType->throw( type => $self->code ) |
59 |
Koha::Exceptions::Patron::Attribute::InvalidType->throw( type => $self->code ) |
| 52 |
unless $type; |
60 |
unless $type; |
|
Lines 72-78
sub type {
Link Here
|
| 72 |
|
80 |
|
| 73 |
my $self = shift; |
81 |
my $self = shift; |
| 74 |
|
82 |
|
| 75 |
return scalar Koha::Patron::Attribute::Types->find( $self->code ); |
83 |
return Koha::Patron::Attribute::Type->_new_from_dbic( $self->_result->code ); |
| 76 |
} |
84 |
} |
| 77 |
|
85 |
|
| 78 |
=head3 authorised_value |
86 |
=head3 authorised_value |
|
Lines 138-143
sub to_api_mapping {
Link Here
|
| 138 |
|
146 |
|
| 139 |
=head3 repeatable_ok |
147 |
=head3 repeatable_ok |
| 140 |
|
148 |
|
|
|
149 |
if ( $attr->repeatable_ok( $type ) ) { ... } |
| 150 |
|
| 141 |
Checks if the attribute type is repeatable and returns a boolean representing |
151 |
Checks if the attribute type is repeatable and returns a boolean representing |
| 142 |
whether storing the current object state would break the repeatable constraint. |
152 |
whether storing the current object state would break the repeatable constraint. |
| 143 |
|
153 |
|
|
Lines 147-152
sub repeatable_ok {
Link Here
|
| 147 |
|
157 |
|
| 148 |
my ( $self, $type ) = @_; |
158 |
my ( $self, $type ) = @_; |
| 149 |
|
159 |
|
|
|
160 |
Koha::Exceptions::MissingParameter->throw( "The type parameter is mandatory" ) |
| 161 |
unless $type; |
| 162 |
|
| 150 |
my $ok = 1; |
163 |
my $ok = 1; |
| 151 |
if ( !$type->repeatable ) { |
164 |
if ( !$type->repeatable ) { |
| 152 |
my $params = { |
165 |
my $params = { |
|
Lines 165-170
sub repeatable_ok {
Link Here
|
| 165 |
|
178 |
|
| 166 |
=head3 unique_ok |
179 |
=head3 unique_ok |
| 167 |
|
180 |
|
|
|
181 |
if ( $attr->unique_ok( $type ) ) { ... } |
| 182 |
|
| 168 |
Checks if the attribute type is marked as unique and returns a boolean representing |
183 |
Checks if the attribute type is marked as unique and returns a boolean representing |
| 169 |
whether storing the current object state would break the unique constraint. |
184 |
whether storing the current object state would break the unique constraint. |
| 170 |
|
185 |
|
|
Lines 174-179
sub unique_ok {
Link Here
|
| 174 |
|
189 |
|
| 175 |
my ( $self, $type ) = @_; |
190 |
my ( $self, $type ) = @_; |
| 176 |
|
191 |
|
|
|
192 |
Koha::Exceptions::MissingParameter->throw( "The type parameter is mandatory" ) |
| 193 |
unless $type; |
| 194 |
|
| 177 |
my $ok = 1; |
195 |
my $ok = 1; |
| 178 |
if ( $type->unique_id ) { |
196 |
if ( $type->unique_id ) { |
| 179 |
my $params = { code => $self->code, attribute => $self->attribute }; |
197 |
my $params = { code => $self->code, attribute => $self->attribute }; |