<?php

class Sistema_RoleController extends Agro_Controller_Action {
	public $_columnList = array(
		'ds_nome_role' => 'Nome'
	);
	
	public function init() {
		$this->view->title = 'Sistema » Configurações » Perfis';
	}
	
	public function setBack() {
		$this->view->back = '/sistema/role';
	}
	
	public function getModel() {
		return new Sistema_Model_Roles();
	}
	
	public function getForm() {
		return new Sistema_Form_Role();
	}
	
	public function getFilter() {
		$where = array();
		
		if ($this->getRequest()->getParam('ds_nome_role')) {
			$where[] = array(
				'field' => 'ds_nome_role',
				'operator' => 'ilike',
				'value' => '%'.$this->getRequest()->getParam('ds_nome_role').'%'
			);
		}
		
		if ($this->getRequest()->getParam('fl_ativo')) {
			$where[] = array(
				'field' => 'fl_ativo',
				'operator' => '=',
				'value' => $this->getRequest()->getParam('fl_ativo')
			);
		}
		
		return $where;
	}

	public function rolevistoriadorAction() {
		$this->isAjax();
		$Roles = $this->getModel();

		if (($this->getRequest()->getParam('tp_usuario') == 'V' || $this->getRequest()->getParam('tp_usuario') == 'M')) {
			$options = $Roles->getComboVistoriador();
		} elseif ($this->getRequest()->getParam('tp_usuario') == 'H') {
			$options = $Roles->getComboAuxiliar();
		} else {
			$options = $Roles->getCombo();
		}

		$opt = array();
		$opt[] = array('id'=>'','label'=>'');

		foreach ($options as $key => $val) {
			$opt[] = array('id' => $key, 'label' => $val);
		}

		$this->getResponse()->setBody(Zend_Json::encode($opt));		
	}
}
