<?php
/**
 * LoanBetweenLibraryStatus business
 *
 * @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 16/12/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 BusinessGnuteca3BusLoanBetweenLibraryStatus extends GnutecaBusiness
{
    public $loanBetweenLibraryStatusId;
    

    public function __construct()
    {
        $table = 'gtcLoanBetweenLibraryStatus';
        $pkeys = 'loanBetweenLibraryStatusId';
        $cols  = 'description';
        parent::__construct($table, $pkeys, $cols);
    }


    public function insertLoanBetweenLibraryStatus()
    {
        return $this->autoInsert();
    }

    
    public function updateLoanBetweenLibraryStatus()
    {
        return $this->autoUpdate();
    }


    public function deleteLoanBetweenLibraryStatus($loanBetweenLibraryStatusId)
    {
        return $this->autoDelete($loanBetweenLibraryStatusId);
    }


    public function getLoanBetweenLibraryStatus($loanBetweenLibraryStatusId)
    {
        $this->clear();
        return $this->autoGet($loanBetweenLibraryStatusId);       
    }


    public function searchLoanBetweenLibraryStatus($object = false)
    {
        $this->clear();
        $filters = array(
            'loanBetweenLibraryId'  => 'equals',
            'description'           => 'ilike',
        );
        return $this->autoSearch($filters, $object);
    }


    public function listLoanBetweenLibraryStatus($filterPossiblesStatus = false)
    {
        //return $this->autoList();
        parent::clear();
        parent::setColumns('loanBetweenLibraryStatusId, description');
        parent::setTables('gtcLoanBetweenLibraryStatus');

        switch ($filterPossiblesStatus)
        {
            // SOLICITADO = pode cancelar, aprovar ou reprovar
            case 1 :
                parent::setWhere("loanBetweenLibraryStatusId IN (1, 2, 3, 4)");
                break;

            // CANCELADO = não pode mais trocar de estado
            case 2:
                parent::setWhere("loanBetweenLibraryStatusId IN (2)");
                break;

            // APROVADO = prode confirmar
            case 3:
                parent::setWhere("loanBetweenLibraryStatusId IN (3,5)");
                break;

            // REPROVADO = não pode mais trocar de estado
            case 4:
                parent::setWhere("loanBetweenLibraryStatusId IN (4)");
                break;

            // CONFIRMADO = pode devolver
            case 5:
                parent::setWhere("loanBetweenLibraryStatusId IN (5,6)");
                break;

            // DEVOLVIDO = não pode mais trocar de estado
            case 6:
                parent::setWhere("loanBetweenLibraryStatusId IN (6,7)");
                break;
                
            // FINALIZADO = não pode mais trocar de estado
            case 7:
                parent::setWhere("loanBetweenLibraryStatusId IN (7)");
                break;                

            default: break;
        }

        $sql = parent::select();
        $rs  = parent::query();

        $out = array();
        if ($rs)
        {
            foreach ($rs as $v)
            {
                list($id, $value) = $v;
                $out[ $id ] = $value;
            }
        }

        return $out;         
    }
}
?>
