<?php

class Sistema_CooperativaController extends Agro_Controller_Action
{
    public $_backAfterSave = 0;

    public function init()
    {
        $this->view->title = 'Sistema » Cadastros » Cooperativas';
    }

    public function getModel()
    {
        return new Sistema_Model_Cooperativas();
    }

    public function getForm()
    {
        return new Sistema_Form_Cooperativa();
    }

    public function getFilter()
    {
        $where = array();

        if ($this->getRequest()->getParam('cnpj')) {
            $where[] = array(
              'field'    => 'cnpj',
              'operator' => '=',
              'value'    => $this->getRequest()->getParam('cnpj')
            );
        }

        if ($this->getRequest()->getParam('ds_nome_cooperativa')) {
            $where[] = array(
              'field'    => 'ds_nome_cooperativa',
              'operator' => 'ilike',
              'value'    => "%{$this->getRequest()->getParam('ds_nome_cooperativa')}%"
            );
        }

        if ($this->getRequest()->getParam('id_estado')) {
            $where[] = array(
              'field'    => 'id_estado',
              'operator' => '=',
              'value'    => $this->getRequest()->getParam('id_estado')
            );
        }

        if ($this->getRequest()->getParam('id_municipio')) {
            $where[] = array(
              'field'    => 'id_municipio',
              'operator' => '=',
              'value'    => $this->getRequest()->getParam('id_municipio')
            );
        }

        return $where;
    }
}
