<?php

class Sinistro_Model_CobrancaRelatorioArquivos extends Agro_Db_Table_Abstract {
	protected $_schema = 'sinistro';
	protected $_name = 'cobranca_relatorio_arquivos';
	protected $_primary = 'id';
	
	public function save($dados) {
		$Row = $this->createRow();
		
		$Row->ds_nome_arquivo = $dados['ds_nome_arquivo'];
		$Row->id_cobranca_relatorio = $dados['id'];

		return $Row->save();
	}
	
	public function getCobrancaArquivos($idRelatorio) {
		$select = $this->select();
		$select->setIntegrityCheck(false);
		$select->from(array('cra'=>'sinistro.cobranca_relatorio_arquivos'),'*');
		$select->where('cra.id_cobranca_relatorio = ?',$idRelatorio);

		return $this->fetchAll($select)->toArray();
	}
	
	public function delete($id) {
		$Row = $this->find($id)->current();
		
		if (Agro_File::delete('cobranca', $Row->ds_nome_arquivo)) {
			parent::delete($id);
			return true;
		}
		
		return false;
	}	

}