Bug 26745: Add TT support to 'title' in notices
[srvgit] / C4 / NewsChannels.pm
index f7fa1d7..7c9df5b 100644 (file)
@@ -22,10 +22,9 @@ use Modern::Perl;
 use C4::Context;
 use Koha::DateUtils;
 
-use vars qw($VERSION @ISA @EXPORT);
+use vars qw(@ISA @EXPORT);
 
 BEGIN { 
-    $VERSION = 3.07.00.049;    # set the version for version checking
     @ISA = qw(Exporter);
     @EXPORT = qw(
         &GetNewsToDisplay
@@ -59,6 +58,7 @@ sub add_opac_new {
     my $retval = 0;
 
     if ($href_entry) {
+        $href_entry->{number} = 0 if $href_entry->{number} !~ /^\d+$/;
         my @fields = keys %{$href_entry};
         my @values = values %{$href_entry};
         my $field_string = join ',', @fields;
@@ -86,6 +86,7 @@ sub upd_opac_new {
     my $retval = 0;
 
     if ($href_entry) {
+        $href_entry->{number} = 0 if $href_entry->{number} !~ /^\d+$/;
         # take the keys of hash entry and make a list, but...
         my @fields = keys %{$href_entry};
         my @values;
@@ -134,9 +135,8 @@ sub get_opac_new {
     my $sth = $dbh->prepare($query);
     $sth->execute($idnew);
     my $data = $sth->fetchrow_hashref;
-    $data->{$data->{'lang'}} = 1 if defined $data->{lang};
-    $data->{expirationdate} = output_pref({ dt => dt_from_string( $data->{expirationdate} ), dateonly => 1 });
-    $data->{timestamp}      = output_pref({ dt => dt_from_string( $data->{timestamp} ), dateonly => 1 }) ;
+    $data->{expirationdate} = output_pref({ dt => dt_from_string( $data->{expirationdate} ), dateonly => 1 }) if ( $data->{expirationdate} );
+    $data->{published_on} = output_pref({ dt => dt_from_string( $data->{published_on} ), dateonly => 1 });
     return $data;
 }
 
@@ -146,9 +146,13 @@ sub get_opac_news {
     my $dbh = C4::Context->dbh;
     my $query = q{
                   SELECT opac_news.*, branches.branchname,
-                         timestamp AS newdate
+                         published_on AS newdate,
+                         borrowers.title AS author_title,
+                         borrowers.firstname AS author_firstname,
+                         borrowers.surname AS author_surname
                   FROM opac_news LEFT JOIN branches
                       ON opac_news.branchcode=branches.branchcode
+                  LEFT JOIN borrowers on borrowers.borrowernumber = opac_news.borrowernumber
                 };
     $query .= ' WHERE 1';
     if ($lang) {
@@ -159,7 +163,7 @@ sub get_opac_news {
         $query .= ' AND (opac_news.branchcode IS NULL OR opac_news.branchcode=?)';
         push @values,$branchcode;
     }
-    $query.= ' ORDER BY timestamp DESC ';
+    $query.= ' ORDER BY published_on DESC ';
     #if ($limit) {
     #    $query.= 'LIMIT 0, ' . $limit;
     #}
@@ -179,7 +183,7 @@ sub get_opac_news {
 =head2 GetNewsToDisplay
 
     $news = &GetNewsToDisplay($lang,$branch);
-    C<$news> is a ref to an array which containts
+    C<$news> is a ref to an array which contains
     all news with expirationdate > today or expirationdate is null
     that is applicable for a given branch.
 
@@ -188,22 +192,22 @@ sub get_opac_news {
 sub GetNewsToDisplay {
     my ($lang,$branch) = @_;
     my $dbh = C4::Context->dbh;
-    # SELECT *,DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate
     my $query = q{
-     SELECT *,timestamp AS newdate
+     SELECT opac_news.*,published_on AS newdate,
+     borrowers.title AS author_title,
+     borrowers.firstname AS author_firstname,
+     borrowers.surname AS author_surname
      FROM   opac_news
+     LEFT JOIN borrowers on borrowers.borrowernumber = opac_news.borrowernumber
      WHERE   (
         expirationdate >= CURRENT_DATE()
         OR    expirationdate IS NULL
-        OR    expirationdate = '00-00-0000'
      )
-     AND   DATE(timestamp) < DATE_ADD(CURDATE(), INTERVAL 1 DAY)
-     AND   (lang = '' OR lang = ?)
-     AND   (branchcode IS NULL OR branchcode = ?)
+     AND   published_on <= CURDATE()
+     AND   (opac_news.lang = '' OR opac_news.lang = ?)
+     AND   (opac_news.branchcode IS NULL OR opac_news.branchcode = ?)
      ORDER BY number
-    }; # expirationdate field is NOT in ISO format?
-       # timestamp has HH:mm:ss, CURRENT_DATE generates 00:00:00
-       #           by adding 1, that captures today correctly.
+    };
     my $sth = $dbh->prepare($query);
     $lang = $lang // q{};
     $sth->execute($lang,$branch);