<?php

class Sistema_ModelopreviagruposatributosController extends Agro_Controller_Action {
	public function init() {
		$this->getHelper('layout')->disableLayout();
		
		$this->view->title = 'Vincular Grupos de Atributos';
	}

	public function getModel() {
		return new Sistema_Model_ModeloPreviaGruposAtributos();
	}
	
	public function getForm() {
		$Form = new Sistema_Form_ModeloPreviaGruposAtributos();
		$Form->populate($this->getRequest()->getParams());
		return $Form;
	}
	
	public function saveAction() {
		$this->getHelper('ViewRenderer')->setNoRender();
		
		$Model = $this->getModel();
		
		$params = $this->getRequest()->getParams();
		
		if ($params['id_atributo_rn'] > 0){
			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('O preenchimento do campo "Atributos" é 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.');
			return true;
		} else {
			//$this->getResponse()->setBody('Não foi possível realizar o processo.');
			return false;
		}
	}
	
	public function getFilter() {
		$session = new Zend_Session_Namespace('id_modelos_laudos_previas_grupos');
		$where = array();
		
		if ($this->getRequest()->getParam('id_modelos_laudos_previas_grupos')) {
			$where[] = array(
				'field' => 'id_modelos_laudos_previas_grupos',
				'operator' => '=',
				'value' => $this->getRequest()->getParam('id_modelos_laudos_previas_grupos')
			);
		}
		
		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')));
	}

}