Filename | /mnt/catalyst/koha/C4/NewsChannels.pm |
Statements | Executed 14 statements in 730µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 453µs | 469µs | BEGIN@20 | C4::NewsChannels::
1 | 1 | 1 | 12µs | 12µs | BEGIN@28 | C4::NewsChannels::
1 | 1 | 1 | 9µs | 18µs | BEGIN@21 | C4::NewsChannels::
1 | 1 | 1 | 8µs | 11µs | BEGIN@23 | C4::NewsChannels::
1 | 1 | 1 | 7µs | 30µs | BEGIN@24 | C4::NewsChannels::
1 | 1 | 1 | 7µs | 45µs | BEGIN@26 | C4::NewsChannels::
0 | 0 | 0 | 0s | 0s | GetNewsToDisplay | C4::NewsChannels::
0 | 0 | 0 | 0s | 0s | add_opac_new | C4::NewsChannels::
0 | 0 | 0 | 0s | 0s | del_opac_new | C4::NewsChannels::
0 | 0 | 0 | 0s | 0s | get_opac_new | C4::NewsChannels::
0 | 0 | 0 | 0s | 0s | get_opac_news | C4::NewsChannels::
0 | 0 | 0 | 0s | 0s | upd_opac_new | C4::NewsChannels::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package C4::NewsChannels; | ||||
2 | |||||
3 | # Copyright 2000-2002 Katipo Communications | ||||
4 | # | ||||
5 | # This file is part of Koha. | ||||
6 | # | ||||
7 | # Koha is free software; you can redistribute it and/or modify it under the | ||||
8 | # terms of the GNU General Public License as published by the Free Software | ||||
9 | # Foundation; either version 2 of the License, or (at your option) any later | ||||
10 | # version. | ||||
11 | # | ||||
12 | # Koha is distributed in the hope that it will be useful, but WITHOUT ANY | ||||
13 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||||
14 | # A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||||
15 | # | ||||
16 | # You should have received a copy of the GNU General Public License along | ||||
17 | # with Koha; if not, write to the Free Software Foundation, Inc., | ||||
18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||
19 | |||||
20 | 2 | 29µs | 2 | 485µs | # spent 469µs (453+16) within C4::NewsChannels::BEGIN@20 which was called:
# once (453µs+16µs) by C4::Members::BEGIN@37 at line 20 # spent 469µs making 1 call to C4::NewsChannels::BEGIN@20
# spent 16µs making 1 call to strict::import |
21 | 2 | 22µs | 2 | 26µs | # spent 18µs (9+8) within C4::NewsChannels::BEGIN@21 which was called:
# once (9µs+8µs) by C4::Members::BEGIN@37 at line 21 # spent 18µs making 1 call to C4::NewsChannels::BEGIN@21
# spent 8µs making 1 call to warnings::import |
22 | |||||
23 | 2 | 23µs | 2 | 13µs | # spent 11µs (8+2) within C4::NewsChannels::BEGIN@23 which was called:
# once (8µs+2µs) by C4::Members::BEGIN@37 at line 23 # spent 11µs making 1 call to C4::NewsChannels::BEGIN@23
# spent 2µs making 1 call to C4::Context::import |
24 | 2 | 26µs | 2 | 52µs | # spent 30µs (7+22) within C4::NewsChannels::BEGIN@24 which was called:
# once (7µs+22µs) by C4::Members::BEGIN@37 at line 24 # spent 30µs making 1 call to C4::NewsChannels::BEGIN@24
# spent 22µs making 1 call to Exporter::import |
25 | |||||
26 | 2 | 53µs | 2 | 84µs | # spent 45µs (7+38) within C4::NewsChannels::BEGIN@26 which was called:
# once (7µs+38µs) by C4::Members::BEGIN@37 at line 26 # spent 45µs making 1 call to C4::NewsChannels::BEGIN@26
# spent 38µs making 1 call to vars::import |
27 | |||||
28 | # spent 12µs within C4::NewsChannels::BEGIN@28 which was called:
# once (12µs+0s) by C4::Members::BEGIN@37 at line 35 | ||||
29 | 1 | 900ns | $VERSION = 3.07.00.049; # set the version for version checking | ||
30 | 1 | 6µs | @ISA = qw(Exporter); | ||
31 | 1 | 4µs | @EXPORT = qw( | ||
32 | &GetNewsToDisplay | ||||
33 | &add_opac_new &upd_opac_new &del_opac_new &get_opac_new &get_opac_news | ||||
34 | ); | ||||
35 | 1 | 564µs | 1 | 12µs | } # spent 12µs making 1 call to C4::NewsChannels::BEGIN@28 |
36 | |||||
37 | =head1 NAME | ||||
38 | |||||
39 | C4::NewsChannels - Functions to manage OPAC and intranet news | ||||
40 | |||||
41 | =head1 DESCRIPTION | ||||
42 | |||||
43 | This module provides the functions needed to mange OPAC and intranet news. | ||||
44 | |||||
45 | =head1 FUNCTIONS | ||||
46 | |||||
47 | =cut | ||||
48 | |||||
49 | sub add_opac_new { | ||||
50 | my ($title, $new, $lang, $expirationdate, $timestamp, $number) = @_; | ||||
51 | my $dbh = C4::Context->dbh; | ||||
52 | my $sth = $dbh->prepare("INSERT INTO opac_news (title, new, lang, expirationdate, timestamp, number) VALUES (?,?,?,?,?,?)"); | ||||
53 | $sth->execute($title, $new, $lang, $expirationdate, $timestamp, $number); | ||||
54 | $sth->finish; | ||||
55 | return 1; | ||||
56 | } | ||||
57 | |||||
58 | sub upd_opac_new { | ||||
59 | my ($idnew, $title, $new, $lang, $expirationdate, $timestamp,$number) = @_; | ||||
60 | my $dbh = C4::Context->dbh; | ||||
61 | my $sth = $dbh->prepare(" | ||||
62 | UPDATE opac_news SET | ||||
63 | title = ?, | ||||
64 | new = ?, | ||||
65 | lang = ?, | ||||
66 | expirationdate = ?, | ||||
67 | timestamp = ?, | ||||
68 | number = ? | ||||
69 | WHERE idnew = ? | ||||
70 | "); | ||||
71 | $sth->execute($title, $new, $lang, $expirationdate, $timestamp,$number,$idnew); | ||||
72 | $sth->finish; | ||||
73 | return 1; | ||||
74 | } | ||||
75 | |||||
76 | sub del_opac_new { | ||||
77 | my ($ids) = @_; | ||||
78 | if ($ids) { | ||||
79 | my $dbh = C4::Context->dbh; | ||||
80 | my $sth = $dbh->prepare("DELETE FROM opac_news WHERE idnew IN ($ids)"); | ||||
81 | $sth->execute(); | ||||
82 | $sth->finish; | ||||
83 | return 1; | ||||
84 | } else { | ||||
85 | return 0; | ||||
86 | } | ||||
87 | } | ||||
88 | |||||
89 | sub get_opac_new { | ||||
90 | my ($idnew) = @_; | ||||
91 | my $dbh = C4::Context->dbh; | ||||
92 | my $sth = $dbh->prepare("SELECT * FROM opac_news WHERE idnew = ?"); | ||||
93 | $sth->execute($idnew); | ||||
94 | my $data = $sth->fetchrow_hashref; | ||||
95 | $data->{$data->{'lang'}} = 1 if defined $data->{lang}; | ||||
96 | $data->{expirationdate} = format_date($data->{expirationdate}); | ||||
97 | $data->{timestamp} = format_date($data->{timestamp}); | ||||
98 | $sth->finish; | ||||
99 | return $data; | ||||
100 | } | ||||
101 | |||||
102 | sub get_opac_news { | ||||
103 | my ($limit, $lang) = @_; | ||||
104 | my $dbh = C4::Context->dbh; | ||||
105 | my $query = "SELECT *, timestamp AS newdate FROM opac_news"; | ||||
106 | if ($lang) { | ||||
107 | $query.= " WHERE lang = '" .$lang ."' "; | ||||
108 | } | ||||
109 | $query.= " ORDER BY timestamp DESC "; | ||||
110 | #if ($limit) { | ||||
111 | # $query.= "LIMIT 0, " . $limit; | ||||
112 | #} | ||||
113 | my $sth = $dbh->prepare($query); | ||||
114 | $sth->execute(); | ||||
115 | my @opac_news; | ||||
116 | my $count = 0; | ||||
117 | while (my $row = $sth->fetchrow_hashref) { | ||||
118 | if ((($limit) && ($count < $limit)) || (!$limit)) { | ||||
119 | push @opac_news, $row; | ||||
120 | } | ||||
121 | $count++; | ||||
122 | } | ||||
123 | return ($count, \@opac_news); | ||||
124 | } | ||||
125 | |||||
126 | =head2 GetNewsToDisplay | ||||
127 | |||||
128 | $news = &GetNewsToDisplay($lang); | ||||
129 | C<$news> is a ref to an array which containts | ||||
130 | all news with expirationdate > today or expirationdate is null. | ||||
131 | |||||
132 | =cut | ||||
133 | |||||
134 | sub GetNewsToDisplay { | ||||
135 | my $lang = shift; | ||||
136 | my $dbh = C4::Context->dbh; | ||||
137 | # SELECT *,DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate | ||||
138 | my $query = " | ||||
139 | SELECT *,timestamp AS newdate | ||||
140 | FROM opac_news | ||||
141 | WHERE ( | ||||
142 | expirationdate >= CURRENT_DATE() | ||||
143 | OR expirationdate IS NULL | ||||
144 | OR expirationdate = '00-00-0000' | ||||
145 | ) | ||||
146 | AND `timestamp` <= CURRENT_DATE() | ||||
147 | AND lang = ? | ||||
148 | ORDER BY number | ||||
149 | "; # expirationdate field is NOT in ISO format? | ||||
150 | my $sth = $dbh->prepare($query); | ||||
151 | $sth->execute($lang); | ||||
152 | my @results; | ||||
153 | while ( my $row = $sth->fetchrow_hashref ){ | ||||
154 | $row->{newdate} = format_date($row->{newdate}); | ||||
155 | push @results, $row; | ||||
156 | } | ||||
157 | return \@results; | ||||
158 | } | ||||
159 | |||||
160 | 1 | 3µs | 1; | ||
161 | __END__ |