View | Details | Raw Unified | Return to bug 14788
Collapse All | Expand All

(-)a/C4/Circulation.pm (+61 lines)
Lines 95-100 BEGIN { Link Here
95
		&AnonymiseIssueHistory
95
		&AnonymiseIssueHistory
96
        &CheckIfIssuedToPatron
96
        &CheckIfIssuedToPatron
97
        &IsItemIssued
97
        &IsItemIssued
98
        GetTopIssues
98
	);
99
	);
99
100
100
	# subs to deal with returns
101
	# subs to deal with returns
Lines 3976-3981 sub GetPendingOnSiteCheckouts { Link Here
3976
    |, { Slice => {} } );
3977
    |, { Slice => {} } );
3977
}
3978
}
3978
3979
3980
sub GetTopIssues {
3981
    my ($params) = @_;
3982
3983
    my ($count, $branch, $itemtype, $ccode, $newness)
3984
        = @$params{qw(count branch itemtype ccode newness)};
3985
3986
    my $dbh = C4::Context->dbh;
3987
    my $query = q{
3988
        SELECT b.biblionumber, b.title, b.author, bi.itemtype, bi.publishercode,
3989
          bi.place, bi.publicationyear, b.copyrightdate, bi.pages, bi.size,
3990
          i.ccode, SUM(i.issues) AS count
3991
        FROM biblio b
3992
        LEFT JOIN items i ON (i.biblionumber = b.biblionumber)
3993
        LEFT JOIN biblioitems bi ON (bi.biblionumber = b.biblionumber)
3994
    };
3995
3996
    my (@where_strs, @where_args);
3997
3998
    if ($branch) {
3999
        push @where_strs, 'i.homebranch = ?';
4000
        push @where_args, $branch;
4001
    }
4002
    if ($itemtype) {
4003
        if (C4::Context->preference('item-level_itypes')){
4004
            push @where_strs, 'i.itype = ?';
4005
            push @where_args, $itemtype;
4006
        } else {
4007
            push @where_strs, 'bi.itemtype = ?';
4008
            push @where_args, $itemtype;
4009
        }
4010
    }
4011
    if ($ccode) {
4012
        push @where_strs, 'i.ccode = ?';
4013
        push @where_args, $ccode;
4014
    }
4015
    if ($newness) {
4016
        push @where_strs, 'TO_DAYS(NOW()) - TO_DAYS(b.datecreated) <= ?';
4017
        push @where_args, $newness;
4018
    }
4019
4020
    if (@where_strs) {
4021
        $query .= 'WHERE ' . join(' AND ', @where_strs);
4022
    }
4023
4024
    $query .= q{
4025
        GROUP BY b.biblionumber
4026
        HAVING count > 0
4027
        ORDER BY count DESC
4028
    };
4029
4030
    $count = int($count);
4031
    if ($count > 0) {
4032
        $query .= "LIMIT $count";
4033
    }
4034
4035
    my $rows = $dbh->selectall_arrayref($query, { Slice => {} }, @where_args);
4036
4037
    return @$rows;
4038
}
4039
3979
__END__
4040
__END__
3980
4041
3981
=head1 AUTHOR
4042
=head1 AUTHOR
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-topissues.tt (-27 / +26 lines)
Lines 1-4 Link Here
1
[% USE Koha %]
1
[% USE Koha %]
2
[% USE AuthorisedValues %]
3
[% USE ItemTypes %]
2
[% INCLUDE 'doc-head-open.inc' %]
4
[% INCLUDE 'doc-head-open.inc' %]
3
<title>[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog &rsaquo; Most popular titles</title>
5
<title>[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog &rsaquo; Most popular titles</title>
4
[% INCLUDE 'doc-head-close.inc' %]
6
[% INCLUDE 'doc-head-close.inc' %]
Lines 20-26 Link Here
20
        <div class="container-fluid">
22
        <div class="container-fluid">
21
            <div class="row-fluid">
23
            <div class="row-fluid">
22
                <div class="span2">
24
                <div class="span2">
23
                    [% IF ( results_loop ) %]
25
                    [% IF ( results ) %]
24
                        <div id="usertopissues">
26
                        <div id="usertopissues">
25
                            [% INCLUDE 'opac-topissues.inc' %]
27
                            [% INCLUDE 'opac-topissues.inc' %]
26
                            [% IF ( OpacNav || OpacNavBottom ) %]
28
                            [% IF ( OpacNav || OpacNavBottom ) %]
Lines 38-44 Link Here
38
                <div class="span10">
40
                <div class="span10">
39
                    <div id="topissues" class="maincontent">
41
                    <div id="topissues" class="maincontent">
40
42
41
                        [% IF ( results_loop ) %]
43
                        [% IF ( results ) %]
42
                            <table id="topissuest" class="table table-bordered table-striped">
44
                            <table id="topissuest" class="table table-bordered table-striped">
43
                                <caption>
45
                                <caption>
44
                                    The [% limit %] most checked-out
46
                                    The [% limit %] most checked-out
Lines 49-56 Link Here
49
                                    at
51
                                    at
50
                                    [% branch %]
52
                                    [% branch %]
51
                                    [% END %]
53
                                    [% END %]
52
                                    [% IF ( timeLimitFinite ) %]
54
                                    [% IF ( timeLimit != 999 ) %]
53
                                    in the past [% timeLimitFinite |html %] months
55
                                    in the past [% timeLimit |html %] months
54
                                    [% ELSE %] of all time[% END %]
56
                                    [% ELSE %] of all time[% END %]
55
                                </caption>
57
                                </caption>
56
                                <thead>
58
                                <thead>
Lines 62-94 Link Here
62
                                    </tr>
64
                                    </tr>
63
                                </thead>
65
                                </thead>
64
                                <tbody>
66
                                <tbody>
65
                                    [% FOREACH results_loo IN results_loop %]
67
                                    [% FOREACH result IN results %]
66
                                        <tr>
68
                                        <tr>
67
                                            <td><a class="title" href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% results_loo.biblionumber %]">[% results_loo.title |html %]</a><p>[% results_loo.author %]
69
                                            <td><a class="title" href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% result.biblionumber %]">[% result.title |html %]</a><p>[% result.author %]
68
                                            [% IF ( results_loo.publishercode ) %]- [% results_loo.publishercode %][% END %] [% IF ( results_loo.seriestitle ) %]([% results_loo.seriestitle %])[% END %]
70
                                            [% IF ( result.publishercode ) %]- [% result.publishercode %][% END %]
69
                                            [% IF ( results_loo.place ) %][% results_loo.place %][% END %]
71
                                            [% IF ( result.place ) %][% result.place %][% END %]
70
                                            [% IF ( results_loo.publicationyear ) %]
72
                                            [% IF ( result.publicationyear ) %]
71
                                                [% results_loo.publicationyear %]
73
                                                [% result.publicationyear %]
72
                                            [% ELSIF ( results_loo.copyrightdate ) %]
74
                                            [% ELSIF ( result.copyrightdate ) %]
73
                                                [% results_loo.copyrightdate %]
75
                                                [% result.copyrightdate %]
74
                                            [% END %]
76
                                            [% END %]
75
                                            [% IF ( results_loo.pages ) %] - [% results_loo.pages %][% END %]
77
                                            [% IF ( result.pages ) %] - [% result.pages %][% END %]
76
                                            [% IF ( results_loo.item('size') ) %][% results_loo.item('size') %][% END %]</p>
78
                                            [% IF ( result.item('size') ) %][% result.item('size') %][% END %]</p>
77
                                            </td>
79
                                            </td>
78
                                            <td>
80
                                            <td>
79
                                                [% IF ( results_loo.description ) %]
81
                                              [% IF Koha.Preference('AdvancedSearchTypes') == 'ccode' %]
80
                                                    <span class="tdlabel">
82
                                                <span class="tdlabel">Collection</span>
81
                                                        [% IF ( ccodesearch ) %]
83
                                                [% AuthorisedValues.GetByCode('ccode', result.ccode, 1) %]
82
                                                            Collection
84
                                              [% ELSE %]
83
                                                        [% ELSE %]
85
                                                <span class="tdlabel">Item type</span>
84
                                                            Item type
86
                                                [% ItemTypes.GetDescription(result.itemtype) %]
85
                                                        [% END %]:
87
                                              [% END %]
86
                                                    </span>
87
                                                    [% results_loo.description %]
88
                                                [% END %]
89
                                            </td>
88
                                            </td>
90
                                            <td><span class="tdlabel">Checkouts: </span> [% results_loo.tot %]</td>
89
                                            <td><span class="tdlabel">Checkouts: </span> [% result.count %]</td>
91
                                            [% IF Koha.Preference( 'opacuserlogin' ) == 1 %]<td>[% IF Koha.Preference( 'RequestOnOpac' ) == 1 %][% UNLESS ( results_loo.norequests ) %]<a href="/cgi-bin/koha/opac-reserve.pl?biblionumber=[% results_loo.biblionumber %]">Place hold</a>[% END %][% END %]</td>[% END %]
90
                                            [% IF Koha.Preference( 'opacuserlogin' ) == 1 %]<td>[% IF Koha.Preference( 'RequestOnOpac' ) == 1 %][% UNLESS ( result.norequests ) %]<a href="/cgi-bin/koha/opac-reserve.pl?biblionumber=[% result.biblionumber %]">Place hold</a>[% END %][% END %]</td>[% END %]
92
                                            </tr>
91
                                            </tr>
93
                                    [% END %]
92
                                    [% END %]
94
                                </tbody>
93
                                </tbody>
Lines 152-158 Link Here
152
                                    <input type="submit" class="btn" value="Submit" />
151
                                    <input type="submit" class="btn" value="Submit" />
153
                                </fieldset>
152
                                </fieldset>
154
                            </form>
153
                            </form>
155
                       [% END # / IF results_loop %]
154
                       [% END # / IF results %]
156
                    </div> <!-- / #topissues -->
155
                    </div> <!-- / #topissues -->
157
                </div> <!-- / .span10 -->
156
                </div> <!-- / .span10 -->
158
            </div> <!-- / .row-fluid -->
157
            </div> <!-- / .row-fluid -->
(-)a/opac/opac-topissues.pl (-59 / +13 lines)
Lines 29-34 use C4::Search; Link Here
29
use C4::Output;
29
use C4::Output;
30
use C4::Koha;
30
use C4::Koha;
31
use C4::Branch;
31
use C4::Branch;
32
use C4::Circulation;
32
use Date::Manip;
33
use Date::Manip;
33
34
34
=head1 NAME
35
=head1 NAME
Lines 73-147 my $itemtype = $input->param('itemtype') || ''; Link Here
73
my $timeLimit = $input->param('timeLimit') || 3;
74
my $timeLimit = $input->param('timeLimit') || 3;
74
my $advanced_search_types = C4::Context->preference('AdvancedSearchTypes');
75
my $advanced_search_types = C4::Context->preference('AdvancedSearchTypes');
75
76
76
my $whereclause = '';
77
77
$whereclause .= ' AND items.homebranch='.$dbh->quote($branch) if ($branch);
78
my $params = {
78
$whereclause .= ' AND TO_DAYS(NOW()) - TO_DAYS(biblio.datecreated) <= '.($timeLimit*30) if $timeLimit < 999;
79
    count => $limit,
79
$whereclause =~ s/ AND $// if $whereclause;
80
    branch => $branch,
80
my $query;
81
    newness => $timeLimit < 999 ? $timeLimit * 30 : undef,
82
};
81
83
82
if($advanced_search_types eq 'ccode'){
84
if($advanced_search_types eq 'ccode'){
83
    $whereclause .= ' AND authorised_values.authorised_value='.$dbh->quote($itemtype) if $itemtype;
85
    $params->{ccode} = $itemtype;
84
    $query = "SELECT datecreated, biblio.biblionumber, title,
85
                    author, sum( items.issues ) AS tot, biblioitems.itemtype,
86
                    biblioitems.publishercode, biblioitems.place, biblioitems.publicationyear, biblio.copyrightdate,
87
                    authorised_values.lib as description, biblioitems.pages, biblioitems.size
88
                    FROM biblio
89
                    LEFT JOIN items USING (biblionumber)
90
                    LEFT JOIN biblioitems USING (biblionumber)
91
                    LEFT JOIN authorised_values ON items.ccode = authorised_values.authorised_value
92
                    WHERE 1
93
                    $whereclause
94
                    AND authorised_values.category = 'ccode' 
95
                    GROUP BY biblio.biblionumber
96
                    HAVING tot >0
97
                    ORDER BY tot DESC
98
                    LIMIT ?
99
                    ";
100
    $template->param(ccodesearch => 1);
86
    $template->param(ccodesearch => 1);
101
}else{
87
} else {
102
    if ($itemtype){
88
    $params->{itemtype} = $itemtype;
103
	if (C4::Context->preference('item-level_itypes')){
89
    $template->param(itemtypesearch => 1);
104
	    $whereclause .= ' AND items.itype = ' . $dbh->quote($itemtype);
105
	}
106
	else {
107
	    $whereclause .= ' AND biblioitems.itemtype='.$dbh->quote($itemtype);
108
        }
109
    }
110
    $query = "SELECT datecreated, biblio.biblionumber, title,
111
                    author, sum( items.issues ) AS tot, biblioitems.itemtype,
112
                    biblioitems.publishercode, biblioitems.place, biblioitems.publicationyear, biblio.copyrightdate,
113
                    itemtypes.description, biblioitems.pages, biblioitems.size
114
                    FROM biblio
115
                    LEFT JOIN items USING (biblionumber)
116
                    LEFT JOIN biblioitems USING (biblionumber)
117
                    LEFT JOIN itemtypes ON itemtypes.itemtype = biblioitems.itemtype
118
                    WHERE 1
119
                    $whereclause
120
                    GROUP BY biblio.biblionumber
121
                    HAVING tot >0
122
                    ORDER BY tot DESC
123
                    LIMIT ?
124
                    ";
125
     $template->param(itemtypesearch => 1);
126
}
127
128
my $sth = $dbh->prepare($query);
129
$sth->execute($limit);
130
my @results;
131
while (my $line= $sth->fetchrow_hashref) {
132
    push @results, $line;
133
}
90
}
134
91
135
my $timeLimitFinite = $timeLimit;
92
my @results = GetTopIssues($params);
136
if($timeLimit eq 999){ $timeLimitFinite = 0 };
137
93
138
$template->param(do_it => 1,
94
$template->param(do_it => 1,
139
                limit => $limit,
95
                limit => $limit,
140
                branch => $branches->{$branch}->{branchname},
96
                branch => $branches->{$branch}->{branchname},
141
                itemtype => $itemtypes->{$itemtype}->{description},
97
                itemtype => $itemtypes->{$itemtype}->{description},
142
                timeLimit => $timeLimit,
98
                timeLimit => $timeLimit,
143
                timeLimitFinite => $timeLimitFinite,
99
                results => \@results,
144
                results_loop => \@results,
145
                );
100
                );
146
101
147
$template->param( branchloop => GetBranchesLoop($branch));
102
$template->param( branchloop => GetBranchesLoop($branch));
148
- 

Return to bug 14788