<?php

class Sinistro_TipoliquidacaoController extends Agro_Controller_Action {	
	public function init() {
		$this->view->title = 'Sistema » Cadastro » Tipo liquidação';
	}
	
	public function setBack() {
		$this->view->back = '/sistema/tipoliquidacao';
	}
	
	public function getModel() {
		return new Sinistro_Model_TipoLiquidacao();
	}
	
	public function getForm() {
		return new Sinistro_Form_TipoLiquidacao();
	}
	
	public function getFilter() {
		$where = array();
		
		if ($this->getRequest()->getParam('ds_nome_tipo_liquidacao')) {
			$where[] = array (
				'field' => 'ds_nome_tipo_liquidacao',
				'operator' => 'ilike',
				'value' => '%'.$this->getRequest()->getParam('ds_nome_tipo_liquidacao').'%'
			);
		}
		
		if ($this->getRequest()->getParam('ds_chave')) {
			$where[] = array (
				'field' => 'ds_chave',
				'operator' => 'ilike',
				'value' => '%'.$this->getRequest()->getParam('ds_chave').'%'
			);
		}
				
		if ($this->getRequest()->getParam('fl_ativo')) {
			$where[] = array (
				'field' => 'fl_ativo',
				'operator' => ' = ',
				'value' => $this->getRequest()->getParam('fl_ativo')
			);
		}		
		
		return $where;
	}
	
	public function showAction(){
		$this->getHelper('layout')->disableLayout();
		
		$Model = $this->getModel();
		
		try {
			$Row = $Model->find($this->getRequest()->getParam("id"))->current();
			if ($Row){
				$this->view->params = $Row->toArray();	
			} else {
				$this->view->params = false;
			}
			
		} catch (Exception $e) {
			$this->view->params = false;
		}
	}
}