<?php
/**
 * LoanBetweenLibraryStatusHistory 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 BusinessGnuteca3BusLoanBetweenLibraryStatusHistory extends GnutecaBusiness
{
    public $loanBetweenLibraryId;
    public $loanBetweenLibraryStatusId;
    public $date;
    public $operator;


    public function __construct()
    {
        $table = 'gtcLoanBetweenLibraryStatusHistory';
        $pkeys = 'loanBetweenLibraryId,
                  loanBetweenLibraryStatusId';
        $cols  = 'date,
                  operator';
        parent::__construct($table, $pkeys, $cols);
    }


    public function insertLoanBetweenLibraryStatusHistory()
    {
        $lastStatus = $this->getLastStatus($this->loanBetweenLibraryId);
        if ($lastStatus != $this->loanBetweenLibraryStatusId)
        {
            return $this->autoInsert();
        }
        return FALSE;
    }


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


    public function deleteLoanBetweenLibraryStatusHistory($loanBetweenLibraryId, $loanBetweenLibraryStatusId)
    {
        return $this->autoDelete($loanBetweenLibraryId, $loanBetweenLibraryStatusId);
    }


    public function getLoanBetweenLibraryStatusHistory($loanBetweenLibraryId, $loanBetweenLibraryStatusId)
    {
        $this->clear();
        return $this->autoGet($loanBetweenLibraryId, $loanBetweenLibraryStatusId);
    }


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


    public function listLoanBetweenLibraryStatusHistory()
    {
        return $this->autoList();
    }


    public function getLastStatus($loanBetweenLibraryId)
    {
        $msql = new MSQL('loanBetweenLibraryStatusId', $this->tables, 'loanBetweenLibraryId = ?', 'date DESC LIMIT 1');
        $sql  = $msql->select(array($loanBetweenLibraryId));
        $rs   = $this->query($sql);
        return $rs[0][0];
    }
}
?>