<?php
class Sistema_Model_VersaoZoneamento extends Agro_Db_Table_Abstract {
	protected $_schema = 'sistema';
	protected $_name = 'versao_zoneamento';
    protected $_primary = 'id';

    // Cria nova versão do zoneamento
    public function newVersionZoneamento($idSafra) {
        try {
            $user = Zend_Auth::getInstance()->getIdentity();
            $result = $this->fetchAll('fl_importado_zoneamento = TRUE AND fl_exportado_tablet = FALSE')->count();

            if ($result <= 0) {
                $Row = $this->createRow();
                $Row->id_usuario_criacao = $user->id;
                $Row->dt_criacao = date('Y-m-d H:i:s');
                $Row->fl_ativo = 'false';
                $Row->id_safra = $idSafra;
                $Row->fl_importado_zoneamento = 'true';
                $Row->fl_exportado_tablet = 'false';
                $Row->save();

	    }

            return true;
        } catch (Exception $e) {
            Agro_Util::zf_debug($e->getMessage());
            return false;
        }
    }
}
