Lines 28-34
use C4::Auth;
Link Here
|
28 |
use C4::Context; |
28 |
use C4::Context; |
29 |
use C4::Output; |
29 |
use C4::Output; |
30 |
use C4::Koha; |
30 |
use C4::Koha; |
31 |
use C4::Members::AttributeTypes; |
|
|
32 |
use Koha::Patron::Attribute::Types; |
31 |
use Koha::Patron::Attribute::Types; |
33 |
|
32 |
|
34 |
use Koha::AuthorisedValues; |
33 |
use Koha::AuthorisedValues; |
Lines 111-163
sub error_add_attribute_type_form {
Link Here
|
111 |
} |
110 |
} |
112 |
|
111 |
|
113 |
sub add_update_attribute_type { |
112 |
sub add_update_attribute_type { |
114 |
my $op = shift; |
113 |
my $op = shift; |
115 |
my $template = shift; |
114 |
my $template = shift; |
116 |
my $code = shift; |
115 |
my $code = shift; |
117 |
|
116 |
|
118 |
my $description = $input->param('description'); |
117 |
my $description = $input->param('description'); |
|
|
118 |
my $repeatable = $input->param('repeatable') || 0; |
119 |
my $unique_id = $input->param('unique_id') || 0; |
120 |
my $opac_display = $input->param('opac_display') || 0; |
121 |
my $opac_editable = $input->param('opac_editable') || 0; |
122 |
my $staff_searchable = $input->param('staff_searchable') || 0; |
123 |
my $authorised_value_category = $input->param('authorised_value_category'); |
124 |
my $display_checkout = $input->param('display_checkout') || 0; |
125 |
my $category_code = $input->param('category_code'); |
126 |
my $class = $input->param('class'); |
119 |
|
127 |
|
120 |
my $attr_type; |
128 |
my $attr_type = Koha::Patron::Attribute::Types->find($code); |
121 |
if ($op eq 'edit') { |
129 |
if ( $op eq 'edit' ) { |
122 |
$attr_type = C4::Members::AttributeTypes->fetch($code); |
|
|
123 |
$attr_type->description($description); |
130 |
$attr_type->description($description); |
124 |
} else { |
131 |
} |
125 |
my $existing = C4::Members::AttributeTypes->fetch($code); |
132 |
else { |
126 |
if (defined($existing)) { |
133 |
if ($attr_type) { # Already exists |
127 |
$template->param(duplicate_code_error => $code); |
134 |
$template->param( duplicate_code_error => $code ); |
|
|
135 |
|
128 |
# FIXME Regression here |
136 |
# FIXME Regression here |
129 |
# Form will not be refilled with entered values on error |
137 |
# Form will not be refilled with entered values on error |
130 |
error_add_attribute_type_form($template); |
138 |
error_add_attribute_type_form($template); |
131 |
return 0; |
139 |
return 0; |
132 |
} |
140 |
} |
133 |
$attr_type = C4::Members::AttributeTypes->new($code, $description); |
141 |
$attr_type = Koha::Patron::Attribute::Type->new( |
134 |
my $repeatable = $input->param('repeatable'); |
142 |
{ |
135 |
$attr_type->repeatable($repeatable); |
143 |
code => $code, |
136 |
my $unique_id = $input->param('unique_id'); |
144 |
description => $description, |
137 |
$attr_type->unique_id($unique_id); |
145 |
repeatable => $repeatable, |
|
|
146 |
unique_id => $unique_id, |
147 |
} |
148 |
); |
138 |
} |
149 |
} |
|
|
150 |
$attr_type->set( |
151 |
{ |
152 |
opac_display => $opac_display, |
153 |
opac_editable => $opac_editable, |
154 |
staff_searchable => $staff_searchable, |
155 |
authorised_value_category => $authorised_value_category, |
156 |
display_checkout => $display_checkout, |
157 |
category_code => $category_code, |
158 |
class => $class, |
159 |
} |
160 |
)->store; |
139 |
|
161 |
|
140 |
my $opac_display = $input->param('opac_display'); |
162 |
my @branches = grep { ! /^\s*$/ } $input->multi_param('branches'); |
141 |
$attr_type->opac_display($opac_display); |
163 |
$attr_type->library_limits( \@branches ); |
142 |
my $opac_editable = $input->param('opac_editable'); |
164 |
|
143 |
$attr_type->opac_editable($opac_editable); |
165 |
if ( $op eq 'edit' ) { |
144 |
my $staff_searchable = $input->param('staff_searchable'); |
166 |
$template->param( edited_attribute_type => $attr_type->code() ); |
145 |
$attr_type->staff_searchable($staff_searchable); |
167 |
} |
146 |
my $authorised_value_category = $input->param('authorised_value_category'); |
168 |
else { |
147 |
$attr_type->authorised_value_category($authorised_value_category); |
169 |
$template->param( added_attribute_type => $attr_type->code() ); |
148 |
my $display_checkout = $input->param('display_checkout'); |
|
|
149 |
$attr_type->display_checkout($display_checkout); |
150 |
$attr_type->category_code(scalar $input->param('category_code')); |
151 |
$attr_type->class(scalar $input->param('class')); |
152 |
my @branches = $input->multi_param('branches'); |
153 |
$attr_type->branches( \@branches ); |
154 |
|
155 |
if ($op eq 'edit') { |
156 |
$template->param(edited_attribute_type => $attr_type->code()); |
157 |
} else { |
158 |
$template->param(added_attribute_type => $attr_type->code()); |
159 |
} |
170 |
} |
160 |
$attr_type->store(); |
|
|
161 |
|
171 |
|
162 |
return 1; |
172 |
return 1; |
163 |
} |
173 |
} |
Lines 166-172
sub delete_attribute_type_form {
Link Here
|
166 |
my $template = shift; |
176 |
my $template = shift; |
167 |
my $code = shift; |
177 |
my $code = shift; |
168 |
|
178 |
|
169 |
my $attr_type = C4::Members::AttributeTypes->fetch($code); |
179 |
my $attr_type = Koha::Patron::Attribute::Types->find($code); |
170 |
my $display_list = 0; |
180 |
my $display_list = 0; |
171 |
if (defined($attr_type)) { |
181 |
if (defined($attr_type)) { |
172 |
$template->param( |
182 |
$template->param( |
Lines 186-201
sub delete_attribute_type {
Link Here
|
186 |
my $template = shift; |
196 |
my $template = shift; |
187 |
my $code = shift; |
197 |
my $code = shift; |
188 |
|
198 |
|
189 |
my $attr_type = C4::Members::AttributeTypes->fetch($code); |
199 |
my $attr_type = Koha::Patron::Attribute::Types->find($code); |
190 |
if (defined($attr_type)) { |
200 |
if (defined($attr_type)) { |
191 |
if ($attr_type->num_patrons() > 0) { |
201 |
# TODO Check must be done for previous step as well |
|
|
202 |
if ( my $num_patrons = Koha::Patrons->filter_by_attribute_type($code)->count ) { |
192 |
$template->param(ERROR_delete_in_use => $code); |
203 |
$template->param(ERROR_delete_in_use => $code); |
193 |
$template->param(ERROR_num_patrons => $attr_type->num_patrons()); |
204 |
$template->param(ERROR_num_patrons => $num_patrons ); |
194 |
} else { |
205 |
} else { |
195 |
$attr_type->delete(); |
206 |
$attr_type->delete(); |
196 |
$template->param(deleted_attribute_type => $code); |
207 |
$template->param(deleted_attribute_type => $code); |
197 |
} |
208 |
} |
198 |
} else { |
209 |
} else { |
|
|
210 |
# FIXME Really needed? |
199 |
$template->param(ERROR_delete_not_found => $code); |
211 |
$template->param(ERROR_delete_not_found => $code); |
200 |
} |
212 |
} |
201 |
} |
213 |
} |
202 |
- |
|
|