<?php
/**
 * LoanBetweenLibraryComposition 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 BusinessGnuteca3BusLoanBetweenLibraryComposition extends GnutecaBusiness
{
    public $loanBetweenLibraryId;
    public $itemNumber;
    public $isConfirmed;
    public $removeData;



    /**
     * Enter description here...
     *
     */
    public function __construct()
    {
        $table = 'gtcLoanBetweenLibraryComposition';
        $pkeys = 'loanBetweenLibraryId,
                  itemNumber';
        $cols  = 'isConfirmed';
        parent::__construct($table, $pkeys, $cols);
    }



    /**
     * Enter description here...
     *
     * @return unknown
     */
    public function insertLoanBetweenLibraryComposition()
    {
    	if ($this->removeData)
    	{
    		$this->deleteLoanBetweenLibraryComposition($this->loanBetweenLibraryId, $this->itemNumber);
    		return true;
    	}
        return $this->autoInsert();
    }



    /**
     * Enter description here...
     *
     * @return unknown
     */
    public function updateLoanBetweenLibraryComposition()
    {
        return $this->autoUpdate();
    }



    /**
     * Enter description here...
     *
     * @param unknown_type $loanBetweenLibraryId
     * @param unknown_type $itemNumber
     * @return unknown
     */
    public function deleteLoanBetweenLibraryComposition($loanBetweenLibraryId, $itemNumber = null)
    {
    	$this->clear();
        $this->setWhere('loanBetweenLibraryId = ?');
        $args[] = $loanBetweenLibraryId;
        if ($itemNumber)
        {
        	$this->setWhere('itemNumber = ?');
        	$args[] = $itemNumber;
        }
        $this->setTables($this->tables);
        return $this->execute( $this->delete($args) );
    }



    /**
     * Enter description here...
     *
     * @param unknown_type $loanBetweenLibraryId
     * @return unknown
     */
    public function getLoanBetweenLibraryComposition($loanBetweenLibraryId)
    {
        $this->clear();
        return $this->autoGet($loanBetweenLibraryId);
    }



    /**
     * Enter description here...
     *
     * @param unknown_type $object
     * @return unknown
     */
    public function searchLoanBetweenLibraryComposition($object = false)
    {
        $this->clear();
        $filters = array(
            'loanBetweenLibraryId'  => 'equals',
            'itemNumber'            => 'equals',
            'isConfirmed'           => 'equals',
        );
        return $this->autoSearch($filters, $object);
    }



    /**
     * Enter description here...
     *
     * @return unknown
     */
    public function listLoanBetweenLibraryComposition()
    {
        return $this->autoList();
    }



    /**
     * Enter description here...
     *
     * @param unknown_type $loanBetweenLibraryId
     * @return unknown
     */
    public function getComposition($loanBetweenLibraryId, $libraryUnitId = null)
    {
        settype($loanBetweenLibraryId, "integer");

        $this->clear();
        $this->setColumns   ("a.loanBetweenLibraryId, a.itemNumber, a.isConfirmed, b.libraryUnitId");
        $this->setTables    ("gtcloanbetweenlibrarycomposition a inner join gtcexemplarycontrol b using(itemnumber)");
        $this->setWhere     ("a.loanbetweenlibraryid = ?");

        if($libraryUnitId)
        {
            $this->setWhere("b.originalLibraryUnitId = '$libraryUnitId'");
        }

        $sql = $this->select(array($loanBetweenLibraryId));

        return $this->query ($sql, true);
    }


        /**
     * Enter description here...
     *
     * @param unknown_type $loanBetweenLibraryId
     * @return unknown
     */
    public function getCompositionExemplaryStatus($loanBetweenLibraryId)
    {
        settype($loanBetweenLibraryId, "integer");

        $this->clear();
        $this->setColumns   ("a.itemNumber, a.isConfirmed, D.libraryname, C.description");
        $this->setTables    ("gtcloanbetweenlibrarycomposition A INNER JOIN gtcexemplarycontrol B USING(itemnumber) INNER JOIN gtcExemplaryStatus C USING(exemplaryStatusId) LEFT JOIN gtcLibraryUnit D ON (B.originallibraryunitid = D.libraryUnitId)");
        $this->setWhere     ("a.loanbetweenlibraryid = ?");
        $sql = $this->select(array($loanBetweenLibraryId));

        return $this->query ($sql, true);
    }
}
?>
