Bug 11430: delete search history by id - API changes
Bug 10807 adds a search history for authorities and bug 10862 adds the search history on the staff interface. This one allows the user to select the search history lines he wants to delete. This change is done for the OPAC and intranet interface. The user is now allow to delete one or more lines of his/her search history. Test plan (for intranet, opac: bootstrap and prog themes): 1/ launch some search (catalogue and authority) 2/ verify the lines is added to your search history 3/ delete one or more lines of the history and verify they have been deleted 4/ at the OPAC: logout and do again steps 1-3. 5/ prove t/db_dependent/Search/History.t Signed-off-by: sonia BOUIS <sonia.bouis@univ-lyon3.fr> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
This commit is contained in:
parent
fdca44709e
commit
380e8d53f0
1 changed files with 70 additions and 11 deletions
|
@ -42,15 +42,18 @@ sub add_to_session {
|
||||||
my $total = $params->{total};
|
my $total = $params->{total};
|
||||||
my $type = $params->{type} || 'biblio';
|
my $type = $params->{type} || 'biblio';
|
||||||
|
|
||||||
|
# To a cookie (the user is not logged in)
|
||||||
|
my $now = dt_from_string;
|
||||||
|
my $id = $now->year . $now->month . $now->day . $now->hour . $now->minute . $now->second . int(rand(100));
|
||||||
my @recent_searches = get_from_session( { cgi => $cgi } );
|
my @recent_searches = get_from_session( { cgi => $cgi } );
|
||||||
push @recent_searches,
|
push @recent_searches, {
|
||||||
{
|
|
||||||
query_desc => $query_desc,
|
query_desc => $query_desc,
|
||||||
query_cgi => $query_cgi,
|
query_cgi => $query_cgi,
|
||||||
total => "$total",
|
total => "$total",
|
||||||
type => $type,
|
type => $type,
|
||||||
time => output_pref( { dt => dt_from_string(), dateformat => 'iso', timeformat => '24hr' } ),
|
time => output_pref( { dt => $now, dateformat => 'iso', timeformat => '24hr' } ),
|
||||||
};
|
id => $id,
|
||||||
|
};
|
||||||
|
|
||||||
shift @recent_searches if ( @recent_searches > 15 );
|
shift @recent_searches if ( @recent_searches > 15 );
|
||||||
set_to_session( { cgi => $cgi, search_history => \@recent_searches } );
|
set_to_session( { cgi => $cgi, search_history => \@recent_searches } );
|
||||||
|
@ -58,22 +61,34 @@ sub add_to_session {
|
||||||
|
|
||||||
sub delete {
|
sub delete {
|
||||||
my ($params) = @_;
|
my ($params) = @_;
|
||||||
|
my $id = $params->{id};
|
||||||
my $userid = $params->{userid};
|
my $userid = $params->{userid};
|
||||||
my $sessionid = $params->{sessionid};
|
my $sessionid = $params->{sessionid};
|
||||||
my $type = $params->{type} || q{};
|
my $type = $params->{type} || q{};
|
||||||
my $previous = $params->{previous} || 0;
|
my $previous = $params->{previous} || 0;
|
||||||
|
|
||||||
unless ($userid) {
|
unless ( ref( $id ) ) {
|
||||||
warn "ERROR: userid is required for history search";
|
$id = $id ? [ $id ] : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
unless ( $userid or @$id ) {
|
||||||
|
warn "ERROR: userid or id is required for history deletion";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $dbh = C4::Context->dbh;
|
my $dbh = C4::Context->dbh;
|
||||||
my $query = q{
|
my $query = q{
|
||||||
DELETE FROM search_history
|
DELETE FROM search_history
|
||||||
WHERE userid = ?
|
WHERE 1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$query .= q{ AND id IN ( } . join( q{,}, (q{?}) x @$id ) . q{ )}
|
||||||
|
if @$id;
|
||||||
|
|
||||||
|
$query .= q{
|
||||||
|
AND userid = ?
|
||||||
|
} if $userid;
|
||||||
|
|
||||||
if ($sessionid) {
|
if ($sessionid) {
|
||||||
$query .=
|
$query .=
|
||||||
$previous
|
$previous
|
||||||
|
@ -85,20 +100,56 @@ sub delete {
|
||||||
if $type;
|
if $type;
|
||||||
|
|
||||||
$dbh->do(
|
$dbh->do(
|
||||||
$query, {}, $userid,
|
$query, {},
|
||||||
|
( @$id ? ( @$id ) : () ),
|
||||||
|
( $userid ? $userid : () ),
|
||||||
( $sessionid ? $sessionid : () ),
|
( $sessionid ? $sessionid : () ),
|
||||||
( $type ? $type : () )
|
( $type ? $type : () )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub delete_from_cookie {
|
||||||
|
my ($params) = @_;
|
||||||
|
my $cookie = $params->{cookie};
|
||||||
|
my $id = $params->{id};
|
||||||
|
|
||||||
|
return unless $cookie;
|
||||||
|
|
||||||
|
unless ( ref( $id ) ) {
|
||||||
|
$id = $id ? [ $id ] : [];
|
||||||
|
}
|
||||||
|
return unless @$id;
|
||||||
|
|
||||||
|
my @searches;
|
||||||
|
if ( $cookie ){
|
||||||
|
$cookie = uri_unescape( $cookie );
|
||||||
|
if (decode_json( $cookie )) {
|
||||||
|
@searches = @{decode_json( $cookie )}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@searches = map {
|
||||||
|
my $search = $_;
|
||||||
|
( grep { $_ != $search->{id} } @$id ) ? $search : ()
|
||||||
|
} @searches;
|
||||||
|
|
||||||
|
return uri_escape( encode_json( \@searches ) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
sub get {
|
sub get {
|
||||||
my ($params) = @_;
|
my ($params) = @_;
|
||||||
|
my $id = $params->{id};
|
||||||
my $userid = $params->{userid};
|
my $userid = $params->{userid};
|
||||||
my $sessionid = $params->{sessionid};
|
my $sessionid = $params->{sessionid};
|
||||||
my $type = $params->{type};
|
my $type = $params->{type};
|
||||||
my $previous = $params->{previous};
|
my $previous = $params->{previous};
|
||||||
|
|
||||||
unless ($userid) {
|
unless ( ref( $id ) ) {
|
||||||
|
$id = $id ? [ $id ] : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
unless ( $userid or @$id ) {
|
||||||
warn "ERROR: userid is required for history search";
|
warn "ERROR: userid is required for history search";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -106,9 +157,16 @@ sub get {
|
||||||
my $query = q{
|
my $query = q{
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM search_history
|
FROM search_history
|
||||||
WHERE userid = ?
|
WHERE 1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$query .= q{ AND id IN ( } . join( q{,}, (q{?}) x @$id ) . q{ )}
|
||||||
|
if @$id;
|
||||||
|
|
||||||
|
$query .= q{
|
||||||
|
AND userid = ?
|
||||||
|
} if $userid;
|
||||||
|
|
||||||
if ($sessionid) {
|
if ($sessionid) {
|
||||||
$query .=
|
$query .=
|
||||||
$previous
|
$previous
|
||||||
|
@ -122,7 +180,8 @@ sub get {
|
||||||
my $dbh = C4::Context->dbh;
|
my $dbh = C4::Context->dbh;
|
||||||
my $sth = $dbh->prepare($query);
|
my $sth = $dbh->prepare($query);
|
||||||
$sth->execute(
|
$sth->execute(
|
||||||
$userid,
|
( @$id ? ( @$id ) : () ),
|
||||||
|
( $userid ? $userid : () ),
|
||||||
( $sessionid ? $sessionid : () ),
|
( $sessionid ? $sessionid : () ),
|
||||||
( $type ? $type : () )
|
( $type ? $type : () )
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue