<?php

class Atendimento_PendenciaController extends Agro_Controller_Action {
	/*public $_columnList = array(
		'ds_nome_pendencia' => 'Pendência',
		'ds_chave' => 'Chave'
	);*/
	
	public function getForm() {
		return new Atendimento_Form_Pendencia();
	}
	
	public function getModel() {
		return new Atendimento_Model_Pendencia();
	}
	
	public function init() {
		$this->view->title = 'Atendimento » Pendências';
	}
		
	public function getFilter() {
		$User = Zend_Auth::getInstance()->getIdentity();
		$where = array();
		
		if ($this->getRequest()->getParam('ds_chave')) {
			$where[] = array(
				'field' => 'ds_chave',
				'operator' => ' ilike ',
				'value' => '%' . $this->getRequest()->getParam('ds_chave') . '%'
			);
		}
		
		if ($this->getRequest()->getParam('ds_nome_pendencia')) {
			$where[] = array(
				'field' => 'ds_nome_pendencia',
				'operator' => ' ilike ',
				'value' => '%' . $this->getRequest()->getParam('ds_nome_pendencia') . '%'
			);
		}
		
		if ($this->getRequest()->getParam('id_tipo_pendencia')) {
			$where[] = array(
				'field' => 'id_tipo_pendencia',
				'operator' => ' = ',
				'value' => $this->getRequest()->getParam('id_tipo_pendencia')
			);
		}
		
		if ($this->getRequest()->getParam('fl_ativo')) {
			$where[] = array(
				'field' => 'fl_ativo',
				'operator' => ' = ',
				'value' => $this->getRequest()->getParam('fl_ativo')
			);
		}

		return $where;
	}

    public function getpendenciasAction() {
        $this->isAjax();
        $this->getResponse()->setBody(Zend_Json::encode(
            (new Atendimento_Model_Pendencia())->getComboPendenciasByTipo(
                $this->getRequest()->getParam('id_tipo_pendencia'),
                true
            )
        ));
    }	
}