From d60a4192cea4c6800b7efe71d40d7a9bb8dd5832 Mon Sep 17 00:00:00 2001 From: Paul Poulain Date: Mon, 25 Jun 2012 14:48:15 +0200 Subject: [PATCH] Categories management This package is a POC to manage the Categories table. It contains : * Category.pm (DB, DataObject and BusinessLogic levels) * the Category.t test * categorie.pl DBIx::Classed * updating copyright * removing a lot of useless files * tabs replaced by 4 spaces, result in some minor changes * use [% IF condition %] in templates, to avoid some pl level hacks http://bugs.koha-community.org/show_bug.cgi?id=8309 --- Koha/BusinessLogic/Category.pm | 5 + Koha/DB/Borrower.pm | 4 +- Koha/DB/Branch2.pm | 4 +- Koha/DB/Category.pm | 76 +++++ Koha/DataObject/Category.pm | 5 + admin/categorie.pl | 305 ++++++++------------ .../prog/en/modules/admin/categorie.tt | 34 +-- .../lib/KohaTest/Koha/BusinessLogic/Category.t | 24 ++ 8 files changed, 251 insertions(+), 206 deletions(-) create mode 100644 Koha/BusinessLogic/Category.pm create mode 100644 Koha/DB/Category.pm create mode 100644 Koha/DataObject/Category.pm create mode 100644 t/db_dependent/lib/KohaTest/Koha/BusinessLogic/Category.t diff --git a/Koha/BusinessLogic/Category.pm b/Koha/BusinessLogic/Category.pm new file mode 100644 index 0000000..1a83ad2 --- /dev/null +++ b/Koha/BusinessLogic/Category.pm @@ -0,0 +1,5 @@ +package Koha::BusinessLogic::Category; + +use Modern::Perl; +use Moose; +extends (qw(Koha::DataObject::Category)); diff --git a/Koha/DB/Borrower.pm b/Koha/DB/Borrower.pm index 9f033f5..398b0ac 100644 --- a/Koha/DB/Borrower.pm +++ b/Koha/DB/Borrower.pm @@ -17,7 +17,9 @@ my $schema = Koha::Schema->connect( 'dbi:mysql:dbname='.C4::Context->config("database"), C4::Context->config("user"), C4::Context->config("pass"), - { AutoCommit => 1 }, + { AutoCommit => 1 +# cursor_class => 'DBIx::Class::Cursor::Cached', + }, ); sub create { diff --git a/Koha/DB/Branch2.pm b/Koha/DB/Branch2.pm index 6bdbb08..3ccfa18 100644 --- a/Koha/DB/Branch2.pm +++ b/Koha/DB/Branch2.pm @@ -7,6 +7,8 @@ use Koha::Schema; use Moose; +# the attributes must be exactly what is in the database. If you declare something that is not in the database +# adding or updating will fail, complaining for an attribute (declared) here that is not a column has 'branchcode' => (is => 'rw', required => 1, isa => 'Str'); has 'branchname' => (is => 'rw', required => 1, isa => 'Str'); has 'branchaddress1' => (is => 'rw', required => 0, isa => 'Str'); @@ -31,7 +33,7 @@ my $schema = Koha::Schema->connect( C4::Context->config("user"), C4::Context->config("pass"), { AutoCommit => 1, - cursor_class => 'DBIx::Class::Cursor::Cached', +# cursor_class => 'DBIx::Class::Cursor::Cached', }, ); diff --git a/Koha/DB/Category.pm b/Koha/DB/Category.pm new file mode 100644 index 0000000..78f54d8 --- /dev/null +++ b/Koha/DB/Category.pm @@ -0,0 +1,76 @@ +package Koha::DB::Category; + +use Modern::Perl; +use C4::Context; #FIXME = create a Koha package for KOHA_CONF reading + +use Koha::Schema; + +use Moose; + +# the attributes must be exactly what is in the database. If you declare something that is not in the database +# adding or updating will fail, complaining for an attribute (declared) here that is not a column +has 'categorycode' => ( is => 'rw', required => 1, isa => 'Str' ); +has 'description' => ( is => 'rw', required => 1, isa => 'Str' ); +has 'enrolmentperiod' => ( is => 'rw', required => 0, isa => 'Int' ); +has 'enrolmentperioddate' => ( is => 'rw', required => 0, isa => 'Str' ); +has 'upperagelimit' => ( is => 'rw', required => 0, isa => 'Int' ); +has 'dateofbirthrequired' => ( is => 'rw', required => 0, isa => 'Str' ); +has 'finetype' => ( is => 'rw', required => 0, isa => 'Str' ); +has 'bulk' => ( is => 'rw', required => 0, isa => 'Int' ); +has 'enrolmentfee' => ( is => 'rw', required => 0, isa => 'Str' ); +has 'overduenoticerequired' => ( is => 'rw', required => 0, isa => 'Int' ); +has 'issuelimit' => ( is => 'rw', required => 0, isa => 'Str' ); #FIXME : this column is unused : not filled by admin/categories or used anywhere +has 'reservefee' => ( is => 'rw', required => 0, isa => 'Str' ); +has 'hidelostitems' => + ( is => 'rw', required => 0, isa => 'Str', default => 0 ); +has 'category_type' => ( is => 'rw', required => 0, isa => 'Str' ); + +# FIXME : we need a package to read the schema and connect to the database +my $schema = Koha::Schema->connect( + 'dbi:mysql:dbname=' . C4::Context->config("database"), + C4::Context->config("user"), + C4::Context->config("pass"), + { + AutoCommit => 1, + + # cursor_class => 'DBIx::Class::Cursor::Cached', # FIXME does not work, ask why on a mailing list of IRC + mysql_enable_utf8 => 1, # REQUIRED to handle properly utf8 + }, +); + +sub create { + my ($self) = @_; + $schema->resultset('Category') + ->create( # FIXME : the issuelimit field is unused, remove the grep once the column has been removed from the database + { map { $_ => $self->$_ } grep {$_ ne 'issuelimit'} $schema->source('Category')->columns } ); +} + +sub read { + my ( $self, $category ) = @_; + return $schema->resultset('Category')->search( + $category, + { + cache_for => 300, + result_class => 'DBIx::Class::ResultClass::HashRefInflator' # HashRefInflator return an array of hashref, which is what we usually need + # FIXME : improve the read to return a Category object when needed + # defaulting to HashRefInflator sounds like a good idea + } + ); +} + +sub update { + my ( $self, $category ) = @_; + return $schema->resultset('Category') + ->search( { 'categorycode' => $category->{categorycode} } ) + ->update($category); +} + +sub delete { + my ( $self, $category ) = @_; + $schema->resultset('Category')->search($category)->delete; +} + +sub columns { + my ( $self, $category ) = @_; + return $schema->source('Category')->columns; +} diff --git a/Koha/DataObject/Category.pm b/Koha/DataObject/Category.pm new file mode 100644 index 0000000..0cd5b06 --- /dev/null +++ b/Koha/DataObject/Category.pm @@ -0,0 +1,5 @@ +package Koha::DataObject::Category; + +use Modern::Perl; +use Moose; +extends (qw(Koha::DB::Category)); diff --git a/admin/categorie.pl b/admin/categorie.pl index 7a02a5d..5d99627 100755 --- a/admin/categorie.pl +++ b/admin/categorie.pl @@ -1,7 +1,8 @@ #!/usr/bin/perl #script to administer the categories table -#written 20/02/2002 by paul.poulain@free.fr +# Copyright 2000-2002 Katipo Communications +# Copyright 2002, 2012 BibLibre ()paul.poulain@biblibre.com) # ALGO : # this script use an $op to know what to do. @@ -18,8 +19,6 @@ # if $op=delete_confirm # - we delete the record having primkey=$primkey - -# Copyright 2000-2002 Katipo Communications # # This file is part of Koha. # @@ -37,223 +36,155 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. use strict; + #use warnings; FIXME - Bug 2505 use CGI; use C4::Context; use C4::Auth; use C4::Output; -use C4::Dates; +#use C4::Dates; use C4::Form::MessagingPreferences; - -sub StringSearch { - my ($searchstring,$type)=@_; - my $dbh = C4::Context->dbh; - $searchstring=~ s/\'/\\\'/g; - my @data=split(' ',$searchstring); - my $count=@data; - my $sth=$dbh->prepare("Select * from categories where (description like ?) order by category_type,description,categorycode"); - $sth->execute("$data[0]%"); - my @results; - while (my $data=$sth->fetchrow_hashref){ - push(@results,$data); - } - # $sth->execute; - $sth->finish; - return (scalar(@results),\@results); -} +use Koha::BusinessLogic::Category; +use Koha::BusinessLogic::Borrower; my $input = new CGI; -my $searchfield=$input->param('description'); +my $searchfield=$input->param('description'); # FIXME : for categories, this is useless (datatable handle that much better) my $script_name="/cgi-bin/koha/admin/categorie.pl"; my $categorycode=$input->param('categorycode'); my $op = $input->param('op'); my ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "admin/categorie.tmpl", - query => $input, - type => "intranet", - authnotrequired => 0, - flagsrequired => {parameters => 1}, - debug => 1, - }); - + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { parameters => 1 }, + debug => 1, + }); $template->param(script_name => $script_name, - categorycode => $categorycode, - searchfield => $searchfield); - + categorycode => $categorycode, + searchfield => $searchfield +); ################## ADD_FORM ################################## # called by default. Used to create form to add or modify a record if ($op eq 'add_form') { - $template->param(add_form => 1); - - #---- if primkey exists, it's a modify action, so read values to modify... - my $data; - if ($categorycode) { - my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("select categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,hidelostitems,overduenoticerequired,category_type from categories where categorycode=?"); - $sth->execute($categorycode); - $data=$sth->fetchrow_hashref; - $sth->finish; - } - - $data->{'enrolmentperioddate'} = undef if ($data->{'enrolmentperioddate'} eq '0000-00-00'); + $template->param(add_form => 1); - $template->param(description => $data->{'description'}, - enrolmentperiod => $data->{'enrolmentperiod'}, - enrolmentperioddate => C4::Dates::format_date($data->{'enrolmentperioddate'}), - upperagelimit => $data->{'upperagelimit'}, - dateofbirthrequired => $data->{'dateofbirthrequired'}, - enrolmentfee => sprintf("%.2f",$data->{'enrolmentfee'}), - overduenoticerequired => $data->{'overduenoticerequired'}, - issuelimit => $data->{'issuelimit'}, - reservefee => sprintf("%.2f",$data->{'reservefee'}), - hidelostitems => $data->{'hidelostitems'}, - category_type => $data->{'category_type'}, - DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), - SMSSendDriver => C4::Context->preference("SMSSendDriver"), - TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification"), - "type_".$data->{'category_type'} => 1, - ); - if (C4::Context->preference('EnhancedMessagingPreferences')) { - C4::Form::MessagingPreferences::set_form_values({ categorycode => $categorycode } , $template); + #---- if primkey exists, it's a modify action, so read values to modify... + my $data; + if ($categorycode) { + $data = Koha::BusinessLogic::Category->read({'categorycode' => $categorycode})->first; } - # END $OP eq ADD_FORM + $template->param( + %{$data}, + DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), + SMSSendDriver => C4::Context->preference("SMSSendDriver"), + TalkingTechItivaPhone => + C4::Context->preference("TalkingTechItivaPhoneNotification"), + ); + if ( C4::Context->preference('EnhancedMessagingPreferences') ) { + C4::Form::MessagingPreferences::set_form_values( + { categorycode => $categorycode }, $template ); + } + + # END $OP eq ADD_FORM ################## ADD_VALIDATE ################################## # called by add_form, used to insert/modify data in DB } elsif ($op eq 'add_validate') { - $template->param(add_validate => 1); - my $is_a_modif = $input->param("is_a_modif"); - my $dbh = C4::Context->dbh; - if($input->param('enrolmentperioddate')){ - $input->param('enrolmentperioddate' => C4::Dates::format_date_in_iso($input->param('enrolmentperioddate')) ); - } - - if ($is_a_modif) { - my $sth=$dbh->prepare("UPDATE categories SET description=?,enrolmentperiod=?, enrolmentperioddate=?,upperagelimit=?,dateofbirthrequired=?,enrolmentfee=?,reservefee=?,hidelostitems=?,overduenoticerequired=?,category_type=? WHERE categorycode=?"); - $sth->execute(map { $input->param($_) } ('description','enrolmentperiod','enrolmentperioddate','upperagelimit','dateofbirthrequired','enrolmentfee','reservefee','hidelostitems','overduenoticerequired','category_type','categorycode')); - $sth->finish; - } else { - my $sth=$dbh->prepare("INSERT INTO categories (categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,reservefee,hidelostitems,overduenoticerequired,category_type) values (?,?,?,?,?,?,?,?,?,?,?)"); - $sth->execute(map { $input->param($_) } ('categorycode','description','enrolmentperiod','enrolmentperioddate','upperagelimit','dateofbirthrequired','enrolmentfee','reservefee','hidelostitems','overduenoticerequired','category_type')); - $sth->finish; - } - if (C4::Context->preference('EnhancedMessagingPreferences')) { - C4::Form::MessagingPreferences::handle_form_action($input, - { categorycode => $input->param('categorycode') }, $template); + $template->param( add_validate => 1 ); + if ( $input->param('enrolmentperioddate') ) { + $input->param( + 'enrolmentperioddate' => C4::Dates::format_date_in_iso( + $input->param('enrolmentperioddate') + ) + ); } - print "Content-Type: text/html\n\n"; - exit; - # END $OP eq ADD_VALIDATE -################## DELETE_CONFIRM ################################## -# called by default form, used to confirm deletion of data in DB -} elsif ($op eq 'delete_confirm') { - $template->param(delete_confirm => 1); + if ($input->param("is_a_modif")) { + Koha::BusinessLogic::Category->update({ map { $_ => $input->param($_) } grep {$_ ne 'issuelimit'} # FIXME : remove grep when issuelimit has been removed from the database + Koha::BusinessLogic::Category->columns }); + } + else { + Koha::BusinessLogic::Category->new({ map { $_ => $input->param($_) } grep {$_ ne 'issuelimit'} # FIXME : remove grep when issuelimit has been removed from the database + Koha::BusinessLogic::Category->columns })->create; + } + if ( C4::Context->preference('EnhancedMessagingPreferences') ) { + C4::Form::MessagingPreferences::handle_form_action( $input, + { categorycode => $input->param('categorycode') }, $template ); + } + print +"Content-Type: text/html\n\n"; + exit; - my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("select count(*) as total from borrowers where categorycode=?"); - $sth->execute($categorycode); - my $total = $sth->fetchrow_hashref; - $sth->finish; - $template->param(total => $total->{'total'}); - - my $sth2=$dbh->prepare("select categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,hidelostitems,overduenoticerequired,category_type from categories where categorycode=?"); - $sth2->execute($categorycode); - my $data=$sth2->fetchrow_hashref; - $sth2->finish; - if ($total->{'total'} >0) { - $template->param(totalgtzero => 1); - } + # END $OP eq ADD_VALIDATE +################## DELETE_CONFIRM ################################## + # called by default form, used to confirm deletion of data in DB +} +elsif ( $op eq 'delete_confirm' ) { + $template->param( delete_confirm => 1 ); - $template->param( description => $data->{'description'}, - enrolmentperiod => $data->{'enrolmentperiod'}, - enrolmentperioddate => C4::Dates::format_date($data->{'enrolmentperioddate'}), - upperagelimit => $data->{'upperagelimit'}, - dateofbirthrequired => $data->{'dateofbirthrequired'}, - enrolmentfee => sprintf("%.2f",$data->{'enrolmentfee'}), - overduenoticerequired => $data->{'overduenoticerequired'}, - issuelimit => $data->{'issuelimit'}, - reservefee => sprintf("%.2f",$data->{'reservefee'}), - hidelostitems => $data->{'hidelostitems'}, - category_type => $data->{'category_type'}, - ); - # END $OP eq DELETE_CONFIRM -################## DELETE_CONFIRMED ################################## -# called by delete_confirm, used to effectively confirm deletion of data in DB -} elsif ($op eq 'delete_confirmed') { - $template->param(delete_confirmed => 1); - my $dbh = C4::Context->dbh; - my $categorycode=uc($input->param('categorycode')); - my $sth=$dbh->prepare("delete from categories where categorycode=?"); - $sth->execute($categorycode); - $sth->finish; - print "Content-Type: text/html\n\n"; - exit; + # Retrieve how many borrowers are using this categorycode + # retrieving a scalar result in retrieving the number of lines + # FIXME = this is not a real SQL count(*), so it's inefficient. A specific method in Koha::Business::Borrowers for that is needed ! + my $total = Koha::BusinessLogic::Borrower->read({'me.categorycode' => $categorycode })->all; + $template->param( total => $total); - # END $OP eq DELETE_CONFIRMED -} else { # DEFAULT - $template->param(else => 1); - my @loop; - my ($count,$results)=StringSearch($searchfield,'web'); - for (my $i=0; $i < $count; $i++){ - my %row = ( - categorycode => $results->[$i]{'categorycode'}, - description => $results->[$i]{'description'}, - enrolmentperiod => $results->[$i]{'enrolmentperiod'}, - enrolmentperioddate => C4::Dates::format_date($results->[$i]{'enrolmentperioddate'}), - upperagelimit => $results->[$i]{'upperagelimit'}, - dateofbirthrequired => $results->[$i]{'dateofbirthrequired'}, - enrolmentfee => sprintf("%.2f",$results->[$i]{'enrolmentfee'}), - overduenoticerequired => $results->[$i]{'overduenoticerequired'}, - issuelimit => $results->[$i]{'issuelimit'}, - reservefee => sprintf("%.2f",$results->[$i]{'reservefee'}), - hidelostitems => $results->[$i]{'hidelostitems'}, - category_type => $results->[$i]{'category_type'}, - "type_".$results->[$i]{'category_type'} => 1); - if (C4::Context->preference('EnhancedMessagingPreferences')) { - my $brief_prefs = _get_brief_messaging_prefs($results->[$i]{'categorycode'}); - $row{messaging_prefs} = $brief_prefs if @$brief_prefs; - } - push @loop, \%row; - } - $template->param(loop => \@loop); - # check that I (institution) and C (child) exists. otherwise => warning to the user - my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("select category_type from categories where category_type='C'"); - $sth->execute; - my ($categoryChild) = $sth->fetchrow; - $template->param(categoryChild => $categoryChild); - $sth=$dbh->prepare("select category_type from categories where category_type='I'"); - $sth->execute; - my ($categoryInstitution) = $sth->fetchrow; - $template->param(categoryInstitution => $categoryInstitution); - $sth->finish; + my $data = Koha::BusinessLogic::Category->read({'categorycode' => $categorycode})->first; + $template->param( + %{$data} + ); -} #---- END $OP eq DEFAULT + # END $OP eq DELETE_CONFIRM +################## DELETE_CONFIRMED ################################## + # called by delete_confirm, used to effectively confirm deletion of data in DB +} +elsif ( $op eq 'delete_confirmed' ) { + $template->param( delete_confirmed => 1 ); + Koha::BusinessLogic::Category->delete( + { 'categorycode' => $categorycode } ); + print +"Content-Type: text/html\n\n"; + exit; + + # END $OP eq DELETE_CONFIRMED +} +else { # DEFAULT + my @loop = Koha::BusinessLogic::Category->read()->all; + $template->param( + else => 1, + loop => \@loop, + ); + +} #---- END $OP eq DEFAULT output_html_with_http_headers $input, $cookie, $template->output; exit 0; -sub _get_brief_messaging_prefs { - my $categorycode = shift; - my $messaging_options = C4::Members::Messaging::GetMessagingOptions(); - my $results = []; - PREF: foreach my $option ( @$messaging_options ) { - my $pref = C4::Members::Messaging::GetMessagingPreferences( { categorycode => $categorycode, - message_name => $option->{'message_name'} } ); - next unless $pref->{'transports'}; - my $brief_pref = { - message_attribute_id => $option->{'message_attribute_id'}, - message_name => $option->{'message_name'}, - $option->{'message_name'} => 1 - }; - foreach my $transport ( keys %{$pref->{'transports'}} ) { - push @{ $brief_pref->{'transports'} }, { transport => $transport }; - } - push @$results, $brief_pref; - } - return $results; -} +# FIXME : should not be here but in a Koha::BusinessLogic Messaging package +#sub _get_brief_messaging_prefs { +# my $categorycode = shift; +# my $messaging_options = C4::Members::Messaging::GetMessagingOptions(); +# my $results = []; +# PREF: foreach my $option (@$messaging_options) { +# my $pref = C4::Members::Messaging::GetMessagingPreferences( +# { +# categorycode => $categorycode, +# message_name => $option->{'message_name'} +# } +# ); +# next unless $pref->{'transports'}; +# my $brief_pref = { +# message_attribute_id => $option->{'message_attribute_id'}, +# message_name => $option->{'message_name'}, +# $option->{'message_name'} => 1 +# }; +# foreach my $transport ( keys %{ $pref->{'transports'} } ) { +# push @{ $brief_pref->{'transports'} }, { transport => $transport }; +# } +# push @$results, $brief_pref; +# } +# return $results; +#} diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categorie.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categorie.tt index e2425af..89b566a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categorie.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categorie.tt @@ -1,7 +1,7 @@ [% INCLUDE 'doc-head-open.inc' %] Koha › Administration › Patron categories › [% IF ( add_form ) %][% IF ( categorycode ) %]Modify category '[% categorycode |html %]'[% ELSE %]New category[% END %][% END %] [% IF ( add_validate ) %]Data recorded[% END %] -[% IF ( delete_confirm ) %][% IF ( totalgtzero ) %]Cannot delete: category [% categorycode |html %] in use[% ELSE %]Confirm deletion of category '[% categorycode |html %]'[% END %][% END %] +[% IF ( delete_confirm ) %][% IF total >0 %]Cannot delete: category [% categorycode |html %] in use[% ELSE %]Confirm deletion of category '[% categorycode |html %]'[% END %][% END %] [% IF ( delete_confirmed ) %]Category deleted[% END %] [% INCLUDE 'doc-head-close.inc' %] @@ -95,7 +95,7 @@ @@ -172,12 +172,12 @@
  • @@ -205,11 +205,11 @@
    - [% IF ( totalgtzero ) %] + [% IF total >0 %] Category [% categorycode |html %] is in use. Deletion not possible![% ELSE %] Confirm deletion of category [% categorycode |html %][% END %] -[% IF ( totalgtzero ) %]
    This category is used [% total %] times. Deletion not possible
    [% END %] +[% IF total >0 %]
    This category is used [% total %] times. Deletion not possible
    [% END %] @@ -229,7 +229,7 @@ Confirm deletion of category [% categorycode |html %][% END %]
    Category code: [% categorycode |html %]
    Description: [% description |html %]
    Lost items in staff client[% IF ( hidelostitems ) %]Hidden by default[% ELSE %]Shown[% END %]
    Hold fee: [% reservefee %]
    -
    [% IF ( totalgtzero ) %] +
    [% IF total >0 %] [% ELSE %] @@ -301,12 +301,12 @@ Confirm deletion of category [% categorycode |html %][% END %] [% loo.description |html %] - [% IF ( loo.type_A ) %]Adult[% END %] - [% IF ( loo.type_C ) %]Child[% END %] - [% IF ( loo.type_P ) %]Prof.[% END %] - [% IF ( loo.type_I ) %]Org.[% END %] - [% IF ( loo.type_S ) %]Staff[% END %] - [% IF ( loo.type_X ) %]Statistical[% END %] + [% IF loo.category_type == "A" %]Adult[% END %] + [% IF loo.category_type == "C" %]Child[% END %] + [% IF loo.category_type == "P" %]Prof.[% END %] + [% IF loo.category_type == "I" %]Org.[% END %] + [% IF loo.category_type == "S" %]Staff[% END %] + [% IF loo.category_type == "X" %]Statistical[% END %] [% IF ( loo.enrolmentperiod ) %] diff --git a/t/db_dependent/lib/KohaTest/Koha/BusinessLogic/Category.t b/t/db_dependent/lib/KohaTest/Koha/BusinessLogic/Category.t new file mode 100644 index 0000000..976b1b8 --- /dev/null +++ b/t/db_dependent/lib/KohaTest/Koha/BusinessLogic/Category.t @@ -0,0 +1,24 @@ +#!/usr/bin/perl + +use v5.10.0; +use Modern::Perl; + +use Test::More tests => 5; + +BEGIN { + use_ok('Koha::BusinessLogic::Category', 'Loading Koha::BusinessLogic::Category OK'); +} + +# CREATE +my $category = Koha::BusinessLogic::Category->new({'categorycode' => 'TEST_C','description' => 'CATEGORY TEST NAME', 'category_type' => 'A'}); +ok($category->create->id eq 'TEST_C','Creating a category OK'); + +# READ +ok(Koha::BusinessLogic::Category->read({'categorycode' => 'TEST_C'})->first->description eq 'CATEGORY TEST NAME','Reading a category OK'); + +# UPDATE +Koha::BusinessLogic::Category->update({'categorycode' => 'TEST_C','description' => 'TEST UPDATED'}); +ok(Koha::BusinessLogic::Category->read({'categorycode' => 'TEST_C'})->first->description eq 'TEST UPDATED','Updating a category OK'); + +# DELETE +ok(Koha::BusinessLogic::Category->delete({'categorycode' => 'TEST_C'}),'Deleting a category OK'); -- 1.7.9.5