<?php

class Sistema_ModelopreviagruposController extends Agro_Controller_Action {
	//public $_columnList = array(
		//'ds_nome_grupo' => 'Nome'
	//);
	
	public function init() {
		$this->getHelper('layout')->disableLayout();
		
		$this->view->title = 'Vincular Grupos de Atributos';
	}

	public function getModel() {
		return new Sistema_Model_ModeloPreviaGrupos();
	}
	
	public function getForm() {
		$Form = new Sistema_Form_ModeloPreviaGrupos();
		$Form->populate($this->getRequest()->getParams());
		return $Form;
	}
	
	public function saveAction() {
		$this->getHelper('ViewRenderer')->setNoRender();
		
		$Model = $this->getModel();
		
		if ($this->getForm()->isValid($this->getRequest()->getParams())){
			if ($Model->save($this->getRequest()->getParams())) {
				$this->getResponse()->setBody('Processo realizado com sucesso.');
			} else {
				$this->getResponse()->setBody('Não foi possível realizar o processo.');
			}
			
		}else {
			// TO-DO: Descobrir como fazer isso direito... :)  Vinicius Berni - 18/05/2010
			$this->getResponse()->setBody('Todos os campos são de preenchimento obrigatório');
		}
			
	}
	
	public function deleteAction() {
		$this->getHelper('ViewRenderer')->setNoRender();
		$Model = $this->getModel();
		
		if ($Model->delete($this->getRequest()->getParam('id'))) {
			$this->getResponse()->setBody('Processo realizado com sucesso.');
		} else {
			$this->getResponse()->setBody('Não foi possível realizar o processo.');
		}
	}
	
	
	
	public function getFilter() {
		$session = new Zend_Session_Namespace('id_modelos_laudos_previas');
		$where = array();
		
		if ($this->getRequest()->getParam('id_modelos_laudos_previas')) {
			$where[] = array(
				'field' => 'id_modelos_laudos_previas',
				'operator' => '=',
				'value' => $this->getRequest()->getParam('id_modelos_laudos_previas')
			);
		}
		
		return $where;
	}
	
	public function ordenaAction() {
		$this->getHelper('ViewRenderer')->setNoRender();
		$this->getHelper('layout')->disableLayout();
		$Model = $this->getModel();
		
		$this->getResponse()->setBody($Model->reOrder($this->getRequest()->getParam('id'), $this->getRequest()->getParam('order')));
	}

}