[Koha-patches] [PATCH 69/78] Suggestions.pm, probably useless & not working (check with hdl)
paul.poulain at biblibre.com
paul.poulain at biblibre.com
Thu May 28 18:33:19 CEST 2009
From: Paul Poulain <paul.poulain at biblibre.com>
---
C4/Suggestions.pm | 187 ++++++++++++++++++++++++++---------------------------
1 files changed, 91 insertions(+), 96 deletions(-)
diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm
index 1732540..8d9295b 100644
--- a/C4/Suggestions.pm
+++ b/C4/Suggestions.pm
@@ -24,7 +24,7 @@ use Mail::Sendmail;
use C4::Context;
use C4::Output;
-use C4::Dates qw(format_date);
+use C4::Dates qw(format_date_in_iso);
use vars qw($VERSION @ISA @EXPORT);
BEGIN {
@@ -47,7 +47,7 @@ BEGIN {
=head1 NAME
-C4::Suggestions - Some useful functions for dealings with suggestions.
+C4::Suggestions - Some useful functions for dealings with aqorders.
=head1 SYNOPSIS
@@ -55,7 +55,7 @@ use C4::Suggestions;
=head1 DESCRIPTION
-The functions in this module deal with the suggestions in OPAC and in librarian interface
+The functions in this module deal with the aqorders in OPAC and in librarian interface
A suggestion is done in the OPAC. It has the status "ASKED"
@@ -65,7 +65,7 @@ When the book is ordered, the suggestion status becomes "ORDERED"
When a book is ordered and arrived in the library, the status becomes "AVAILABLE"
-All suggestions of a borrower can be seen by the borrower itself.
+All aqorders of a borrower can be seen by the borrower itself.
Suggestions done by other borrowers can be seen when not "AVAILABLE"
=head1 FUNCTIONS
@@ -77,7 +77,7 @@ Suggestions done by other borrowers can be seen when not "AVAILABLE"
searches for a suggestion
return :
-C<\@array> : the suggestions found. Array of hash.
+C<\@array> : the aqorders found. Array of hash.
Note the status is stored twice :
* in the status field
* as parameter ( for example ASKED => 1, or REJECTED => 1) . This is for template & translation purposes.
@@ -85,7 +85,7 @@ Note the status is stored twice :
=cut
sub SearchSuggestion {
- my ($user,$author,$title,$publishercode,$status,$suggestedbyme,$branchcode)=@_;
+ my (%suggestion,$suggestedbyme)=@_;
my $dbh = C4::Context->dbh;
my $query = "
SELECT suggestions.*,
@@ -99,23 +99,17 @@ sub SearchSuggestion {
U2.borrowernumber AS borrnummanagedby
FROM suggestions
LEFT JOIN borrowers AS U1 ON suggestedby=U1.borrowernumber
- LEFT JOIN borrowers AS U2 ON managedby=U2.borrowernumber
+ LEFT JOIN borrowers AS U2 ON suggestionmanagedby=U2.borrowernumber
WHERE 1=1 ";
my @sql_params;
- if ($author) {
- push @sql_params,"%".$author."%";
- $query .= " and author like ?";
+ foreach ('title','author','isbn','publishercode','seriestitle') {
+ if ($suggestion{$_}){
+ push @sql_params,"%".$dbh->quote($suggestion{$_})."%";
+ $query .= " and aqorders.$_ like ?";
+ }
}
- if ($title) {
- push @sql_params,"%".$title."%";
- $query .= " and suggestions.title like ?";
- }
- if ($publishercode) {
- push @sql_params,"%".$publishercode."%";
- $query .= " and publishercode like ?";
- }
- if (C4::Context->preference("IndependantBranches") || $branchcode) {
+ if (C4::Context->preference("IndependantBranches") || $suggestion{'branchcode'}) {
my $userenv = C4::Context->userenv;
if ($userenv) {
unless ($userenv->{flags} % 2 == 1){
@@ -123,36 +117,35 @@ sub SearchSuggestion {
$query .= " and (U1.branchcode = ? or U1.branchcode ='')";
}
}
- if ($branchcode) {
- push @sql_params,$branchcode;
+ if ($suggestion{'branchcode'}) {
+ push @sql_params,$suggestion{'branchcode'};
$query .= " and (U1.branchcode = ? or U1.branchcode ='')";
}
}
- if ($status) {
- push @sql_params,$status;
- $query .= " and status=?";
+ if ($suggestion{'status'}) {
+ push @sql_params,$suggestion{'status'};
+ $query .= " and aqorders.status=?";
}
if ($suggestedbyme) {
unless ($suggestedbyme eq -1) {
- push @sql_params,$user;
- $query .= " and suggestedby=?";
+ push @sql_params,$suggestion{'suggestedby'};
+ $query .= " and aqorders.suggestedby=?";
}
} else {
- $query .= " and managedby is NULL";
+ $query .= " and status NOT IN ('ORDERED', 'CLAIMED','RECEIVED')";
}
- my $sth=$dbh->prepare($query);
+ my $sth=$dbh->prepare($query);
$sth->execute(@sql_params);
my @results;
my $even=1; # the even variable is used to set even / odd lines, for highlighting
while (my $data=$sth->fetchrow_hashref){
- $data->{$data->{STATUS}} = 1;
+ $data->{$data->{'status'}} = 1;
if ($even) {
$even=0;
- $data->{even}=1;
+ $data->{'even'}=1;
} else {
$even=1;
}
-# $data->{date} = format_date($data->{date});
push(@results,$data);
}
return (\@results);
@@ -160,9 +153,9 @@ sub SearchSuggestion {
=head2 GetSuggestion
-\%sth = &GetSuggestion($suggestionid)
+\%sth = &GetSuggestion($ordernumber)
-this function get the detail of the suggestion $suggestionid (input arg)
+this function get the detail of the suggestion $ordernumber (input arg)
return :
the result of the SQL query as a hash : $sth->fetchrow_hashref.
@@ -170,21 +163,21 @@ return :
=cut
sub GetSuggestion {
- my ($suggestionid) = @_;
+ my ($ordernumber) = @_;
my $dbh = C4::Context->dbh;
my $query = "
SELECT *
- FROM suggestions
- WHERE suggestionid=?
+ FROM aqorders
+ WHERE ordernumber=?
";
my $sth = $dbh->prepare($query);
- $sth->execute($suggestionid);
+ $sth->execute($ordernumber);
return($sth->fetchrow_hashref);
}
=head2 GetSuggestionFromBiblionumber
-$suggestionid = &GetSuggestionFromBiblionumber($dbh,$biblionumber)
+$ordernumber = &GetSuggestionFromBiblionumber($dbh,$biblionumber)
Get a suggestion from it's biblionumber.
@@ -196,19 +189,19 @@ the id of the suggestion which is related to the biblionumber given on input arg
sub GetSuggestionFromBiblionumber {
my ($dbh,$biblionumber) = @_;
my $query = qq|
- SELECT suggestionid
- FROM suggestions
+ SELECT ordernumber
+ FROM aqorders
WHERE biblionumber=?
|;
my $sth = $dbh->prepare($query);
$sth->execute($biblionumber);
- my ($suggestionid) = $sth->fetchrow;
- return $suggestionid;
+ my ($ordernumber) = $sth->fetchrow;
+ return $ordernumber;
}
=head2 GetSuggestionByStatus
-$suggestions = &GetSuggestionByStatus($status,[$branchcode])
+$aqorders = &GetSuggestionByStatus($status,[$branchcode])
Get a suggestion from it's status
@@ -222,17 +215,17 @@ sub GetSuggestionByStatus {
my $branchcode = shift;
my $dbh = C4::Context->dbh;
my @sql_params=($status);
- my $query = qq(SELECT suggestions.*,
+ my $query = qq(SELECT aqorders.*,
U1.surname AS surnamesuggestedby,
U1.firstname AS firstnamesuggestedby,
U1.branchcode AS branchcodesuggestedby,
U1.borrowernumber AS borrnumsuggestedby,
- U2.surname AS surnamemanagedby,
- U2.firstname AS firstnamemanagedby,
- U2.borrowernumber AS borrnummanagedby
- FROM suggestions
+ U2.surname AS surnamesuggestionmanagedby,
+ U2.firstname AS firstnamesuggestionmanagedby,
+ U2.borrowernumber AS borrnumsuggestionmanagedby
+ FROM aqorders
LEFT JOIN borrowers AS U1 ON suggestedby=U1.borrowernumber
- LEFT JOIN borrowers AS U2 ON managedby=U2.borrowernumber
+ LEFT JOIN borrowers AS U2 ON suggestionmanagedby=U2.borrowernumber
WHERE status = ?);
if (C4::Context->preference("IndependantBranches") || $branchcode) {
my $userenv = C4::Context->userenv;
@@ -253,7 +246,6 @@ sub GetSuggestionByStatus {
my $results;
$results= $sth->fetchall_arrayref({});
-# map{$_->{date} = format_date($_->{date})} @$results;
return $results;
}
@@ -261,7 +253,7 @@ sub GetSuggestionByStatus {
&CountSuggestion($status)
-Count the number of suggestions with the status given on input argument.
+Count the number of aqorders with the status given on input argument.
the arg status can be :
=over 2
@@ -290,7 +282,7 @@ sub CountSuggestion {
if ($userenv->{flags} % 2 == 1){
my $query = qq |
SELECT count(*)
- FROM suggestions
+ FROM aqorders
WHERE status=?
|;
$sth = $dbh->prepare($query);
@@ -299,7 +291,7 @@ sub CountSuggestion {
else {
my $query = qq |
SELECT count(*)
- FROM suggestions LEFT JOIN borrowers ON borrowers.borrowernumber=suggestions.suggestedby
+ FROM aqorders LEFT JOIN borrowers ON borrowers.borrowernumber=aqorders.suggestedby
WHERE status=?
AND (borrowers.branchcode='' OR borrowers.branchcode =?)
|;
@@ -310,7 +302,7 @@ sub CountSuggestion {
else {
my $query = qq |
SELECT count(*)
- FROM suggestions
+ FROM aqorders
WHERE status=?
|;
$sth = $dbh->prepare($query);
@@ -330,21 +322,24 @@ Insert a new suggestion on database with value given on input arg.
=cut
sub NewSuggestion {
- my ($borrowernumber,$title,$author,$publishercode,$note,$copyrightdate,$volumedesc,$publicationyear,$place,$isbn,$biblionumber,$reason) = @_;
+ my %data=@_;
+# $borrowernumber,$title,$author,$publishercode,$note,$copyrightdate,$volumedesc,$publicationyear,$place,$isbn,$biblionumber,$reason) = @_;
my $dbh = C4::Context->dbh;
+ $data{'suggestioncreatedon'}= format_date_in_iso($data{'suggestioncreatedon'}) if ($data{'suggestioncreatedon'});
my $query = qq |
- INSERT INTO suggestions
- (status,suggestedby,title,author,publishercode,note,copyrightdate,
- volumedesc,publicationyear,place,isbn,biblionumber,reason)
- VALUES ('ASKED',?,?,?,?,?,?,?,?,?,?,?,?)
- |;
+ INSERT INTO aqorders SET
+ status='ASKED',|;
+ my @parameters;
+ map { push @parameters,"$_ = ".$dbh->quote($data{$_}) if($data{$_}); }(keys %data);
+ $query.=join ",", @parameters;
+ warn $query;
my $sth = $dbh->prepare($query);
- $sth->execute($borrowernumber,$title,$author,$publishercode,$note,$copyrightdate,$volumedesc,$publicationyear,$place,$isbn,$biblionumber,$reason);
+ $sth->execute;
}
=head2 ModStatus
-&ModStatus($suggestionid,$status,$managedby,$biblionumber)
+&ModStatus($ordernumber,$status,$suggestionmanagedby,$biblionumber)
Modify the status (status can be 'ASKED', 'ACCEPTED', 'REJECTED', 'ORDERED')
and send a mail to notify the user that did the suggestion.
@@ -354,63 +349,63 @@ Note that there is no function to modify a suggestion : only the status can be m
=cut
sub ModStatus {
- my ($suggestionid,$status,$managedby,$biblionumber,$reason) = @_;
+ my ($ordernumber,$status,$suggestionmanagedby,$biblionumber,$reason) = @_;
my $dbh = C4::Context->dbh;
my $sth;
- if ($managedby>0) {
+ if ($suggestionmanagedby>0) {
if ($biblionumber) {
my $query = qq|
- UPDATE suggestions
- SET status=?,managedby=?,biblionumber=?,reason=?
- WHERE suggestionid=?
+ UPDATE aqorders
+ SET status=?,suggestionmanagedby=?,biblionumber=?,reason=?
+ WHERE ordernumber=?
|;
$sth = $dbh->prepare($query);
- $sth->execute($status,$managedby,$biblionumber,$reason,$suggestionid);
+ $sth->execute($status,$suggestionmanagedby,$biblionumber,$reason,$ordernumber);
} else {
my $query = qq|
- UPDATE suggestions
- SET status=?,managedby=?,reason=?
- WHERE suggestionid=?
+ UPDATE aqorders
+ SET status=?,suggestionmanagedby=?,reason=?
+ WHERE ordernumber=?
|;
$sth = $dbh->prepare($query);
- $sth->execute($status,$managedby,$reason,$suggestionid);
+ $sth->execute($status,$suggestionmanagedby,$reason,$ordernumber);
}
} else {
if ($biblionumber) {
my $query = qq|
- UPDATE suggestions
+ UPDATE aqorders
SET status=?,biblionumber=?,reason=?
- WHERE suggestionid=?
+ WHERE ordernumber=?
|;
$sth = $dbh->prepare($query);
- $sth->execute($status,$biblionumber,$reason,$suggestionid);
+ $sth->execute($status,$biblionumber,$reason,$ordernumber);
}
else {
my $query = qq|
- UPDATE suggestions
+ UPDATE aqorders
SET status=?,reason=?
- WHERE suggestionid=?
+ WHERE ordernumber=?
|;
$sth = $dbh->prepare($query);
- $sth->execute($status,$reason,$suggestionid);
+ $sth->execute($status,$reason,$ordernumber);
}
}
# check mail sending.
my $queryMail = "
- SELECT suggestions.*,
+ SELECT aqorders.*,
boby.surname AS bysurname,
boby.firstname AS byfirstname,
boby.email AS byemail,
lib.surname AS libsurname,
lib.firstname AS libfirstname,
lib.email AS libemail
- FROM suggestions
+ FROM aqorders
LEFT JOIN borrowers AS boby ON boby.borrowernumber=suggestedby
- LEFT JOIN borrowers AS lib ON lib.borrowernumber=managedby
- WHERE suggestionid=?
+ LEFT JOIN borrowers AS lib ON lib.borrowernumber=suggestionmanagedby
+ WHERE ordernumber=?
";
$sth = $dbh->prepare($queryMail);
- $sth->execute($suggestionid);
+ $sth->execute($ordernumber);
my $emailinfo = $sth->fetchrow_hashref;
my $template = gettemplate("suggestion/mail_suggestion_$status.tmpl", "intranet", CGI->new());
@@ -438,51 +433,51 @@ sub ModStatus {
=head2 ConnectSuggestionAndBiblio
-&ConnectSuggestionAndBiblio($suggestionid,$biblionumber)
+&ConnectSuggestionAndBiblio($ordernumber,$biblionumber)
connect a suggestion to an existing biblio
=cut
sub ConnectSuggestionAndBiblio {
- my ($suggestionid,$biblionumber) = @_;
+ my ($ordernumber,$biblionumber) = @_;
my $dbh=C4::Context->dbh;
my $query = "
- UPDATE suggestions
+ UPDATE aqorders
SET biblionumber=?
- WHERE suggestionid=?
+ WHERE ordernumber=?
";
my $sth = $dbh->prepare($query);
- $sth->execute($biblionumber,$suggestionid);
+ $sth->execute($biblionumber,$ordernumber);
}
=head2 DelSuggestion
-&DelSuggestion($borrowernumber,$suggestionid)
+&DelSuggestion($borrowernumber,$ordernumber)
Delete a suggestion. A borrower can delete a suggestion only if he is its owner.
=cut
sub DelSuggestion {
- my ($borrowernumber,$suggestionid,$type) = @_;
+ my ($borrowernumber,$ordernumber,$type) = @_;
my $dbh = C4::Context->dbh;
# check that the suggestion comes from the suggestor
my $query = "
SELECT suggestedby
- FROM suggestions
- WHERE suggestionid=?
+ FROM aqorders
+ WHERE ordernumber=?
";
my $sth = $dbh->prepare($query);
- $sth->execute($suggestionid);
+ $sth->execute($ordernumber);
my ($suggestedby) = $sth->fetchrow;
if ($type eq "intranet" || $suggestedby eq $borrowernumber ) {
my $queryDelete = "
- DELETE FROM suggestions
- WHERE suggestionid=?
+ DELETE FROM aqorders
+ WHERE ordernumber=?
";
$sth = $dbh->prepare($queryDelete);
- my $suggestiondeleted=$sth->execute($suggestionid);
+ my $suggestiondeleted=$sth->execute($ordernumber);
return $suggestiondeleted;
}
}
--
1.6.0.4
More information about the Koha-patches
mailing list