Your IP : 216.73.217.69


Current Path : /home/semix18/public_html/optimum-wycena.pl/core/classes/
Upload File :
Current File : /home/semix18/public_html/optimum-wycena.pl/core/classes/class.dbConnectRowCache.php

<?php
/**
*	Dobi System
*
*	Terms of use and legal restrictions:
*   PLEASE READ THESE TERMS ( www.dobi.pl/doc/license/ ) CAREFULLY BEFORE USING THIS PRODUCT. 
*	USING THIS PRODUCT INDICATES THAT YOU ACCEPT THESE TERMS. 
*	IF YOU DO NOT ACCEPT THESE TERMS , DO NOT USE THIS PRODUCT.
*
*	PHP 5.1.2 and later 
*
*	@license	www.dobi.pl/doc/license/ Dobi License 1.0
*   @copyright	Copyright (c) 2005-2006 Michał 'Cube' Daniel ( http://www.dobi.pl )
* 	@link		www.dobi.pl
*	@package	Dobi Core
*	@version 	1.0, 2006/08/10 11:57
*   @author		Michał 'Cube' Daniel cube@dobi.pl		
*
*/

class dbConnectRowCache 
{
	private $db_arr_row_cache_data;
	private $db_row_cache_name = '';
	private $db = null;
	 
	public function __construct( dbConnect $dbConnect )
	{
		$this->db = $dbConnect;
	}
	 
	public function __call( $method, $args)
	{
		if (method_exists($this->db, $method))
	    {
	       	switch(count($args))
	       	{
				case 0:
						return $this->db->$method();
				case 1:
						return $this->db->$method($args[0]);		
				case 2:
						return $this->db->$method($args[0], $args[1]);
				case 3:
						return $this->db->$method($args[0], $args[1], $args[2]);
				case 4:
						return $this->db->$method($args[0], $args[1], $args[2], $args[3]);		
				case 5:
						return $this->db->$method($args[0], $args[1], $args[2], $args[3], $args[4]);
				default:
						Dobi::exception('dobiException', WARNING, _DOBI_DATABASE_ERR_6_ . ' (' . $method . ')');														     
			}
		}
		else 
		{
		 	Dobi::exception('dobiException', FATAL, _DOBI_DATABASE_ERR_7_ . ' (' . $method . ')');   
		}  
	}
	
	public function rowCache( $name, $select, $from, $where = '', $order = '', $limit = '')
	{
	 	$sql = 'SELECT ' . $select . ' FROM ' . $this->db->getTable($from); 
	 	if ($where != '') 
	 	{
	 		$sql .= ' WHERE ' . $where;
	 	}
	 	if ($order != '') 
	 	{
	 	 	$sql .= ' ORDER BY ' . $order;
	 	}
	 	if ($limit != '') 
	 	{
	 	 	$sql .= ' LIMIT ' . $limit;
	 	}
	 	//test
		//echo $sql . '<br />';		 		 	   	 
	 	$stmt = $this->db->query($sql);
	 	$stmt->setFetchMode(ASSOC);	 
	 	$a = 0;
        foreach ($stmt as $row)
        { 
         	foreach ($row as $key => $value) 
         	{
       	        $this->db_arr_row_cache_data[$name][$a][$key] = $value; 	 	
         	}
			$a++; 
		}	
		$stmt = NULL;	
		$this->db->close();
		$this->db_arr_row_cache_data[$name]['rows'] = $a; 
		$this->db_arr_row_cache_data[$name]['start_row'] = 0; 
		//Dobi::var_dump($this->db_arr_row_cache_data[$name]);
	}
	 
	public function rowCacheSQL( $name, $sql )
	{
	 	$stmt = $this->db->query($sql);	 
	 	$stmt->setFetchMode(ASSOC);	 
	 	$a = 0;
        foreach ($stmt as $row)
        { 
         	foreach ($row as $key => $value) 
         	{
       	        $this->db_arr_row_cache_data[$name][$a][$key] = $value; 	 	
         	}
			$a++; 
		}	
		$stmt = NULL;
		$this->db->close();	
		$this->db_arr_row_cache_data[$name]['rows'] = $a; 
		$this->db_arr_row_cache_data[$name]['start_row'] = 0;
	}
	  
	public function setName( $name )
	{
	 	$this->db_row_cache_name = $name;
	}	 
	 
	public function unsetName()
	{
	 	$this->db_row_cache_name = '';
	}
	  
	public function checkName( $name, $err = 'unknown' )
	{
	 	if ($name != '') 
	 	{
	 	 	return $name;
	 	}
	 	elseif ($name == '' && $this->db_row_cache_name != '')
	 	{
	 		return $this->db_row_cache_name;
	 	}
	 	else Dobi::exception('dobiExcDatabase', WARNING, _DOBI_DATABASE_ERR_2_ . $err);
	}
	 
	public function setStartRow( $name = '', $start )
	{
	 	$name = $this->checkName($name, 'setStartRow');
	 	if ($name == 'last')
	 	{
	 		$this->db_arr_row_cache_data[$name]['start_row'] = $this->db_arr_row_cache_data[$name]['rows'];
	 	}
	 	else $this->db_arr_row_cache_data[$name]['start_row'] = $start;
	}
	 
	public function getStartRow( $name = '' )
	{ 
	 	$name = $this->checkName($name, 'getStartRow');	 	
	    return $this->db_arr_row_cache_data[$name]['start_row'];	
	}	
	  
	public function rowExists( $name = '' )
	{
	 	$name = $this->checkName($name, 'rowExists');	 	
        if ($this->db_arr_row_cache_data[$name]['start_row'] < $this->db_arr_row_cache_data[$name]['rows'])
        {
        	return true;
        }
        return false;
	}	 
	 
	public function increment( $name = '' )
	{
	 	$name = $this->checkName($name, 'increment');		   	
	 	$this->db_arr_row_cache_data[$name]['start_row']++;	 	 
	}
	 
	public function decrement( $name = '' )
	{
	 	$name = $this->checkName($name, 'decrement');	 	
	 	$this->db_arr_row_cache_data[$name]['start_row']--;
	}	
	  
	public function getRow( $field, $name = '' )
	{ 
	 	$name = $this->checkName($name, 'getRow');	 	
	    return $this->db_arr_row_cache_data[$name][$this->db_arr_row_cache_data[$name]['start_row']][$field];	
	}
	
	public function getRowByID( $id, $field, $name = '' )
	{ 
	 	$name = $this->checkName($name, 'getRowbyID');	 	
	    return $this->db_arr_row_cache_data[$name][$id][$field];	
	}
	
	public function findRow( $key, $value, $name = '' )
	{
		$name = $this->checkName($name, 'findRow');
		foreach($this->db_arr_row_cache_data[$name] as $id => $arrID)
		{
			if (is_array($arrID))
			{
				foreach($arrID as $field => $field_value)
				{
					if ($field == $key && $value == $field_value)
					{
						return $id;
					}
				}
			}
		}
		return false;
	}
		 
	public function getRowsAmount( $name = '' )
	{
	 	$name = $this->checkName($name, 'getRowsAmount');	 	
	 	return $this->db_arr_row_cache_data[$name]['rows'];
	}

	public function clear( $name = '' )
	{ 
	 	$name = $this->checkName($name, 'clear');	
	 	$this->db_arr_row_cache_data[$name] = NULL; 
	 	$this->db_arr_group_by_data[$name] = NULL; 
	 	$this->db_row_cache_name = ''; 
	}
	 
	public function clearAll()
	{ 	
	 	$this->db_arr_row_cache_data = NULL; 
	 	$this->db_arr_group_by_data = NULL; 		 	
	 	$this->db_row_cache_name = ''; 
	}		 
}

?>