Login   Register  
PHP Classes
elePHPant
Icontem

File: arromat.class.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Sebastian D  >  arromat  >  arromat.class.php  >  Download  
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
Author: By
Last change: xxxxx
Date: 4 years ago
Size: 3,230 bytes
 

Contents

Class file image Download
<?
//    simple use, easy integration
//     Author: SD
//    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;
    }














}