View | Details | Raw Unified | Return to bug 15163
Collapse All | Expand All

(-)a/C4/Members/Attributes.pm (-3 / +32 lines)
Lines 71-77 marked for OPAC display are returned. Link Here
71
sub GetBorrowerAttributes {
71
sub GetBorrowerAttributes {
72
    my $borrowernumber = shift;
72
    my $borrowernumber = shift;
73
    my $opac_only = @_ ? shift : 0;
73
    my $opac_only = @_ ? shift : 0;
74
    my $branch_limit = @_ ? shift : 0;
75
74
76
    my $dbh = C4::Context->dbh();
75
    my $dbh = C4::Context->dbh();
77
    my $query = "SELECT code, description, attribute, lib, password, display_checkout, category_code, class
76
    my $query = "SELECT code, description, attribute, lib, password, display_checkout, category_code, class
Lines 220-227 sub SetBorrowerAttributes { Link Here
220
    my $attr_list = shift;
219
    my $attr_list = shift;
221
220
222
    my $dbh = C4::Context->dbh;
221
    my $dbh = C4::Context->dbh;
223
    my $delsth = $dbh->prepare("DELETE FROM borrower_attributes WHERE borrowernumber = ?");
222
224
    $delsth->execute($borrowernumber);
223
    DeleteBorrowerAttributes( $borrowernumber );
225
224
226
    my $sth = $dbh->prepare("INSERT INTO borrower_attributes (borrowernumber, code, attribute, password)
225
    my $sth = $dbh->prepare("INSERT INTO borrower_attributes (borrowernumber, code, attribute, password)
227
                             VALUES (?, ?, ?, ?)");
226
                             VALUES (?, ?, ?, ?)");
Lines 236-241 sub SetBorrowerAttributes { Link Here
236
    return 1; # borrower attributes successfully set
235
    return 1; # borrower attributes successfully set
237
}
236
}
238
237
238
=head2 DeleteBorrowerAttributes
239
240
  DeleteBorrowerAttributes($borrowernumber);
241
242
Delete borrower attributes for the patron identified by C<$borrowernumber>.
243
244
=cut
245
246
sub DeleteBorrowerAttributes {
247
    my $borrowernumber = shift;
248
    my $no_branch_limit = @_ ? shift : 0;
249
    my $branch_limit = $no_branch_limit
250
        ? 0
251
        : C4::Context->userenv ? C4::Context->userenv->{"branch"} : 0;
252
253
    my $dbh = C4::Context->dbh;
254
    my $query = q{
255
        DELETE FROM borrower_attributes
256
        };
257
    $query .= q{
258
        LEFT JOIN borrower_attribute_types_branches ON bat_code = code
259
        WHERE b_branchcode = ? OR b_branchcode IS NULL
260
    } if $branch_limit;
261
    $query .= q{
262
        WHERE borrowernumber = ?
263
    };
264
265
    $dbh->do( $query, undef, $branch_limit ? $branch_limit : (), $borrowernumber );
266
}
267
239
=head2 DeleteBorrowerAttribute
268
=head2 DeleteBorrowerAttribute
240
269
241
  DeleteBorrowerAttribute($borrowernumber, $attribute);
270
  DeleteBorrowerAttribute($borrowernumber, $attribute);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt (-3 / +8 lines)
Lines 1022-1029 Link Here
1022
        [% END %]
1022
        [% END %]
1023
        <ol class="attributes_table">
1023
        <ol class="attributes_table">
1024
            [% FOREACH patron_attribute IN pa_loo.items %]
1024
            [% FOREACH patron_attribute IN pa_loo.items %]
1025
                <li data-category_code="[% patron_attribute.category_code %]">
1025
                [% IF patron_attribute.limited_to_another_branch %]
1026
                    <label for="[% patron_attribute.form_id %]">[% patron_attribute.description %]: </label>
1026
                    <input type="hidden" id="[% patron_attribute.form_id %]_code" name="[% patron_attribute.form_id %]_code" value="[% patron_attribute.code |html %]" />
1027
                    <input type="hidden" id="[% patron_attribute.form_id %]" name="[% patron_attribute.form_id %]" value="[% patron_attribute.value |html %]" />
1028
                [% ELSE %]
1029
                    <li data-category_code="[% patron_attribute.category_code %]">
1030
                        <label for="[% patron_attribute.form_id %]">[% patron_attribute.description %]: </label>
1027
                        <input type="hidden" id="[% patron_attribute.form_id %]_code" name="[% patron_attribute.form_id %]_code" value="[% patron_attribute.code |html %]" />
1031
                        <input type="hidden" id="[% patron_attribute.form_id %]_code" name="[% patron_attribute.form_id %]_code" value="[% patron_attribute.code |html %]" />
1028
                        [% IF ( patron_attribute.use_dropdown ) %]
1032
                        [% IF ( patron_attribute.use_dropdown ) %]
1029
                            <select id="[% patron_attribute.form_id %]" name="[% patron_attribute.form_id %]">
1033
                            <select id="[% patron_attribute.form_id %]" name="[% patron_attribute.form_id %]">
Lines 1051-1057 Link Here
1051
                        [% IF ( patron_attribute.repeatable ) %]
1055
                        [% IF ( patron_attribute.repeatable ) %]
1052
                        <a href="#" class="clone-field" onclick="clone_entry(this); return false;">New</a>
1056
                        <a href="#" class="clone-field" onclick="clone_entry(this); return false;">New</a>
1053
                        [% END %]
1057
                        [% END %]
1054
                </li>
1058
                    </li>
1059
                [% END %]
1055
            [% END %]
1060
            [% END %]
1056
        </ol>
1061
        </ol>
1057
        [% IF pa_loo.class %]</fieldset>[% END %]
1062
        [% IF pa_loo.class %]</fieldset>[% END %]
(-)a/members/memberentry.pl (-1 / +7 lines)
Lines 745-751 sub patron_attributes_form { Link Here
745
    my $template = shift;
745
    my $template = shift;
746
    my $borrowernumber = shift;
746
    my $borrowernumber = shift;
747
747
748
    my @types = C4::Members::AttributeTypes::GetAttributeTypes();
748
    my @types = C4::Members::AttributeTypes::GetAttributeTypes(1, 1);
749
    if (scalar(@types) == 0) {
749
    if (scalar(@types) == 0) {
750
        $template->param(no_patron_attribute_types => 1);
750
        $template->param(no_patron_attribute_types => 1);
751
        return;
751
        return;
Lines 763-770 sub patron_attributes_form { Link Here
763
    my @attribute_loop = ();
763
    my @attribute_loop = ();
764
    my $i = 0;
764
    my $i = 0;
765
    my %items_by_class;
765
    my %items_by_class;
766
    my $user_branch = C4::Context->userenv->{"branch"};
766
    foreach my $type_code (map { $_->{code} } @types) {
767
    foreach my $type_code (map { $_->{code} } @types) {
767
        my $attr_type = C4::Members::AttributeTypes->fetch($type_code);
768
        my $attr_type = C4::Members::AttributeTypes->fetch($type_code);
769
        my $limited_to_another_branch = 0;
770
        if ( my $branch_limitations = $attr_type->branches ) {
771
            $limited_to_another_branch = not grep { /^$user_branch$/ } @$branch_limitations;
772
        }
768
        my $entry = {
773
        my $entry = {
769
            class             => $attr_type->class(),
774
            class             => $attr_type->class(),
770
            code              => $attr_type->code(),
775
            code              => $attr_type->code(),
Lines 774-779 sub patron_attributes_form { Link Here
774
            category          => $attr_type->authorised_value_category(),
779
            category          => $attr_type->authorised_value_category(),
775
            category_code     => $attr_type->category_code(),
780
            category_code     => $attr_type->category_code(),
776
            password          => '',
781
            password          => '',
782
            limited_to_another_branch => $limited_to_another_branch,
777
        };
783
        };
778
        if (exists $attr_hash{$attr_type->code()}) {
784
        if (exists $attr_hash{$attr_type->code()}) {
779
            foreach my $attr (@{ $attr_hash{$attr_type->code()} }) {
785
            foreach my $attr (@{ $attr_hash{$attr_type->code()} }) {
(-)a/t/db_dependent/Members_Attributes.t (-27 / +39 lines)
Lines 23-30 use C4::Context; Link Here
23
use C4::Members;
23
use C4::Members;
24
use C4::Members::AttributeTypes;
24
use C4::Members::AttributeTypes;
25
use Koha::Database;
25
use Koha::Database;
26
use t::lib::TestBuilder;
26
27
27
use Test::More tests => 60;
28
use Test::More;# tests => 60;
28
29
29
use t::lib::TestBuilder;
30
use t::lib::TestBuilder;
30
31
Lines 44-66 $dbh->do(q|DELETE FROM borrower_attribute_types|); Link Here
44
my $library = $builder->build({
45
my $library = $builder->build({
45
    source => 'Branch',
46
    source => 'Branch',
46
});
47
});
47
my $borrowernumber = AddMember(
48
    firstname =>  'my firstname',
49
    surname => 'my surname',
50
    categorycode => 'S',
51
    branchcode => $library->{branchcode},
52
);
53
48
49
my $patron = $builder->build(
50
    {   source => 'Borrower',
51
        value  => {
52
            firstname    => 'my firstname',
53
            surname      => 'my surname',
54
            categorycode => 'S',
55
            branchcode => $library->{branchcode},
56
        }
57
    }
58
);
59
C4::Context->set_userenv(123, 'userid', 'usercnum', 'First name', 'Surname', $library->{branchcode}, 'My Library', 0);
60
my $borrowernumber = $patron->{borrowernumber};
54
61
55
my $attribute_type1 = C4::Members::AttributeTypes->new('my code1', 'my description1');
62
my $attribute_type1 = C4::Members::AttributeTypes->new('my code1', 'my description1');
56
$attribute_type1->unique_id(1);
63
$attribute_type1->unique_id(1);
57
my $attribute_type2 = C4::Members::AttributeTypes->new('my code2', 'my description2');
58
$attribute_type2->opac_display(1);
59
$attribute_type2->staff_searchable(1);
60
61
my $attribute_types = C4::Members::Attributes::GetAttributes();
64
my $attribute_types = C4::Members::Attributes::GetAttributes();
62
is( @$attribute_types, 0, 'GetAttributes returns the correct number of attribute types' );
65
is( @$attribute_types, 0, 'GetAttributes returns the correct number of attribute types' );
63
64
$attribute_type1->store();
66
$attribute_type1->store();
65
$attribute_types = C4::Members::Attributes::GetAttributes();
67
$attribute_types = C4::Members::Attributes::GetAttributes();
66
is( @$attribute_types, 1, 'GetAttributes returns the correct number of attribute types' );
68
is( @$attribute_types, 1, 'GetAttributes returns the correct number of attribute types' );
Lines 68-73 is( $attribute_types->[0], $attribute_type1->code(), 'GetAttributes returns the Link Here
68
$attribute_types = C4::Members::Attributes::GetAttributes(1);
70
$attribute_types = C4::Members::Attributes::GetAttributes(1);
69
is( @$attribute_types, 0, 'GetAttributes returns the correct number of attribute types with the filter opac_only' );
71
is( @$attribute_types, 0, 'GetAttributes returns the correct number of attribute types with the filter opac_only' );
70
72
73
my $attribute_type2 = C4::Members::AttributeTypes->new('my code2', 'my description2');
74
$attribute_type2->opac_display(1);
75
$attribute_type2->staff_searchable(1);
71
$attribute_type2->store();
76
$attribute_type2->store();
72
$attribute_types = C4::Members::Attributes::GetAttributes();
77
$attribute_types = C4::Members::Attributes::GetAttributes();
73
is( @$attribute_types, 2, 'GetAttributes returns the correct number of attribute types' );
78
is( @$attribute_types, 2, 'GetAttributes returns the correct number of attribute types' );
Lines 75-80 is( $attribute_types->[1], $attribute_type2->code(), 'GetAttributes returns the Link Here
75
$attribute_types = C4::Members::Attributes::GetAttributes(1);
80
$attribute_types = C4::Members::Attributes::GetAttributes(1);
76
is( @$attribute_types, 1, 'GetAttributes returns the correct number of attribute types with the filter opac_only' );
81
is( @$attribute_types, 1, 'GetAttributes returns the correct number of attribute types with the filter opac_only' );
77
82
83
my $new_library = $builder->build( { source => 'Branch' } );
84
my $attribute_type_limited = C4::Members::AttributeTypes->new('my code3', 'my description3');
85
$attribute_type_limited->branches([ $new_library->{branchcode} ]);
86
$attribute_type_limited->store;
78
87
79
my $borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes();
88
my $borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes();
80
is( @$borrower_attributes, 0, 'GetBorrowerAttributes without the borrower number returns an empty array' );
89
is( @$borrower_attributes, 0, 'GetBorrowerAttributes without the borrower number returns an empty array' );
Lines 91-96 my $attributes = [ Link Here
91
        value => 'my attribute2',
100
        value => 'my attribute2',
92
        code => $attribute_type2->code(),
101
        code => $attribute_type2->code(),
93
        password => 'my password2',
102
        password => 'my password2',
103
    },
104
    {
105
        value => 'my attribute limited',
106
        code => $attribute_type_limited->code(),
94
    }
107
    }
95
];
108
];
96
109
Lines 107-113 is( $set_borrower_attributes, 1, 'SetBorrowerAttributes returns the success code Link Here
107
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes();
120
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes();
108
is( @$borrower_attributes, 0, 'GetBorrowerAttributes without the borrower number returns an empty array' );
121
is( @$borrower_attributes, 0, 'GetBorrowerAttributes without the borrower number returns an empty array' );
109
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
122
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
110
is( @$borrower_attributes, 2, 'GetBorrowerAttributes returns the correct number of borrower attributes' );
123
is( @$borrower_attributes, 3, 'GetBorrowerAttributes returns the correct number of borrower attributes' );
111
is( $borrower_attributes->[0]->{code}, $attributes->[0]->{code}, 'SetBorrowerAttributes stores the correct code correctly' );
124
is( $borrower_attributes->[0]->{code}, $attributes->[0]->{code}, 'SetBorrowerAttributes stores the correct code correctly' );
112
is( $borrower_attributes->[0]->{description}, $attribute_type1->description(), 'SetBorrowerAttributes stores the field description correctly' );
125
is( $borrower_attributes->[0]->{description}, $attribute_type1->description(), 'SetBorrowerAttributes stores the field description correctly' );
113
is( $borrower_attributes->[0]->{value}, $attributes->[0]->{value}, 'SetBorrowerAttributes stores the field value correctly' );
126
is( $borrower_attributes->[0]->{value}, $attributes->[0]->{value}, 'SetBorrowerAttributes stores the field value correctly' );
Lines 116-129 is( $borrower_attributes->[1]->{code}, $attributes->[1]->{code}, 'SetBorrowerAtt Link Here
116
is( $borrower_attributes->[1]->{description}, $attribute_type2->description(), 'SetBorrowerAttributes stores the field description correctly' );
129
is( $borrower_attributes->[1]->{description}, $attribute_type2->description(), 'SetBorrowerAttributes stores the field description correctly' );
117
is( $borrower_attributes->[1]->{value}, $attributes->[1]->{value}, 'SetBorrowerAttributes stores the field value correctly' );
130
is( $borrower_attributes->[1]->{value}, $attributes->[1]->{value}, 'SetBorrowerAttributes stores the field value correctly' );
118
is( $borrower_attributes->[1]->{password}, $attributes->[1]->{password}, 'SetBorrowerAttributes stores the field password correctly' );
131
is( $borrower_attributes->[1]->{password}, $attributes->[1]->{password}, 'SetBorrowerAttributes stores the field password correctly' );
132
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
133
is( @$borrower_attributes, 3, 'GetBorrowerAttributes returns the correct number of borrower attributes' );
119
134
120
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber, 1);
135
# TODO This is not implemented yet
121
is( @$borrower_attributes, 1, 'GetBorrowerAttributes returns the correct number of borrower attributes with the filter opac_only' );
136
#$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber, undef, 'branch_limited');
122
is( $borrower_attributes->[0]->{code}, $attributes->[1]->{code}, 'GetBorrowerAttributes returns the correct code' );
137
#is( @$borrower_attributes, 2, 'GetBorrowerAttributes returns the correct number of borrower attributes filtered on library' );
123
is( $borrower_attributes->[0]->{description}, $attribute_type2->description(), 'GetBorrowerAttributes returns the correct description' );
124
is( $borrower_attributes->[0]->{value}, $attributes->[1]->{value}, 'GetBorrowerAttributes returns the correct value' );
125
is( $borrower_attributes->[0]->{password}, $attributes->[1]->{password}, 'GetBorrowerAttributes returns the correct password' );
126
127
138
128
my $attribute_value = C4::Members::Attributes::GetBorrowerAttributeValue();
139
my $attribute_value = C4::Members::Attributes::GetBorrowerAttributeValue();
129
is( $attribute_value, undef, 'GetBorrowerAttributeValue without arguments returns undef' );
140
is( $attribute_value, undef, 'GetBorrowerAttributeValue without arguments returns undef' );
Lines 147-153 my $attribute = { Link Here
147
};
158
};
148
C4::Members::Attributes::UpdateBorrowerAttribute($borrowernumber, $attribute);
159
C4::Members::Attributes::UpdateBorrowerAttribute($borrowernumber, $attribute);
149
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
160
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
150
is( @$borrower_attributes, 2, 'UpdateBorrowerAttribute does not change the number of borrower attributes' );
161
is( @$borrower_attributes, 3, 'UpdateBorrowerAttribute does not change the number of borrower attributes' );
151
is( $borrower_attributes->[0]->{code}, $attribute->{code}, 'UpdateBorrowerAttribute updates the field code correctly' );
162
is( $borrower_attributes->[0]->{code}, $attribute->{code}, 'UpdateBorrowerAttribute updates the field code correctly' );
152
is( $borrower_attributes->[0]->{description}, $attribute_type1->description(), 'UpdateBorrowerAttribute updates the field description correctly' );
163
is( $borrower_attributes->[0]->{description}, $attribute_type1->description(), 'UpdateBorrowerAttribute updates the field description correctly' );
153
is( $borrower_attributes->[0]->{value}, $attribute->{attribute}, 'UpdateBorrowerAttribute updates the field value correctly' );
164
is( $borrower_attributes->[0]->{value}, $attribute->{attribute}, 'UpdateBorrowerAttribute updates the field value correctly' );
Lines 185-201 for my $attr( split(' ', $attributes->[1]->{value}) ) { Link Here
185
196
186
C4::Members::Attributes::DeleteBorrowerAttribute();
197
C4::Members::Attributes::DeleteBorrowerAttribute();
187
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
198
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
188
is( @$borrower_attributes, 2, 'DeleteBorrowerAttribute without arguments deletes nothing' );
199
is( @$borrower_attributes, 3, 'DeleteBorrowerAttribute without arguments deletes nothing' );
189
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber);
200
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber);
190
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
201
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
191
is( @$borrower_attributes, 2, 'DeleteBorrowerAttribute without the attribute deletes nothing' );
202
is( @$borrower_attributes, 3, 'DeleteBorrowerAttribute without the attribute deletes nothing' );
192
C4::Members::Attributes::DeleteBorrowerAttribute(undef, $attribute);
203
C4::Members::Attributes::DeleteBorrowerAttribute(undef, $attribute);
193
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
204
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
194
is( @$borrower_attributes, 2, 'DeleteBorrowerAttribute with a undef borrower number deletes nothing' );
205
is( @$borrower_attributes, 3, 'DeleteBorrowerAttribute with a undef borrower number deletes nothing' );
195
206
196
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attribute);
207
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attribute);
197
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
208
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
198
is( @$borrower_attributes, 1, 'DeleteBorrowerAttribute deletes a borrower attribute' );
209
is( @$borrower_attributes, 2, 'DeleteBorrowerAttribute deletes a borrower attribute' );
199
is( $borrower_attributes->[0]->{code}, $attributes->[1]->{code}, 'DeleteBorrowerAttribute deletes the correct entry');
210
is( $borrower_attributes->[0]->{code}, $attributes->[1]->{code}, 'DeleteBorrowerAttribute deletes the correct entry');
200
is( $borrower_attributes->[0]->{description}, $attribute_type2->description(), 'DeleteBorrowerAttribute deletes the correct entry');
211
is( $borrower_attributes->[0]->{description}, $attribute_type2->description(), 'DeleteBorrowerAttribute deletes the correct entry');
201
is( $borrower_attributes->[0]->{value}, $attributes->[1]->{value}, 'DeleteBorrowerAttribute deletes the correct entry');
212
is( $borrower_attributes->[0]->{value}, $attributes->[1]->{value}, 'DeleteBorrowerAttribute deletes the correct entry');
Lines 203-206 is( $borrower_attributes->[0]->{password}, $attributes->[1]->{password}, 'Delete Link Here
203
214
204
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attributes->[1]);
215
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attributes->[1]);
205
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
216
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
206
is( @$borrower_attributes, 0, 'DeleteBorrowerAttribute deletes a borrower attribute' );
217
is( @$borrower_attributes, 1, 'DeleteBorrowerAttribute deletes a borrower attribute' );
218
219
done_testing;
207
- 

Return to bug 15163