<?php

class Atendimento_ContatotelefoneController extends Agro_Controller_Action {
	protected $_paginator = false;
	public $_columnList = array(
		'ds_endereco_rua' => 'Endereço',
		'ds_endereco_bairro' => 'Bairro',
		'fl_principal' => 'Principal'
	);
	
	public function init() {
		//$this->view->title = 'Gerência de Vistorias Prévias';
		$this->getHelper('layout')->disableLayout();
	}
	
	public function getForm() {
		$this->view->id_contato = $this->getRequest()->getParam('id_contato');
		$this->view->id = $this->getRequest()->getParam('id');
		
		return new Atendimento_Form_ContatoTelefone();		
	}
	
	public function getModel() {
		return new Atendimento_Model_ContatoTelefones();
	}
	
	public function saveAction() {
		$this->getHelper('ViewRenderer')->setNoRender();
		$this->getHelper('layout')->disableLayout();
		$result = array();
		
		$Model = $this->getModel();
		
		if ($Model->save($this->getRequest()->getParams())) {
			$result['id'] = $this->getRequest()->getParam('id_contato');
			$result['message'] = MSG_SUCCESS;
			$result['status'] = true;
		} else {
			$result['message'] = MSG_ERROR;
			$result['status'] = false;
		}

		$this->getResponse()->setBody(Zend_Json::encode($result));
	}
	
	public function getFilter() {
		$where = array();
		
		if ($this->getRequest()->getParam('id_contato')) {
			$where[] = array(
				'field' => 'id_contato',
				'operator' => '=',
				'value' => $this->getRequest()->getParam('id_contato')
			);
		}
		
		return $where;
	} 
}