<?php
/**
 *
 * @author Eduardo Bonfandini [eduardo@solis.coop.br]
 *
 * @version $Id$
 *
 * \b Maintainers \n
 * Eduardo Bonfandini   [eduardo@solis.coop.br]
 * Jamiel Spezia        [jamiel@solis.coop.br]
 * Luiz Gregory Filho   [luiz@solis.coop.br]
 * Moises Heberle       [moises@solis.coop.br]
 *
 * @since
 * Class created on 06/01/2009
 *
 * \b Organization: \n
 * SOLIS - Cooperativa de Solucoes Livres \n
 * The Gnuteca3 Development Team
 *
 * \b CopyLeft: \n
 * CopyLeft (L) 2008 SOLIS - Cooperativa de Solucoes Livres \n
 *
 * \b License: \n
 * Licensed under GPL (for further details read the COPYING file or http://www.gnu.org/copyleft/gpl.html )
 *
 * \b History: \n
 * See history in SVN repository: http://gnuteca.solis.coop.br
 */
class BusinessGnuteca3BusReportParameter extends GnutecaBusiness
{
	public $reportParameterId;
    public $reportId;
    public $label;
    public $identifier;
    public $type;
    public $defaultValue;
    public $options;
    public $lastValue;
    public $arrayItem;
    public $level;
    
    public $reportParameterIdS;
    public $reportIdS;
    public $labelS;
    public $identifierS;
    public $typeS;
    public $defaultValueS;
    public $optionsS;
    public $lastValueS;


    /**
     * Class constructor
     **/
    function __construct()
    {
        parent::__construct();
        $this->defineTables();
    }


    /**
    * Define or redefine the class atributes;
    */
    function defineTables()
    {
        $this->setTables('gtcReportParameter');
        $this->setId('reportParameterId');
        $this->setColumnsNoId('reportId, label, identifier, type, defaultValue, options, lastValue, level');
    }


    /**
     * List all records from the table handled by the class
     *
     * @param: None
     *
     * @returns (array): Return an array with the entire table
     *
     **/
    public function listReportParameter($object=FALSE)
    {
        $this->defineTables();
        return $this->autoList();
    }


    /**
     * Return a specific record from the database
     *
     * @param $moduleConfig (integer): Primary key of the record to be retrieved
     * @param $parameter (integer): Primary key of the record to be retrieved
     *
     * @return (object): Return an object of the type handled by the class
     *
     **/
    public function getReportParameter($id)
    {
        $this->defineTables();
        $this->clear;
        //here you can pass how many where you want
        return $this->autoGet($id);
    }


    /**
     * Do a search on the database table handled by the class
     *
     * @param $filters (object): Search filters
     *
     * @return (array): An array containing the search results
     **/
    public function searchReportParameter($toObject = false, $orderBy = 'level')
    {
        $this->defineTables();
        $this->clear();

        //here you can pass how many where you want, or use filters

        $filters  = array(
		                    'reportParameterId' => 'equals' ,
		                    'reportId'          => 'equals' ,
		                    'label'             => 'ilike'  ,
		                    'identifier'        => 'ilike'  ,
		                    'type'              => 'equals' ,
		                    'defaultValue'      => 'ilike'  , 
		                    'options'           => 'ilike'  ,
		                    'lastValue'         => 'ilike'  ,
                            'leve'              => 'equals'
                        );
        $this->setOrderBy($orderBy);
                        
        return $this->autoSearch($filters, $toObject);
    }


    /**
     * Insert a new record
     *
     * @param $data (object): An object of the type handled by the class
     *
     * @return True if succed, otherwise False
     *
     **/
    public function insertReportParameter()
    {
    	$this->level = $this->arrayItem;
    	if ( !$this->level )
    	{
    		$this->level = '0';
    	}
    	$this->defineTables();
        return $this->autoInsert();
    }


    /**
     * Update data from a specific record
     *
     * @param $data (object): Data which will replace the old record data
     *
     * @return (boolean): True if succeed, otherwise False
     *
     **/
    public function updateReportParameter()
    {
        $this->defineTables();
        return $this->autoUpdate();
    }


    /**
     * Delete a record
     *
     * @param $moduleConfig (string): Primary key for deletion
     * @param $parameter (string): Primary key for deletion
     *
     * @return (boolean): True if succeed, otherwise False
     *
     **/
    public function deleteReportParameter($id)
    {
        $this->defineTables();
        return $this->autoDelete($id);
    }
    
    public function deleteReportParameterByReport($reportId)
    {
    	$this->clear();
        $this->defineTables();
        $this->setWhere( 'reportId = ?');
        $sql = $this->delete( array($reportId) );
        $rs  = $this->execute($sql);
        return $rs;
    }
    
}
?>