<?php
/**
 * ****************************************************************
 * Project:      *
 * Copyright:    Copyright (c) 2007
 * Company:      Thomas Niemann
 * ****************************************************************
 * Workfile:     BasicManager.php
 * ****************************************************************
 * Description:  
 *                
 * ***************************************************************/
class BasicManager
{
    protected $sql = null;
    protected $object = null;
    public function fillObjectDataList($_class, $_result)
    {
        $objArray = array();
        $resultCount = count($_result);
        if ($resultCount > 0) {
            foreach ($_result as $row) {
                array_push($objArray, $this->fillObjectData($_class, $row));
            }
        }
        return $objArray;
    }


    /*****************************************************************
    * fills object with data
    *****************************************************************/
    function fillObjectData($_class, $_data)
    {
        $object = new $_class();

        if ($_data == null) {
            $object = null;
        } else {
            $methods = get_class_methods($object);

            $keys = array_keys($_data);
            $numKeys = count($keys);
            for ($i = 0; $i < $numKeys; $i++) {
                $key = $keys[$i];
                $value = $_data[$key];

                $method = "set" . ucfirst($key);
                // method in object available and public?
                //				if (!in_array($method, $methods)) {
                //					// function not available or not public
                //					throw new Exception('Unknown method call '.$_class.'->'.$method);
                //				}

                // call the function
                call_user_func(array($object, $method), $value);
            }
        }
        return $object;
    }
}
?>