Witam
Ja kiedyś napisałem sobie taką klasę – działała, ale dziś już mam to inaczej napisane. W każdym razie może się przyda;-) Nowej klasy nie dam, ale może sobie tą ktoś przerobi;-) Jak się przyda to fajno jak nie to też. A jak używać chyba widać;-)
<?php
if (eregi(\"class.pagesMenu.inc.php\",$_SERVER['PHP_SELF'])) { Header(\"Location: ../index.php\"); }
class cPagesMenu {
var $current;
var $max;
var $jumpSize;
var $numbersTable;
var $next;
var $back;
function cPagesMenu($from, $max, $jump) {
$this->current = ceil($from/$jump)+1; $this->max = ceil($max/$jump); $this->jumpSize = $jump;
if($from<0)
$form = 0;
if($from>$max)
$from = $max-$jump;
if($this->current<=3) {
$to = $this->max;
if($this->max>=7)
$to = 7;
for($count = 1; $count<=$to; $count++) {
if($count == $this->current)
$tmp = array('Number' => $count, 'Current' => true); else
$tmp = array('Number' => $count, 'Current' => false, 'From' => ($count-1
)*$jump);
$this->numbersTable[$count-1] = $tmp;
}
if($this->current > 1)
$this->back = true;
else
$this->back = false;
if($this->current < $this->max)
$this->next = true;
else
$this->next = false;
} elseif($this->current<=($this->max-3) && ($this->current>3)) {
for($count = $this->current-3, $index = 0; $count<=$this->current+3; $count++, $index++) {
if($count == $this->current)
$tmp = array('Number' => $count, 'Current' => true); else
$tmp = array('Number' => $count, 'Current' => false, 'From' => ($count-1
)*$jump);
$this->numbersTable[$index] = $tmp;
}
if($this->current > 1)
$this->back = true;
else
$this->back = false;
if($this->current < $this->max)
$this->next = true;
else
$this->next = false;
} elseif($this->current>($this->max-3)) {
if($this->max > 7)
$fr = $this->max-6;
else
$fr = $this->max-($this->max-1);
for($count = $fr, $index = 0; $count<=$this->max; $count++, $index++) {
if($count == $this->current)
$tmp = array('Number' => $count, 'Current' => true); else
$tmp = array('Number' => $count, 'Current' => false, 'From' => ($count-1
)*$jump);
$this->numbersTable[$index] = $tmp;
}
if($this->max-$this->current >= 0)
$this->back = true;
else
$this->back = false;
if($this->current<$this->max)
$this->next = true;
else
$this->next = false;
}
}
function getNumbers() {
return $this->numbersTable;
}
function getCurrent() {
return $this->current;
}
function getNext() {
if($this->next)
return (($this->current-1)*$this->jumpSize)+$this->jumpSize;
else
return false;
}
function getBack() {
if($this->back)
return (($this->current-1)*$this->jumpSize)-$this->jumpSize;
else
return false;
}
}
?>
Pozdrawiam
Marcin Staniszczak