koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] koha authorities/authorities-home.pl C4/Output....


From: Pierrick LE GALL
Subject: [Koha-cvs] koha authorities/authorities-home.pl C4/Output....
Date: Tue, 04 Apr 2006 10:05:48 +0000

CVSROOT:        /sources/koha
Module name:    koha
Branch:         
Changes by:     Pierrick LE GALL <address@hidden>       06/04/04 10:05:48

Modified files:
        authorities    : authorities-home.pl 
        C4             : Output.pm 
Added files:
        koha-tmpl/intranet-tmpl/prog/en/includes: menu-authorities.inc 
        koha-tmpl/intranet-tmpl/prog/en/authorities: 
                                                     searchresultlist.tmpl 
                                                     detail.tmpl 
                                                     authorities.tmpl 
                                                     authorities-home.tmpl 

Log message:
        new: authorities in prog/en template, only partial import from 
default/en
        template.
        
        improved: C4::Output::pagination_bar builds an HTML pagination bar with 
no
        language dependency. This function hugely simplifies templates and 
offers a
        standard pagination method. This function also improves preformances.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/koha/koha-tmpl/intranet-tmpl/prog/en/includes/menu-authorities.inc?rev=1.1
http://cvs.savannah.gnu.org/viewcvs/koha/koha/koha-tmpl/intranet-tmpl/prog/en/authorities/searchresultlist.tmpl?rev=1.1
http://cvs.savannah.gnu.org/viewcvs/koha/koha/koha-tmpl/intranet-tmpl/prog/en/authorities/detail.tmpl?rev=1.1
http://cvs.savannah.gnu.org/viewcvs/koha/koha/koha-tmpl/intranet-tmpl/prog/en/authorities/authorities.tmpl?rev=1.1
http://cvs.savannah.gnu.org/viewcvs/koha/koha/koha-tmpl/intranet-tmpl/prog/en/authorities/authorities-home.tmpl?rev=1.1
http://cvs.savannah.gnu.org/viewcvs/koha/koha/authorities/authorities-home.pl.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/koha/koha/C4/Output.pm.diff?tr1=1.53&tr2=1.54&r1=text&r2=text

Patches:
Index: koha/C4/Output.pm
diff -u koha/C4/Output.pm:1.53 koha/C4/Output.pm:1.54
--- koha/C4/Output.pm:1.53      Thu Aug  4 13:31:22 2005
+++ koha/C4/Output.pm   Tue Apr  4 10:05:48 2006
@@ -1,6 +1,6 @@
 package C4::Output;
 
-# $Id: Output.pm,v 1.53 2005/08/04 13:31:22 tipaul Exp $
+# $Id: Output.pm,v 1.54 2006/04/04 10:05:48 plg Exp $
 
 #package to deal with marking up output
 #You will need to edit parts of this pm
@@ -51,7 +51,7 @@
 
 @ISA = qw(Exporter);
 @EXPORT = qw(
-               &themelanguage &gettemplate setlanguagecookie
+               &themelanguage &gettemplate setlanguagecookie pagination_bar
                );
 
 #FIXME: this is a quick fix to stop rc1 installing broken
@@ -146,6 +146,7 @@
   }
 }
 
+
 sub setlanguagecookie {
    my ($query,$language,$uri)address@hidden;
    my $cookie=$query->cookie(-name => 'KohaOpacLanguage',
@@ -155,6 +156,144 @@
    -cookie=>$cookie);
 }                                 
 
+=item pagination_bar
+
+   pagination_bar($base_url, $nb_pages, $current_page, $startfrom_name)
+
+Build an HTML pagination bar based on the number of page to display, the
+current page and the url to give to each page link.
+
+C<$base_url> is the URL for each page link. The
+C<$startfrom_name>=page_number is added at the end of the each URL.
+
+C<$nb_pages> is the total number of pages available.
+
+C<$current_page> is the current page number. This page number won't become a
+link.
+
+This function returns HTML, without any language dependency.
+
+=cut
+
+sub pagination_bar {
+    my ($base_url, $nb_pages, $current_page, $startfrom_name) = @_;
+
+    # how many pages to show before and after the current page?
+    my $pages_around = 2;
+
+    my $url =
+        $base_url
+        .($base_url =~ m/&/ ? '&amp;' : '?')
+        .$startfrom_name.'='
+        ;
+
+    my $pagination_bar = '';
+
+    # current page detection
+    if (not defined $current_page) {
+        $current_page = 1;
+    }
+
+    # navigation bar useful only if more than one page to display !
+    if ($nb_pages > 1) {
+        # link to first page?
+        if ($current_page > 1) {
+            $pagination_bar.=
+                "\n".'&nbsp;'
+                .'<a href="'.$url.'1" rel="start">'
+                .'&lt;&lt;'
+                .'</a>'
+                ;
+        }
+        else {
+            $pagination_bar.=
+                "\n".'&nbsp;<span class="inactive">&lt;&lt;</span>';
+        }
+
+        # link on previous page ?
+        if ($current_page > 1) {
+            my $previous = $current_page - 1;
+
+            $pagination_bar.=
+                "\n".'&nbsp;'
+                .'<a href="'
+                .$url.$previous
+                .'" rel="prev">'
+                .'&lt;'
+                .'</a>'
+                ;
+        }
+        else {
+            $pagination_bar.=
+                "\n".'&nbsp;<span class="inactive">&lt;</span>';
+        }
+
+        my $min_to_display = $current_page - $pages_around;
+        my $max_to_display = $current_page + $pages_around;
+        my $last_displayed_page = undef;
+
+        for my $page_number (1..$nb_pages) {
+            if ($page_number == 1
+                or $page_number == $nb_pages
+                or ($page_number >= $min_to_display and $page_number <= 
$max_to_display)
+            ) {
+                if (defined $last_displayed_page
+                    and $last_displayed_page != $page_number - 1
+                ) {
+                    $pagination_bar.=
+                        "\n".'&nbsp;<span class="inactive">...</span>'
+                        ;
+                }
+
+                if ($page_number == $current_page) {
+                    $pagination_bar.=
+                        "\n".'&nbsp;'
+                        .'<span class="currentPage">'.$page_number.'</span>'
+                        ;
+                }
+                else {
+                    $pagination_bar.=
+                        "\n".'&nbsp;'
+                        .'<a href="'.$url.$page_number.'">'.$page_number.'</a>'
+                        ;
+                }
+                $last_displayed_page = $page_number;
+            }
+        }
+
+        # link on next page?
+        if ($current_page < $nb_pages) {
+            my $next = $current_page + 1;
+
+            $pagination_bar.=
+                "\n".'&nbsp;<a href="'.$url.$next.'" rel="next">'
+                .'&gt;'
+                .'</a>'
+                ;
+        }
+        else {
+            $pagination_bar.=
+                "\n".'&nbsp;<span class="inactive">&gt;</span>'
+                ;
+        }
+
+        # link to last page?
+        if ($current_page != $nb_pages) {
+            $pagination_bar.=
+                "\n".'&nbsp;<a href="'.$url.$nb_pages.'" rel="last">'
+                .'&gt;&gt;'
+                .'</a>'
+                ;
+        }
+        else {
+            $pagination_bar.=
+                "\n".'&nbsp;<span class="inactive">&gt;&gt;</span>';
+        }
+    }
+
+    return $pagination_bar;
+}
+
 
 END { }       # module clean-up code here (global destructor)
 
Index: koha/authorities/authorities-home.pl
diff -u koha/authorities/authorities-home.pl:1.11 
koha/authorities/authorities-home.pl:1.12
--- koha/authorities/authorities-home.pl:1.11   Fri Jan  6 16:39:37 2006
+++ koha/authorities/authorities-home.pl        Tue Apr  4 10:05:48 2006
@@ -38,11 +38,8 @@
 my $authtypecode = $query->param('authtypecode');
 my $dbh = C4::Context->dbh;
 
-my $startfrom=$query->param('startfrom');
 my $authid=$query->param('authid');
-$startfrom=0 if(!defined $startfrom);
 my ($template, $loggedinuser, $cookie);
-my $resultsperpage;
 
 my $authtypes = getauthtypes;
 my @authtypesloop;
@@ -62,85 +59,90 @@
        my @operator = $query->param('operator');
        my @value = $query->param('value');
 
-       $resultsperpage= $query->param('resultsperpage');
-       $resultsperpage = 19 if(!defined $resultsperpage);
-       my @tags;
-       my ($results,$total) = authoritysearch($dbh, 
address@hidden,address@hidden,
-                                                                               
address@hidden, address@hidden, address@hidden,
-                                                                               
$startfrom*$resultsperpage, $resultsperpage,$authtypecode);
-       ($template, $loggedinuser, $cookie)
-               = get_template_and_user({template_name => 
"authorities/searchresultlist.tmpl",
-                               query => $query,
-                               type => 'intranet',
-                               authnotrequired => 0,
-                               flagsrequired => {borrowers => 1},
-                               flagsrequired => {catalogue => 1},
-                               debug => 1,
-                               });
+    my $startfrom = $query->param('startfrom') || 1;
+    my $resultsperpage = $query->param('resultsperpage') || 19;
 
-       # multi page display gestion
-       my $displaynext=0;
-       my $displayprev=$startfrom;
-       if(($total - (($startfrom+1)*($resultsperpage))) > 0 ){
-               $displaynext = 1;
-       }
+       my ($results,$total) = authoritysearch(
+        $dbh,
+        address@hidden,
+        address@hidden,
+        address@hidden,
+        address@hidden,
+        address@hidden,
+        ($startfrom - 1)*$resultsperpage,
+        $resultsperpage,
+        $authtypecode
+    );
+
+       ($template, $loggedinuser, $cookie)
+               = get_template_and_user({
+            template_name => "authorities/searchresultlist.tmpl",
+            query => $query,
+            type => 'intranet',
+            authnotrequired => 0,
+            flagsrequired => {borrowers => 1},
+            flagsrequired => {catalogue => 1},
+            debug => 1,
+        });
 
        my @field_data = ();
 
-       # we must get parameters once again. Because if there is a mainentry, 
it has been replaced by something else during the search, thus the links 
next/previous would not work anymore 
+       # we must get parameters once again. Because if there is a mainentry, it
+       # has been replaced by something else during the search, thus the links
+       # next/previous would not work anymore
        my @marclist_ini = $query->param('marclist');
        for(my $i = 0 ; $i <= $#marclist ; $i++)
        {
-               push @field_data, { term => "marclist", val=>$marclist_ini[$i] 
};
-               push @field_data, { term => "and_or", val=>$and_or[$i] };
-               push @field_data, { term => "excluding", val=>$excluding[$i] };
-               push @field_data, { term => "operator", val=>$operator[$i] };
-               push @field_data, { term => "value", val=>$value[$i] };
+               push @field_data, { term => "marclist"  , 
val=>$marclist_ini[$i] };
+               push @field_data, { term => "and_or"    , val=>$and_or[$i] };
+               push @field_data, { term => "excluding" , val=>$excluding[$i] };
+               push @field_data, { term => "operator"  , val=>$operator[$i] };
+               push @field_data, { term => "value"     , val=>$value[$i] };
        }
 
-       my @numbers = ();
-
-       if ($total>$resultsperpage)
-       {
-               for (my $i=1; $i<$total/$resultsperpage+1; $i++)
-               {
-                       if ($i<16)
-                       {
-                       my $highlight=0;
-                       ($startfrom==($i-1)) && ($highlight=1);
-                       push @numbers, { number => $i,
-                                       highlight => $highlight ,
-                                       searchdata=> address@hidden,
-                                       startfrom => ($i-1)};
-                       }
-       }
-       }
+    # construction of the url of each page
+    my $base_url =
+        'authorities-home.pl?'
+        .join(
+            '&amp;',
+            map { $_->{term}.'='.$_->{val} } @field_data
+        )
+        .'&amp;'
+        .join(
+            '&amp;',
+            map { $_->{term}.'='.$_->{val} } (
+                {term => 'resultsperpage', val => $resultsperpage},
+                {term => 'type'          , val => 'intranet'},
+                {term => 'op'            , val => 'do_search'},
+                {term => 'authtypecode'  , val => $authtypecode}
+            )
+        )
+        ;
 
-       my $from = $startfrom*$resultsperpage+1;
+       my $from = ($startfrom - 1) * $resultsperpage + 1;
        my $to;
 
-       if($total < (($startfrom+1)*$resultsperpage))
-       {
+       if ($total < $startfrom * $resultsperpage) {
                $to = $total;
-       } else {
-               $to = (($startfrom+1)*$resultsperpage);
        }
+    else {
+               $to = $startfrom * $resultsperpage;
+       }
+
        $template->param(result => $results) if $results;
+
        $template->param(
-                                                       startfrom=> $startfrom,
-                                                       displaynext=> 
$displaynext,
-                                                       displayprev=> 
$displayprev,
-                                                       resultsperpage => 
$resultsperpage,
-                                                       startfromnext => 
$startfrom+1,
-                                                       startfromprev => 
$startfrom-1,
-                                                       
searchdata=>address@hidden,
-                                                       total=>$total,
-                                                       from=>$from,
-                                                       to=>$to,
-                                                       numbers=>address@hidden,
-                                                       
authtypecode=>$authtypecode,
-                                                       isEDITORS => 
$authtypecode eq 'EDITORS',
-                                                       );
+        pagination_bar => pagination_bar(
+            $base_url,
+            int($total/$resultsperpage)+1,
+            $startfrom,
+            'startfrom'
+            ),
+        total=>$total,
+        from=>$from,
+        to=>$to,
+        isEDITORS => $authtypecode eq 'EDITORS',
+    );
 
 } elsif ($op eq "delete") {
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]