<?php
/**
 * This file handles the connection and actions for gtcWeekDay table
 *
 * @author Moises Heberle [moises@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 28/11/2008
 *
 * \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 to manipulate the basConfig table
 **/
class BusinessGnuteca3BusSearchPresentationFormat extends GnutecaBusiness
{
    public $searchFormatId;
    public $category;
    public $searchFormat;
    public $detailFormat;

    public $searchFormatIdS;
    public $categoryS;
    public $searchFormatS;
    public $detailFormatS;
    

    function __construct()
    {
        $table = 'gtcSearchPresentationFormat';
        $pkeys = 'searchFormatId,
                  category';
        $cols  = 'searchFormat,
                  detailFormat';
        parent::__construct($table, $pkeys, $cols);
    }


    /**
     * Insert a new record
     *
     * @return TRUE if succed, otherwise FALSE
     **/
    public function insertSearchPresentationFormat()
    {
    	if ($this->removeData)
    	{
    		$this->deleteSearchPresentationFormat($this->searchFormatId, $this->category);
    		return false;
    	}
    	if ($this->getSearchPresentationFormat($this->searchFormatId, $this->category))
    	{
    		return $this->updateSearchPresentationFormat();
    	}
        return $this->autoInsert();
    }


    /**
     * Update data from a specific record
     *
     * @return (boolean): TRUE if succeed, otherwise FALSE
     **/
    public function updateSearchPresentationFormat()
    {
        return $this->autoUpdate();
    }


    /**
     * Delete a record
     *
     * @param $formatBackOfBookId (integer)
     *
     * @return (boolean): TRUE if succeed, otherwise FALSE
     *
     **/
    public function deleteSearchPresentationFormat($searchFormatId, $category)
    {
        return $this->autoDelete($searchFormatId, $category);
    }


    /**
     * Return a specific record from the database
     *
     * @param $formatBackOfBookId (integer)
     *
     * @return (Object): Return an object of the type handled by the class
     **/
    public function getSearchPresentationFormat($searchFormatId, $category)
    {
        $this->clear();
        return $this->autoGet($searchFormatId, $category);
    }


    /**
     * Do a search on the database table handled by the class
     *
     * @param $object (bool): Case TRUE return as Object, otherwise Array
     *
     * @return (Array): An array containing the search results
     **/
    public function searchSearchPresentationFormat($object = false)
    {
        $this->clear();
        $filters = array(
            'searchFormatId' => 'equals',
            'category'       => 'equals',
            'searchFormat'   => 'ilike',
            'detailFormat'   => 'ilike'
        );
        return $this->autoSearch($filters, $object);
    }


    /**
     * List all records from the table handled by the class
     *
     * @param None
     *
     * @return (Array): Return an array with the entire table
     *
     **/
    public function listSearchPresentationFormat()
    {
        return $this->autoList();
    }
    
    
    public function deleteBySearchFormat($searchFormatId)
    {
    	$sql = new MSQL(null, $this->tables, 'searchFormatId = ?');
    	return $this->execute( $sql->delete(array($searchFormatId)) );
    }
}
?>
