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

(-)a/C4/Installer/PerlDependencies.pm (+13 lines)
Lines 634-639 our $PERL_DEPS = { Link Here
634
        'required' => '1',
634
        'required' => '1',
635
        'min_ver'  => '0.22',
635
        'min_ver'  => '0.22',
636
    },
636
    },
637
    'DBIx::SearchBuilder' => {
638
        'usage'    => 'Core',
639
        'required' => '1',
640
        'min_ver'  => '1.56',
641
    },
642
    'DBIx::SearchBuilder::Record' => {
643
        'usage'    => 'Core',
644
        'required' => '1',
645
    },
646
    'DBIx::SearchBuilder::Handle' => {
647
        'usage'    => 'Core',
648
        'required' => '1',
649
    },
637
};
650
};
638
651
639
1;
652
1;
(-)a/Koha/DataObject/AuthorisedValue.pm (+61 lines)
Line 0 Link Here
1
package Koha::DataObject::AuthorisedValue;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 2 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
=head1 NAME
19
20
Koha::DataObject::AuthorisedValue - Row-level class for the authorised_values table
21
22
=cut
23
24
use base qw/Koha::SearchBuilder::Record/;
25
26
use Modern::Perl;
27
28
sub _Init {
29
    my $self = shift;
30
31
    $self->Table("authorised_values");
32
33
    return $self->SUPER::_Init(@_);
34
}
35
36
# Tell Record what the primary keys are
37
sub _PrimaryKeys {
38
    return ['id'];
39
}
40
41
sub _ClassAccessible {
42
    {
43
        id               => { 'read' => 1, 'auto' => 1, 'public' => 1, },
44
        category         => { 'read' => 1, 'auto' => 1, 'public' => 1, },
45
        authorised_value => { 'read' => 1, 'auto' => 1, 'public' => 1, },
46
        lib              => { 'read' => 1, 'auto' => 1, 'public' => 1, },
47
        lib_opac         => { 'read' => 1, 'auto' => 1, 'public' => 1, },
48
        mageurl          => { 'read' => 1, 'auto' => 1, 'public' => 1, },
49
    };
50
}
51
52
53
=head1 AUTHOR
54
55
Kyle M Hall, E<lt>khall@bywatersolutions.comE<gt>
56
57
=cut
58
59
1;
60
61
__END__
(-)a/Koha/DataObject/AuthorisedValues.pm (+39 lines)
Line 0 Link Here
1
package Koha::DataObject::AuthorisedValues;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 2 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
=head1 NAME
19
20
Koha::DataObject::AuthorisedValues - Table level class for the authorised_values table
21
22
=cut
23
24
use base qw/Koha::SearchBuilder/;
25
26
sub _Init {
27
    my $self = shift;
28
29
    $self->Table("authorised_values");
30
31
    return $self->SUPER::_Init(@_);
32
}
33
34
sub NewItem {
35
    my $self = shift;
36
    return ( Koha::DataObject::AuthorisedValue->new() );
37
}
38
39
1;
(-)a/Koha/SearchBuilder.pm (+54 lines)
Line 0 Link Here
1
package Koha::SearchBuilder;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 2 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
=head1 NAME
19
20
Koha::SearchBuilder - Koha specific class derived from DBIx::SearchBuilder
21
22
Base class for plural Koha::DataObject classes. Subclasses must provide the following methods
23
24
B<_Init> - Initializes object
25
26
B<NewItem> - Returns an instance of the singular version of this class.
27
28
=head1 FUNCTIONS
29
30
=cut
31
32
use base qw/DBIx::SearchBuilder/;
33
34
use Modern::Perl;
35
36
sub _Init {
37
    my $self = shift;
38
39
    $self->SUPER::_Init(@_);
40
41
    my $handle = Koha::SearchBuilder::Handle->new();
42
    $handle->Connect();
43
    $self->_Handle( $handle ); 
44
}
45
46
=head1 AUTHOR
47
48
Kyle M Hall, E<lt>khall@bywatersolutions.comE<gt>
49
50
=cut
51
52
1;
53
54
__END__
(-)a/Koha/SearchBuilder/Handle.pm (+65 lines)
Line 0 Link Here
1
package Koha::SearchBuilder::Handle;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 2 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
=head1 NAME
19
20
Koha::SearchBuilder::Handle - Koha specific class derived from DBIx::SearchBuilder::Handle
21
22
=cut
23
24
use base qw/DBIx::SearchBuilder::Handle/;
25
26
use Modern::Perl;
27
28
use C4::Context;
29
30
sub Connect {
31
    my $self = shift;
32
    my %args = (@_);
33
34
    my $driver = C4::Context::db_scheme2dbi( C4::Context->config('db_scheme') );
35
36
    $self->SUPER::Connect(
37
	Driver => $driver,
38
        User => C4::Context->config('user'),,
39
        Password => C4::Context->config('pass'),
40
	Host     => C4::Context->config('hostname'),
41
	Database => C4::Context->config('database'),
42
        %args,
43
    );
44
45
    if ( $driver eq 'mysql' ) {
46
        my $version = $self->DatabaseVersion;
47
        ($version) = $version =~ /^(\d+\.\d+)/;
48
        $self->dbh->do("SET NAMES 'utf8'") if $version >= 4.1;
49
    }
50
    elsif ( $driver eq 'Pg' ) {
51
        my $version = $self->DatabaseVersion;
52
        ($version) = $version =~ /^(\d+\.\d+)/;
53
        $self->dbh->do("SET bytea_output = 'escape'") if $version >= 9.0;
54
    }
55
}
56
57
=head1 AUTHOR
58
59
Kyle M Hall, E<lt>khall@bywatersolutions.comE<gt>
60
61
=cut
62
63
1;
64
65
__END__
(-)a/Koha/SearchBuilder/Record.pm (+62 lines)
Line 0 Link Here
1
package Koha::SearchBuilder::Record;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 2 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
=head1 NAME
19
20
Koha::SearchBuilder::Record - Koha specific class derived from DBIx::SearchBuilder::Record
21
22
Base class for singular (row-level) Koha::DataObject classes. Subclasses must provide the following methods
23
24
B<_Init> - Initializes object
25
26
B<_PrimaryKeys> - Returns an array of the primary keys for this classes table
27
28
Subclasses may override the following methods:
29
30
B<_ClassAccessible> - Describes the table and allows for accessor functions ( e.g. $record->fieldname() )
31
32
=head1 FUNCTIONS
33
34
=cut
35
36
use base qw/DBIx::SearchBuilder::Record/;
37
38
use Modern::Perl;
39
40
use Koha::SearchBuilder::Handle;
41
42
sub _Init {
43
    my $self = shift;
44
45
    $self->SUPER::_Init(@_);
46
47
    my $handle = Koha::SearchBuilder::Handle->new();
48
    $handle->Connect();
49
50
    $self->_Handle( $handle );
51
}
52
53
=head1 AUTHOR
54
55
Kyle M Hall, E<lt>khall@bywatersolutions.comE<gt>
56
57
=cut
58
59
1;
60
61
__END__
62
(-)a/t/db_dependent/SearchBuilder.t (-1 / +38 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use strict;
4
use warnings;
5
6
use Test::More tests => 8;
7
8
BEGIN {
9
    use_ok('Koha::SearchBuilder');
10
    use_ok('Koha::SearchBuilder::Handle');
11
    use_ok('Koha::SearchBuilder::Record');
12
    use_ok('Koha::DataObject::AuthorisedValue');
13
    use_ok('Koha::DataObject::AuthorisedValues');
14
}
15
16
my $av = Koha::DataObject::AuthorisedValue->new();
17
18
$av->Create(
19
    'category' => 'Foo',
20
    'authorised_value' => 'Bar',
21
    'lib' => 'libFoo',
22
    'lib_opac' => 'opacFoo',
23
);
24
25
my $avs = Koha::DataObject::AuthorisedValues->new();
26
$avs->Limit( FIELD => "category", VALUE => "Foo" );
27
my $record = $avs->Next();
28
ok( $record->authorised_value() eq "Bar", "Create, Limit, Next, and field value getter working correctly");
29
30
my $av_id = $record->id();
31
32
$av->LoadById($av_id);
33
ok( $av->lib_opac() eq 'opacFoo', "LoadById functions correctly" );
34
35
$record->Delete();
36
37
$av->LoadById($av_id);
38
ok( !defined( $av->lib_opac() ), "Delete functions correctly" );

Return to bug 9869