|
Line 0
Link Here
|
|
|
1 |
package Koha::DB::Branch2; |
| 2 |
|
| 3 |
use Modern::Perl; |
| 4 |
use C4::Context; #FIXME = create a Koha package for KOHA_CONF reading |
| 5 |
|
| 6 |
use Koha::Schema; |
| 7 |
|
| 8 |
use Moose; |
| 9 |
|
| 10 |
has 'branchcode' => (is => 'rw', required => 1, isa => 'Str'); |
| 11 |
has 'branchname' => (is => 'rw', required => 1, isa => 'Str'); |
| 12 |
has 'branchaddress1' => (is => 'rw', required => 0, isa => 'Str'); |
| 13 |
has 'branchaddress2' => (is => 'rw', required => 0, isa => 'Str'); |
| 14 |
has 'branchaddress3' => (is => 'rw', required => 0, isa => 'Str'); |
| 15 |
has 'branchzip' => (is => 'rw', required => 0, isa => 'Str'); |
| 16 |
has 'branchcity' => (is => 'rw', required => 0, isa => 'Str'); |
| 17 |
has 'branchstate' => (is => 'rw', required => 0, isa => 'Str'); |
| 18 |
has 'branchcountry' => (is => 'rw', required => 0, isa => 'Str'); |
| 19 |
has 'branchphone' => (is => 'rw', required => 0, isa => 'Str'); |
| 20 |
has 'branchfax' => (is => 'rw', required => 0, isa => 'Str'); |
| 21 |
has 'branchemail' => (is => 'rw', required => 0, isa => 'Str'); |
| 22 |
has 'branchurl' => (is => 'rw', required => 0, isa => 'Str'); |
| 23 |
has 'issuing' => (is => 'rw', required => 0, isa => 'Int'); |
| 24 |
has 'branchip' => (is => 'rw', required => 0, isa => 'Str'); |
| 25 |
has 'branchprinter' => (is => 'rw', required => 0, isa => 'Str'); |
| 26 |
has 'branchnotes' => (is => 'rw', required => 0, isa => 'Str'); |
| 27 |
has 'opac_info' => (is => 'rw', required => 0, isa => 'Str'); |
| 28 |
|
| 29 |
my $schema = Koha::Schema->connect( |
| 30 |
'dbi:mysql:dbname='.C4::Context->config("database"), |
| 31 |
C4::Context->config("user"), |
| 32 |
C4::Context->config("pass"), |
| 33 |
{ AutoCommit => 1, |
| 34 |
cursor_class => 'DBIx::Class::Cursor::Cached', |
| 35 |
}, |
| 36 |
); |
| 37 |
|
| 38 |
sub create { |
| 39 |
my ($self) = @_; |
| 40 |
$schema->resultset('Branch')->create({ map { $_ => $self->$_ } $schema->source('Branch')->columns }); |
| 41 |
} |
| 42 |
|
| 43 |
sub read { |
| 44 |
my ($self, $branch) = @_; |
| 45 |
return $schema->resultset('Branch')->search($branch, { cache_for => 300 }); |
| 46 |
} |
| 47 |
|
| 48 |
sub update { |
| 49 |
my ($self, $branch) = @_; |
| 50 |
return $schema->resultset('Branch')->search({branchcode => $branch->{branchcode}})->update($branch); |
| 51 |
} |
| 52 |
|
| 53 |
sub delete { |
| 54 |
my ($self,$branch) = @_; |
| 55 |
$schema->resultset('Branch')->search($branch)->delete; |
| 56 |
} |
| 57 |
|