(bug #4050) update datelastseen even if document isn't on loan
[koha.git] / C4 / NewsChannels.pm
index 5a3def4..8cf1ff6 100644 (file)
@@ -25,7 +25,16 @@ use C4::Dates qw(format_date);
 use vars qw($VERSION @ISA @EXPORT);
 
 BEGIN { 
-               $VERSION = 3.00;        # set the version for version checking
+       $VERSION = 3.01;        # set the version for version checking
+       @ISA = qw(Exporter);
+       @EXPORT = qw(
+               &GetNewsToDisplay
+               &news_channels &get_new_channel &del_channels &add_channel &update_channel
+               &news_channels_categories &get_new_channel_category &del_channels_categories
+               &add_channel_category &update_channel_category &news_channels_by_category
+               &add_opac_new &upd_opac_new &del_opac_new &get_opac_new &get_opac_news
+               &add_opac_electronic &upd_opac_electronic &del_opac_electronic &get_opac_electronic &get_opac_electronics
+       );
 }
 
 =head1 NAME
@@ -38,23 +47,7 @@ This module provides the functions needed to admin the news channels and its cat
 
 =head1 FUNCTIONS
 
-=over 2
-
-=cut
-
-
-@ISA = qw(Exporter);
-@EXPORT = qw(
-  &GetNewsToDisplay
-  &news_channels &get_new_channel &del_channels &add_channel &update_channel
-  &news_channels_categories &get_new_channel_category &del_channels_categories
-  &add_channel_category &update_channel_category &news_channels_by_category
-  &add_opac_new &upd_opac_new &del_opac_new &get_opac_new &get_opac_news
-  &add_opac_electronic &upd_opac_electronic &del_opac_electronic &get_opac_electronic &get_opac_electronics
-);
-
-
-=item news_channels
+=head2 news_channels
 
   ($count, @channels) = &news_channels($channel_name, $id_category, $unclassified);
 
@@ -97,7 +90,7 @@ sub news_channels {
     return (scalar(@channels), @channels);
 }
 
-=item news_channels_by_category
+=head2 news_channels_by_category
 
   ($count, @results) = &news_channels_by_category();
 
@@ -119,6 +112,8 @@ A reference to an array of references to hash which keys are the new_channels fi
 
 Additionally the last index of results has a reference to all the news channels which don't have a category 
 
+=back
+
 =cut
 
 sub news_channels_by_category {
@@ -239,16 +234,16 @@ sub update_channel_category {
 }
 
 sub add_opac_new {
-    my ($title, $new, $lang, $expirationdate, $number) = @_;
+    my ($title, $new, $lang, $expirationdate, $timestamp, $number) = @_;
     my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare("INSERT INTO opac_news (title, new, lang, expirationdate, number) VALUES (?,?,?,?,?)");
-    $sth->execute($title, $new, $lang, $expirationdate, $number);
+    my $sth = $dbh->prepare("INSERT INTO opac_news (title, new, lang, expirationdate, timestamp, number) VALUES (?,?,?,?,?,?)");
+    $sth->execute($title, $new, $lang, $expirationdate, $timestamp, $number);
     $sth->finish;
     return 1;
 }
 
 sub upd_opac_new {
-    my ($idnew, $title, $new, $lang, $expirationdate, $number) = @_;
+    my ($idnew, $title, $new, $lang, $expirationdate, $timestamp,$number) = @_;
     my $dbh = C4::Context->dbh;
     my $sth = $dbh->prepare("
         UPDATE opac_news SET 
@@ -256,10 +251,11 @@ sub upd_opac_new {
             new = ?,
             lang = ?,
             expirationdate = ?,
+            timestamp = ?,
             number = ?
         WHERE idnew = ?
     ");
-    $sth->execute($title, $new, $lang, $expirationdate,$number,$idnew);
+    $sth->execute($title, $new, $lang, $expirationdate, $timestamp,$number,$idnew);
     $sth->finish;
     return 1;
 }
@@ -285,6 +281,7 @@ sub get_opac_new {
     my $data = $sth->fetchrow_hashref;
     $data->{$data->{'lang'}} = 1;
     $data->{expirationdate} = format_date($data->{expirationdate});
+    $data->{timestamp}      = format_date($data->{timestamp});
     $sth->finish;
     return $data;
 }
@@ -316,24 +313,26 @@ sub get_opac_news {
 }
 
 =head2 GetNewsToDisplay
-    
+
     $news = &GetNewsToDisplay($lang);
     C<$news> is a ref to an array which containts
     all news with expirationdate > today or expirationdate is null.
-    
+
 =cut
 
 sub GetNewsToDisplay {
     my $lang = shift;
     my $dbh = C4::Context->dbh;
+    # SELECT *,DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate
     my $query = "
-     SELECT *,DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate
+     SELECT *,timestamp AS newdate
      FROM   opac_news
      WHERE   (
-        expirationdate > CURRENT_DATE()
+        expirationdate >= CURRENT_DATE()
         OR    expirationdate IS NULL
         OR    expirationdate = '00-00-0000'
       )
+      AND   `timestamp` <= CURRENT_DATE()
       AND   lang = ?
       ORDER BY number
     ";                         # expirationdate field is NOT in ISO format?
@@ -341,6 +340,7 @@ sub GetNewsToDisplay {
     $sth->execute($lang);
     my @results;
     while ( my $row = $sth->fetchrow_hashref ){
+               $row->{newdate} = format_date($row->{newdate});
         push @results, $row;
     }
     return \@results;
@@ -409,16 +409,14 @@ sub get_opac_electronics {
     my $count = 0;
     while (my $row = $sth->fetchrow_hashref) {
             push @opac_electronic, $row;
-
-    
         $count++;
     }
 
     return ($count,\@opac_electronic);
 }
-END { }    # module clean-up code here (global destructor)
 
-=back
+1;
+__END__
 
 =head1 AUTHOR