Lines 108-150
Koha::Patron - Koha Patron Object class
Link Here
|
108 |
|
108 |
|
109 |
=head2 Class Methods |
109 |
=head2 Class Methods |
110 |
|
110 |
|
111 |
=head3 new, _new_from_dbic, _add_dynamic_methods |
111 |
=head3 new |
112 |
|
112 |
|
113 |
These methods are used internally. They dynamically add accessors to Koha::Patron objects resulting from |
113 |
Our methods below include an AUTOLOAD that will dynamically create accessor methods for any |
114 |
calls to ->new, ->find and ->search for any defined extended patron attributes. Said accessors will be named |
114 |
defined extended patron attributes. |
115 |
after the 'code' of the attribute type and will return either the single value or an array of values for |
|
|
116 |
attribute types that are repeatable. |
117 |
|
115 |
|
118 |
=cut |
116 |
Said accessors will be named after the 'code' of the attribute type and will return either |
119 |
|
117 |
the single value or an array of values for attribute types that are repeatable. |
120 |
sub new { |
|
|
121 |
my ( $class, $params ) = @_; |
122 |
|
123 |
my $self = $class->next::method($params); |
124 |
|
125 |
$self->_add_dynamic_methods; |
126 |
|
118 |
|
127 |
return $self; |
119 |
=cut |
128 |
} |
|
|
129 |
|
130 |
sub _new_from_dbic { |
131 |
my $self = shift; |
132 |
my ( $source, $data, $prefetch ) = @_; |
133 |
|
134 |
my $obj = $self->next::method(@_); |
135 |
|
120 |
|
136 |
$obj->_add_dynamic_methods; |
121 |
our $AUTOLOAD; |
137 |
|
122 |
|
138 |
return $obj; |
123 |
# This autoload generates a method for each extended attribute type defined in the system upon the first call |
139 |
} |
124 |
# for a method matching an attribute type name. |
|
|
125 |
# |
126 |
# TODO: This could be abstracted in the future as a Mixin for extended_attribute, ill_attributes and additional_fields |
140 |
|
127 |
|
141 |
sub _add_dynamic_methods { |
128 |
sub AUTOLOAD { |
142 |
my $self = shift; |
129 |
my @args = @_; |
|
|
130 |
my $self = shift(@args); |
131 |
my $name = $AUTOLOAD; |
132 |
$name =~ s/.*:://; # Remove package name |
133 |
my $found = 0; |
143 |
|
134 |
|
144 |
# Fetch attributes dynamically |
135 |
# Fetch attributes dynamically |
145 |
my $attribute_types = Koha::Patron::Attribute::Types->search(); |
136 |
my $attribute_types = Koha::Patron::Attribute::Types->search(); |
146 |
while ( my $attr = $attribute_types->next ) { |
137 |
while ( my $attr = $attribute_types->next ) { |
147 |
my $code = $attr->code; |
138 |
my $code = $attr->code; |
|
|
139 |
$found = 1 if ( $code eq $name ); |
148 |
|
140 |
|
149 |
# Dynamically create accessor method |
141 |
# Dynamically create accessor method |
150 |
no strict 'refs'; |
142 |
no strict 'refs'; |
Lines 170-175
sub _add_dynamic_methods {
Link Here
|
170 |
} |
162 |
} |
171 |
} |
163 |
} |
172 |
} |
164 |
} |
|
|
165 |
|
166 |
if ($found) { |
167 |
return $self->$name(); |
168 |
} else { |
169 |
my $wt = 'SUPER::' . $name; |
170 |
return $self->$wt(@args); |
171 |
} |
172 |
} |
173 |
|
174 |
sub new { |
175 |
my ( $class, $params ) = @_; |
176 |
|
177 |
return $class->SUPER::new($params); |
173 |
} |
178 |
} |
174 |
|
179 |
|
175 |
=head3 fixup_cardnumber |
180 |
=head3 fixup_cardnumber |
176 |
- |
|
|