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

(-)a/Koha/DataObject/AuthorisedValue.pm (+29 lines)
Line 0 Link Here
1
package Koha::DataObject::AuthorisedValue;
2
3
use base qw/Koha::SearchBuilder::Record/;
4
5
sub _Init {
6
    my $self = shift;
7
8
    $self->Table("authorised_values");
9
10
    return $self->SUPER::_Init(@_);
11
}
12
13
# Tell Record what the primary keys are
14
sub _PrimaryKeys {
15
    return ['id'];
16
}
17
18
sub _ClassAccessible {
19
    {
20
        id => { 'read' => 1, 'auto' => 1, 'public' => 1, },
21
        category => { 'read' => 1, 'auto' => 1, 'public' => 1, },
22
        authorised_value => { 'read' => 1, 'auto' => 1, 'public' => 1, },
23
        lib => { 'read' => 1, 'auto' => 1, 'public' => 1, },
24
        lib_opac => { 'read' => 1, 'auto' => 1, 'public' => 1, },
25
        mageurl => { 'read' => 1, 'auto' => 1, 'public' => 1, },
26
    };
27
}
28
29
1;
(-)a/Koha/DataObject/AuthorisedValues.pm (+18 lines)
Line 0 Link Here
1
package Koha::DataObject::AuthorisedValues;
2
3
use base qw/Koha::SearchBuilder/;
4
5
sub _Init {
6
    my $self = shift;
7
8
    $self->Table("authorised_values");
9
10
    return $self->SUPER::_Init(@_);
11
}
12
13
sub NewItem {
14
    my $self = shift;
15
    return ( Koha::DataObject::AuthorisedValue->new() );
16
}
17
18
1;
(-)a/Koha/SearchBuilder.pm (+19 lines)
Line 0 Link Here
1
package Koha::SearchBuilder;
2
3
use base qw/DBIx::SearchBuilder/;
4
5
use DBIx::SearchBuilder;
6
use C4::Context;
7
8
sub _Init {
9
    my $self = shift;
10
11
    $self->SUPER::_Init(@_);
12
13
    my $handle = Koha::SearchBuilder::Handle->new();
14
    $handle->Connect();
15
    $self->_Handle( $handle ); 
16
}
17
18
1;
19
(-)a/Koha/SearchBuilder/Handle.pm (+37 lines)
Line 0 Link Here
1
package Koha::SearchBuilder::Handle;
2
3
use base qw/DBIx::SearchBuilder::Handle/;
4
5
use strict;
6
use warnings;
7
8
use C4::Context;
9
10
sub Connect {
11
    my $self = shift;
12
    my %args = (@_);
13
14
    my $driver = C4::Context::db_scheme2dbi( C4::Context->config('db_scheme') );
15
16
    $self->SUPER::Connect(
17
	Driver => $driver,
18
        User => C4::Context->config('user'),,
19
        Password => C4::Context->config('pass'),
20
	Host     => C4::Context->config('hostname'),
21
	Database => C4::Context->config('database'),
22
        %args,
23
    );
24
25
    if ( $driver eq 'mysql' ) {
26
        my $version = $self->DatabaseVersion;
27
        ($version) = $version =~ /^(\d+\.\d+)/;
28
        $self->dbh->do("SET NAMES 'utf8'") if $version >= 4.1;
29
    }
30
    elsif ( $driver eq 'Pg' ) {
31
        my $version = $self->DatabaseVersion;
32
        ($version) = $version =~ /^(\d+\.\d+)/;
33
        $self->dbh->do("SET bytea_output = 'escape'") if $version >= 9.0;
34
    }
35
}
36
37
1;
(-)a/Koha/SearchBuilder/Record.pm (+19 lines)
Line 0 Link Here
1
package Koha::SearchBuilder::Record;
2
3
use base qw/DBIx::SearchBuilder::Record/;
4
5
use Koha::SearchBuilder::Handle;
6
7
sub _Init {
8
    my $self = shift;
9
10
    $self->SUPER::_Init(@_);
11
12
    my $handle = Koha::SearchBuilder::Handle->new();
13
    $handle->Connect();
14
15
    $self->_Handle( $handle );
16
}
17
18
1;
19
(-)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