PHP Classes
Icontem

File: arromat.class.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Sebastian D  >  arromat  >  arromat.class.php  
File: arromat.class.php
Role: Class source
Content type: text/plain
Description: class source to simplify the paging process
Class: arromat
Generate pagination parameters for data navigation
 

Contents

Class file image Download
<?
//    simple use, easy integration
//     Author: Sebastian Dimitrow
//    Version:    1.31

class arromat
{




    var 
$rows    =    5;
    var 
$pages= array();
    var 
$actual_page 1;
    var 
$pages_per_site 20;

    var 
$start_row 0;
    var 
$data = array();
    

    function 
arromat($data,$page)
    {

        
$this->data= (array)$data;
        if (!empty(
$page)) $this->actual_page=$page;

    }




    function 
getNumberPages()
    {
        
//thanks to alex for bugfixing
        
if ($this->rows==0)
            
$this->number_pages=1;
        else
            
$this->number_pages=ceil(count($this->data)/$this->rows);

        return 
$this->number_pages;
    }

    function 
setRows($anzahl)
    {
       
$this->rows=$anzahl;
    }


    function 
getPages()
    {
        
$seiten=array();
        
        if (
$this->actual_page+$this->pages_per_site<$this->getNumberPages())
            
$end=$this->actual_page+(int)($this->pages_per_site/2);
        else
            
$end=$this->getNumberPages();
        
$start=$end-$this->pages_per_site;
        if (
$start<0)
            
$start=0;
        for (
$i=$start;$i<$end;$i++)
            
$seiten[$i]=$i+1;

        return 
$seiten;
    }


    function 
getActualPage()
    {
        return 
$this->actual_page;
    }


    function 
getNextPage()
    {
        if (
$this->actual_page $this->getNumberPages() && $this->getNumberPages()>1)
            return 
$this->actual_page+1;
        else
            return 
false;
    }

    function 
getPrevPage()
    {
        if (
$this->actual_page 1)
            return 
$this->actual_page-1;
        else
            return 
false;
    }


    function 
getTotalItems()
    {
        return 
count($this->data);
    }

    function 
getCurrentItemsStr($separator='-')
    {
        
$start = ($this->rows*($this->actual_page-1));
        
$tmp=$start;
        if (
$start==0)
            
$start=1;
        return 
$start.$separator.($tmp+count($this->getPageData()));
    }

    function 
getPageData()
    {
        return 
array_slice ($this->data$this->getStartRow(),$this->rows);
    }


    
// a little sort function
    
function mksort($ky,$sort_method='asc')
    {
        if (!
$ky) return false;

        
$arr_tmp = array();
        
$arr_tmp1 = array();
        foreach (
$this->data as $key=>$val)
        {
            if (
array_key_exists($ky,$val))
            {
                
$arr_tmp[]=$val[$ky];
            } else return 
false;
        }


            switch (
$sort_method)
            {

                case 
'desc':
                            
natcasesort($arr_tmp);
                            
arsort($arr_tmp);
                            break;
                default:    
natcasesort($arr_tmp);
                            break;
            }


            foreach(
$arr_tmp as $key => $val)
            {
                
$this->data[$key][$ky]=$arr_tmp[$key];
                
$arr_tmp1[]=$this->data[$key];
            }
            
$this->data=$arr_tmp1;

           return 
true;
    }




    
//PRIVATE


    
function getStartRow()
    {
        
$this->start_row=($this->rows*$this->actual_page)-$this->rows;
        return 
$this->start_row;
    }














}

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products