<?php defined('SYSPATH') OR die('No direct access allowed.');

class timation {
    
    public static function sinceSaved($saleTime){
        
        $currentTime 	= time();
        $since 		= abs($currentTime - $saleTime);
        $differenced     = '0 seconds ago';
        
        if( ($showTime = (int)( $since / (3600*24*30))) >= 1){
            if($showTime == 1)
                $differenced = $showTime." month ago";
            else
                $differenced = $showTime." months ago";
        }
        elseif(($showTime = (int)( $since / (3600*24))) >= 1){
            if($showTime == 1)
                $differenced = $showTime." day ago";
            else
                $differenced = $showTime." days ago";
        }
        elseif(($showTime = (int)( $since / 3600)) >= 1){
            if($showTime == 1)
                $differenced = $showTime." hour ago";
            else
                $differenced = $showTime." hours ago";
        }
        elseif(($showTime = (int)( $since / 60))){
            if($showTime == 1)
                $differenced = $showTime." minute ago";
            else
                $differenced = $showTime." minutes ago";
        }
        elseif(($showTime = (int) $since)){
            if($showTime == 1)
                $differenced = $showTime." second ago";
            else
                $differenced = $showTime." seconds ago";
        }
        
        return $differenced;
    }
    
    public static function pagedMessages($data, $messages){
        
        $view   = View::factory('message', $data)	->bind('pagination', $pagination)
							->bind('messages', $messages);
	    
	$total      =count($messages);
	$pagination = Pagination::factory(array(
		    'current_page'   => array('source'=>'query_string', 'key'=>'page'),
		    'total_items' => $total,
		    'items_per_page' => 5,));
		
	$messages  = array_slice($messages,$pagination->offset ,$pagination->items_per_page);
        
        return $view;
    }
}