/**
  * @return mixed
  */
 public function getTipoString()
 {
     return Administrativo_Model_TipoUsuario::getById($this->getTipo());
 }
 /**
  * Monta o formulário de cadastro de perfis
  *
  * @param string $sAction
  * @param null   $iId
  * @param array  $values
  * @return Twitter_Bootstrap_Form_Horizontal
  */
 private function formPerfil($sAction = 'novo', $iId = null, $values = array())
 {
     $oForm = new Twitter_Bootstrap_Form_Horizontal();
     $oBaseUrlHelper = new Zend_View_Helper_BaseUrl();
     if ($iId !== NULL) {
         $sAction .= "/id/{$iId}";
     }
     $oForm->setAction($oBaseUrlHelper->baseUrl('/administrativo/perfil/' . $sAction))->setMethod('post');
     if ($iId !== NULL) {
         $oElm = $oForm->createElement('hidden', 'id');
         $oElm->setValue($iId);
         $oForm->addElement($oElm);
     }
     $aTipos = Administrativo_Model_TipoUsuario::getLista();
     $oElm = $oForm->createElement('select', 'tipo', array('multiOptions' => $aTipos));
     $oElm->setLabel('Tipo:');
     $oElm->setAttrib('ajax-url', $oBaseUrlHelper->baseUrl('/administrativo/usuario/get-contadores'));
     $oElm->setRequired(TRUE);
     if (isset($values['tipo'])) {
         $oElm->setValue($values['tipo']);
     }
     $oForm->addElement($oElm);
     $oElm = $oForm->createElement('text', 'nome');
     $oElm->setLabel('Nome');
     $oElm->setRequired();
     if (isset($values['nome'])) {
         $oElm->setValue($values['nome']);
     }
     $oForm->addElement($oElm);
     $oElm = $oForm->createElement('select', 'administrativo', array('multiOptions' => array('1' => 'Sim', '0' => 'Não')));
     $oElm->setLabel('Administrativo');
     if (isset($values['administrativo']) and $values['administrativo'] == true) {
         $oElm->setValue('1');
     } else {
         $oElm->setValue('0');
     }
     $oForm->addElement($oElm);
     $oForm->addElement('submit', 'submit', array('label' => 'Salvar', 'buttonType' => Twitter_Bootstrap_Form_Element_Submit::BUTTON_SUCCESS));
     return $oForm;
 }
 /**
  * Renderiza o formulário
  *
  * @see Zend_Form::init()
  * @return Zend_form
  */
 public function init()
 {
     $oBaseUrlHelper = new Zend_View_Helper_BaseUrl();
     $this->setName('formCadastroUsuario');
     $this->setAction($oBaseUrlHelper->baseUrl('/administrativo/usuario'));
     $this->setMethod('post');
     $oElm = $this->createElement('hidden', 'id');
     $oElm->setValue(NULL);
     $this->addElement($oElm);
     $aTipos = Administrativo_Model_TipoUsuario::getLista();
     $oElm = $this->createElement('select', 'tipo', array('multiOptions' => $aTipos));
     $oElm->setLabel('Tipo:');
     $oElm->setAttrib('url-buscador', $oBaseUrlHelper->baseUrl('/administrativo/usuario/get-contadores'));
     $oElm->setRequired(TRUE);
     $this->addElement($oElm);
     $oElm = $this->createElement('hidden', 'cnpj');
     $this->addElement($oElm);
     $aContadores = Administrativo_Model_Contador::getAll();
     $aListaContadores = array();
     foreach ($aContadores as $oContador) {
         $sNome = utf8_encode($oContador->attr('nome'));
         $aListaContadores[$oContador->attr('cnpj')] = $sNome . ' - ' . $oContador->attr('cnpj');
     }
     $oElm = $this->createElement('select', 'contador', array('multiOptions' => $aListaContadores));
     $oElm->setLabel('Contador:');
     $this->addElement($oElm);
     $oElmBuscar = $this->createElement('button', 'buscador', array('label' => '', 'icon' => 'search', 'iconPosition' => Twitter_Bootstrap_Form_Element_Button::ICON_POSITION_LEFT));
     $oElm = $this->createElement('hidden', 'insc_municipal');
     $this->addElement($oElm);
     $oElm = $this->createElement('text', 'cnpj', array('append' => $oElmBuscar, 'class' => 'numerico', 'description' => '-'));
     $oElm->setAttrib('url-buscador', $oBaseUrlHelper->baseUrl('administrativo/usuario/get-contribuinte-cnpj'));
     $oElm->setLabel('CNPJ:');
     $this->addElement($oElm);
     $oElm = $this->createElement('text', 'login');
     $oElm->setLabel('Login:'******'errors');
     $oElm->setRequired(TRUE);
     $this->addElement($oElm);
     $oElm = $this->createElement('text', 'nome');
     $oElm->setLabel('Nome:');
     $oElm->setRequired(TRUE);
     $oElm->removeDecorator('errors');
     $this->addElement($oElm);
     $oElm = $this->createElement('text', 'email');
     $oElm->setLabel('Email:');
     $oElm->setRequired(TRUE);
     $oElm->removeDecorator('errors');
     $this->addElement($oElm);
     $oElm = $this->createElement('text', 'fone');
     $oElm->setLabel('Telefone:');
     $oElm->setAttrib('class', 'telefone');
     $oElm->setValidators(array(new Zend_Validate_Alnum(), new Zend_Validate_StringLength(array('max' => 13))));
     $this->addElement($oElm);
     $aPerfis = array();
     $oPerfilUsuario = $this->_view->user->getPerfil();
     if ($this->_view->user->getAdministrativo()) {
         $aDadosPerfis = Administrativo_Model_Perfil::getAll();
         foreach ($aDadosPerfis as $oPerfil) {
             $aPerfis[$oPerfil->getEntity()->getId()] = $oPerfil->getEntity()->getNome();
         }
     } else {
         $aDadosPerfis = $oPerfilUsuario->getPerfis();
         foreach ($aDadosPerfis as $oPerfil) {
             $aPerfis[$oPerfil->getId()] = $oPerfil->getNome();
         }
     }
     $oElm = $this->createElement('select', 'perfil', array('multiOptions' => $aPerfis));
     $oElm->removeDecorator('errors');
     $oElm->setLabel('Perfil:');
     $oElm->setRequired(TRUE);
     $this->addElement($oElm);
     $this->addElement('submit', 'submit', array('label' => 'Salvar', 'buttonType' => Twitter_Bootstrap_Form_Element_Submit::BUTTON_SUCCESS));
     return $this;
 }