<?php

class Safra13_Model_LaudoPreviaFolhaResposta extends Agro_Db_Table_Abstract {
	protected $_schema = 'seguro';
	protected $_name = 'vistorias_previas_laudos_folhas_respostas';
	protected $_primary = 'id';
	public $_order = 'id';
	
	public function save($dados) {
		$Row = $this->createRow();
		
		$Row->id_atributo_rn = $dados['id_atributo_rn'];
		if($dados['ds_resposta'] == '|') {
			$dados['ds_resposta'] = '';
		}
		$Row->ds_resposta = $dados['ds_resposta'];
		$Row->id_vistoria_previa_laudo_folha = $dados['id_vistoria_previa_laudo_folha'];
		$Row->ds_label_pergunta = $dados['ds_label_pergunta'];
		
		return $Row->save();
	}
	
	public function getRespostas($id_folha) {
		$sql = "select
					*
				from
					seguro.vistorias_previas_laudos_folhas_respostas folha
				where
					id_vistoria_previa_laudo_folha = $id_folha
				order by
					id_atributo_rn";
		$Rs = $this->_db->fetchAll($sql);
		$arr = array();
		foreach($Rs as $linha) {
			if(!is_array($arr[$linha['id_atributo_rn']])) {
				$arr[$linha['id_atributo_rn']] = array();
			}
			$arr[$linha['id_atributo_rn']][] = $linha;
		}
		return $arr;
	}
}
