<?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 04/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 BusinessGnuteca3BusFormatBackOfBook extends GnutecaBusiness
{
    public $formatBackOfBookId;
    public $description;
    public $format;
    public $internalFormat;

    public $formatBackOfBookIdS;
    public $descriptionS;
    public $formatS;
    public $internalFormatS;


    /**
     * Class constructor
     **/
    function __construct()
    {
        $table = 'gtcFormatBackOfBook';
        $pkeys = 'formatBackOfBookId';
        $cols  = 'description,
                  format,
                  internalFormat';
        parent::__construct($table, $pkeys, $cols);
    }


    /**
     * Insert a new record
     *
     * @return TRUE if succed, otherwise FALSE
     **/
    public function insertFormatBackOfBook()
    {
        return $this->autoInsert();
    }


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


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


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


    /**
     * 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 searchFormatBackOfBook($object = false)
    {
        $this->clear();
        $this->setColumns('formatBackOfBookId, description, format, internalFormat');
        $this->setTables('gtcFormatBackOfBook');
        if ( $this->formatBackOfBookIdS )
        {
            $this->setWhere('formatBackOfBookId = ?');
            $data[] = $this->formatBackOfBookIdS;
        }
        if ($this->descriptionS)
        {
            $this->descriptionS = str_replace(' ','%', $this->descriptionS);
            $this->setWhere('lower(description) LIKE lower(?)');
            $data[] = '%' . strtolower($this->descriptionS) . '%';
        }
        if ($this->formatS)
        {
            $this->formatS = str_replace(' ','%', $this->formatS);
            $this->setWhere('lower(format) LIKE lower(?)');
            $data[] = '%' . strtolower($this->formatS) . '%';
        }
        if ($this->internalFormatS)
        {
            $this->internalFormatS = str_replace(' ','%', $this->internalFormatS);
            $this->setWhere('lower(internalFormat) LIKE lower(?)');
            $data[] = '%' . strtolower($this->internalFormatS) . '%';
        }
        $sql = $this->select($data);
        $rs  = $this->query($sql);
        return $rs;
        /*$this->clear();
        $filters = array(
            'formatBackOfBookId' => 'equals',
            'description'        => 'ilike',
            'format'             => 'ilike',
            'internalFormat'     => '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 listFormatBackOfBook()
    {
        return $this->autoList();
    }
}
?>
