Permalink
Browse files

refactored slashifyDate function out of inline code, created C4/Koha.pm

to hold it and wrote tests for it, started marking other places for
potential refactoring.
  • Loading branch information...
1 parent f65c91e commit 0376493cd4bf8bc88a37e5424af4d67e1fa816d8 pate committed Apr 8, 2002
Showing with 215 additions and 55 deletions.
  1. +61 −0 C4/Koha.pm
  2. +13 −15 C4/Output.pm
  3. +8 −6 insertdata.pl
  4. +14 −0 koha.t
  5. +4 −0 loadmodules.pl
  6. +5 −1 memberentry.pl
  7. +4 −3 modbibitem.pl
  8. +7 −5 moredetail.pl
  9. +60 −12 moremember.pl
  10. +5 −3 request.pl
  11. +27 −10 search.pl
  12. +7 −0 testKoha.pl
View
@@ -0,0 +1,61 @@
+package C4::Koha;
+
+use strict;
+require Exporter;
+
+use vars qw($VERSION @ISA @EXPORT);
+
+$VERSION = 0.01;
+
+@ISA = qw(Exporter);
+@EXPORT = qw(&slashifyDate);
+
+use vars qw();
+
+
+sub slashifyDate {
+ # accepts a date of the form xx-xx-xx[xx] and returns it in the
+ # form xx/xx/xx[xx]
+ my @dateOut = split('-', shift);
+ return("$dateOut[2]/$dateOut[1]/$dateOut[0]")
+}
+
+
+
+1;
+__END__
+
+=head1 NAME
+
+Koha - Perl Module containing convenience functions for Koha scripts
+
+=head1 SYNOPSIS
+
+ use Koha;
+
+
+ $date = slashifyDate("01-01-2002")
+
+
+
+=head1 DESCRIPTION
+
+Koha.pm provides many functions for Koha scripts.
+
+slashifyDate() takes a dash separated date string and returns a slash
+separated date string
+
+=head1 AUTHOR
+
+Pat Eyler, pate@gnu.org
+
+=head1 SEE ALSO
+
+perl(1).
+
+=cut
+
+
+
+
+
View
@@ -72,8 +72,7 @@ my $priv_func = sub {
# make all your functions, whether exported or not;
sub startpage{
- my $string="<html>\n";
- return($string);
+ return("<html>\n");
}
sub gotopage{
@@ -133,13 +132,16 @@ sub endmenu{
}
sub mktablehdr {
- my $string="<table border=0 cellspacing=0 cellpadding=5>\n";
- return($string);
+ return("<table border=0 cellspacing=0 cellpadding=5>\n");
}
sub mktablerow {
- #the last item in data may be a backgroundimage
+ #the last item in data may be a backgroundimage
+
+ # FIXME
+ # should this be a foreach (1..$cols) loop?
+
my ($cols,$colour,@data)=@_;
my $i=0;
my $string="<tr valign=top bgcolor=$colour>";
@@ -162,8 +164,7 @@ sub mktablerow {
}
sub mktableft {
- my $string="</table>\n";
- return($string);
+ return("</table>\n");
}
sub mkform{
@@ -350,8 +351,7 @@ sub mkform2{
sub endpage{
- my $string="</body></html>\n";
- return($string);
+ return("</body></html>\n");
}
sub mklink {
@@ -376,15 +376,11 @@ sub mkheadr {
}
sub center {
- my ($text)=@_;
- my $string="<CENTER>\n";
- return ($string);
+ return ("<CENTER>\n");
}
sub endcenter {
- my ($text)=@_;
- my $string="</CENTER>\n";
- return ($string);
+ return ("</CENTER>\n");
}
sub bold {
@@ -395,3 +391,5 @@ sub bold {
END { } # module clean-up code here (global destructor)
+
+
View
@@ -40,9 +40,8 @@
altrelationship='$data{'altrelationship'}',othernames='$data{'othernames'}',phoneday='$data{'phoneday'}',
categorycode='$data{'categorycode'}',city='$data{'city'}',area='$data{'area'}',phone='$data{'phone'}',
borrowernotes='$data{'borrowernotes'}',altphone='$data{'altphone'}',surname='$data{'surname'}',
- initials='$data{'initials'}',physstreet='$data{'streetaddress'}',ethnicity='$data{'ethnicity'}',
- gonenoaddress='$data{'gna'}',lost='$data{'lost'}',debarred='$data{'debarred'}',textmessaging='$data{'textmessaging'}',
- guarantor='$data{'guarantor'}'
+ initials='$data{'initials'}',streetaddress='$data{'address'}',ethnicity='$data{'ethnicity'}',
+ gonenoaddress='$data{'gna'}',lost='$data{'lost'}',debarred='$data{'debarred'}'
where borrowernumber=$data{'borrowernumber'}";
# print $query;
@@ -54,14 +53,13 @@
$query="insert into borrowers (title,expiry,cardnumber,sex,ethnotes,streetaddress,faxnumber,
firstname,altnotes,dateofbirth,contactname,emailaddress,dateenrolled,streetcity,
altrelationship,othernames,phoneday,categorycode,city,area,phone,borrowernotes,altphone,surname,
- initials,ethnicity,textmessaging)
- values ('$data{'title'}','$data{'expiry'}','$data{'cardnumber'}',
+ initials,ethnicity,borrowernumber) values ('$data{'title'}','$data{'expiry'}','$data{'cardnumber'}',
'$data{'sex'}','$data{'ethnotes'}','$data{'address'}','$data{'faxnumber'}',
'$data{'firstname'}','$data{'altnotes'}','$data{'dateofbirth'}','$data{'contactname'}','$data{'emailaddress'}',
'$data{'joining'}','$data{'streetcity'}','$data{'altrelationship'}','$data{'othernames'}',
'$data{'phoneday'}','$data{'categorycode'}','$data{'city'}','$data{'area'}','$data{'phone'}',
'$data{'borrowernotes'}','$data{'altphone'}','$data{'surname'}','$data{'initials'}',
- '$data{'ethnicity'}','$data{'textmessaging'}')";
+ '$data{'ethnicity'}','$data{'borrowernumber'}')";
}
# ok if its an adult (type) it may have borrowers that depend on it as a guarantor
# so when we update information for an adult we should check for guarantees and update the relevant part
@@ -71,6 +69,10 @@
# is adult check guarantees;
my ($count,$guarantees)=findguarantees($data{'borrowernumber'});
for (my $i=0;$i<$count;$i++){
+ # FIXME
+ # It looks like the $i is only being returned to handle walking through
+ # the array, which is probably better done as a foreach loop.
+ #
my $guaquery="update borrowers set streetaddress='$data{'address'}',faxnumber='$data{'faxnumber'}',
streetcity='$data{'streetcity'}',phoneday='$data{'phoneday'}',city='$data{'city'}',area='$data{'area'}',phone='$data{'phone'}'
,streetaddress='$data{'address'}'
View
14 koha.t
@@ -0,0 +1,14 @@
+BEGIN { $| = 1; print "1..2\n"; }
+END {print "not ok 1\n" unless $loaded;}
+use C4::Koha;
+$loaded = 1;
+print "ok 1\n";
+
+$date = "01/01/2002";
+$newdate = &slashifyDate("2002-01-01");
+
+if ($date eq $newdate) {
+ print "ok 2\n";
+} else {
+ print "not ok 2\n";
+}
View
@@ -18,6 +18,10 @@
sub acquisitions {
+ # FIXME
+ # instead of getting a hash, then reading/writing to it at least twice
+ # and up to four times, maybe this should be a different function -
+ # areAquisitionsSimple() which returns a boolean
my %systemprefs=systemprefs();
($systemprefs{'acquisitions'}) || ($systemprefs{'acquisitions'}='normal');
if ($systemprefs{'acquisitions'} eq 'simple') {
View
@@ -45,7 +45,11 @@
}
my $cardnumber=$data->{'cardnumber'};
-my %systemprefs=systemprefs();
+my %sysemprefs=systemprefs();
+# FIXME
+# This logic should probably be moved out of the presentation code.
+# Not tonight though.
+#
if ($cardnumber eq '' && $systemprefs{'autoMemberNum'} eq '1') {
my $dbh=C4Connect;
my $query="select max(substring(borrowers.cardnumber,2,7)) from borrowers";
View
@@ -8,8 +8,10 @@
use strict;
use C4::Search;
-use CGI;
use C4::Output;
+use C4::Koha;
+use CGI;
+
my $input = new CGI;
#
@@ -152,8 +154,7 @@
#print @items;
my $count=@items;
for (my $i=0;$i<$count;$i++){
- my @temp=split('-',$items[$i]->{'datelastseen'});
- $items[$i]->{'datelastseen'}="$temp[2]/$temp[1]/$temp[0]";
+ $items[$i]->{'datelastseen'} = slashifyDate($items[$i]->{'datelastseen'});
print <<printend
<tr valign=top gcolor=#ffffcc>
<td><input type=checkbox name="check_group_$items[$i]->{'barcode'}"></td>
View
@@ -6,10 +6,11 @@
use strict;
#use DBI;
use C4::Search;
-use CGI;
+use C4::Koha;
use C4::Output;
use C4::Acquisitions;
+use CGI;
my $input = new CGI;
print $input->header;
#whether it is called from the opac of the intranet
@@ -130,14 +131,15 @@
$items[$i]->{'withdrawn'}=~ s/0/No/;
$items[$i]->{'withdrawn'}=~ s/1/Yes/;
$items[$i]->{'replacementprice'}+=0.00;
+
my $year=substr($items[$i]->{'timestamp0'},0,4);
my $mon=substr($items[$i]->{'timestamp0'},4,2);
my $day=substr($items[$i]->{'timestamp0'},6,2);
$items[$i]->{'timestamp0'}="$day/$mon/$year";
-my @temp=split('-',$items[$i]->{'dateaccessioned'});
-$items[$i]->{'dateaccessioned'}="$temp[2]/$temp[1]/$temp[0]";
-@temp=split('-',$items[$i]->{'datelastseen'});
-$items[$i]->{'datelastseen'}="$temp[2]/$temp[1]/$temp[0]";
+
+$items[$i]->{'dateaccessioned'} = slashifyDate($items[$i]->{'dateaccessioned'});
+$items[$i]->{'datelastseen'} = slashifyDate($items[$i]->{'datelastseen'});
+
print <<printend
<FONT SIZE=2 face="arial, helvetica">
<b>Home Branch:</b> $items[$i]->{'homebranch'}<br>
Oops, something went wrong.

0 comments on commit 0376493

Please sign in to comment.