<?php

class Sistema_StatusController extends Agro_Controller_Action
{
	public $_columnList = array(
		'cd_status' => array('label'=>'Código', 'align'=>'center'),
		'ds_status' => 'Status',
		'ds_chave' => 'Chave',
		'ds_tipo_status' => 'Tipo'
	);

	public function init() {
		$this->view->title = 'Sistema » Configurações » Status';
	}

	public function setBack() {
		$this->view->back = '/sistema/status';
	}

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

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

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

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

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

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

		return $where;
	}

	public function getjsonAction(){
		$this->getHelper('ViewRenderer')->setNoRender();
		$this->getHelper('layout')->disableLayout();
		
		$params = $this->getRequest()->getParams();
		$Model = $this->getModel();

		$this->getResponse()->setBody(Zend_Json::encode($Model->getId($params["chave"], $params["grupo"])));
	}
}
