예제 #1
0
 public function editarAction()
 {
     $this->autenticacao();
     $this->view->title = $this->t->_('Edit schedule');
     $this->_helper->viewRenderer->setRender('salvar');
     $form = new Admin_Form_Horarios();
     $this->view->form = $form;
     $model = new Application_Model_EventoRealizacao();
     $evento = $this->_request->getParam('evento', 0);
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         if ($form->isValid($formData)) {
             $id = $this->_request->getParam('id', 0);
             $data = $form->getValues();
             try {
                 $cache = Zend_Registry::get('cache_common');
                 $ps = $cache->load('prefsis');
                 $idEncontro = (int) $ps->encontro["id_encontro"];
                 $existe = $model->existeHorario(array($idEncontro, $data['id_sala'], $data['data'], $data['hora_inicio'], $data['hora_fim']));
                 // se id for igual ao id existe, pode atualizar, pois se trata do mesmo evento
                 if (!$existe or $id == $existe) {
                     $data['data'] = new Zend_Db_Expr($model->getAdapter()->quoteInto("TO_DATE(?, 'DD/MM/YYYY')", $data['data']));
                     $model->update($data, 'evento = ' . $id);
                     $this->_helper->flashMessenger->addMessage(array('success' => 'Horário atualizado com sucesso.'));
                     return $this->_helper->redirector->goToRoute(array('module' => 'admin', 'controller' => 'evento', 'action' => 'detalhes', 'id' => $evento), 'default', true);
                 } else {
                     $this->_helper->flashMessenger->addMessage(array('danger' => 'Já existe um evento no mesmo dia, mesma sala e mesmo horário.'));
                 }
             } catch (Exception $e) {
                 $this->_helper->flashMessenger->addMessage(array('danger' => 'Ocorreu um erro inesperado.<br/>Detalhes: ' . $e->getMessage()));
             }
         } else {
             $form->populate($formData);
         }
     } else {
         $id = $this->_getParam('id', 0);
         if ($id > 0) {
             $form->populate($model->getAdapter()->fetchRow("SELECT evento, id_evento,\n                  id_sala, TO_CHAR(data, 'DD/MM/YYYY') as data,\n                  TO_CHAR(hora_inicio, 'HH24:MI') as hora_inicio,\n                  TO_CHAR(hora_fim, 'HH24:MI') as hora_fim, descricao\n               FROM evento_realizacao WHERE evento = " . $id));
         }
     }
     $select = "SELECT TO_CHAR(data, 'DD/MM/YYYY') as data,\n             TO_CHAR(hora_inicio, 'HH24:MI') as hora_inicio,\n             TO_CHAR(hora_fim, 'HH24:MI') as hora_fim, descricao FROM evento_realizacao\n             WHERE id_evento = ? ORDER BY data ASC, hora_inicio ASC";
     $this->view->idEvento = $evento;
     $this->view->horariosEventos = $model->getAdapter()->fetchAll($select, $evento);
 }
예제 #2
0
 public function interesseAction()
 {
     $this->autenticacao();
     $sessao = Zend_Auth::getInstance()->getIdentity();
     $cache = Zend_Registry::get('cache_common');
     $ps = $cache->load('prefsis');
     $idEncontro = (int) $ps->encontro["id_encontro"];
     $idPessoa = $sessao["idPessoa"];
     $eventos = new Application_Model_Evento();
     // usada para mostrar dias que possuem eventos
     $this->view->diasEncontro = $eventos->listarDiasDoEncontro($idEncontro);
     $this->view->idEncontro = $idEncontro;
     $this->view->idPessoa = $idPessoa;
     $tipoEventos = new Application_Model_TipoEvento();
     $this->view->tipoEvento = $tipoEventos->fetchAll();
     $model = new Application_Model_EventoRealizacao();
     $eventoRealizacao = $model->fetchAll();
     // TODO: refezer este trecho usando join ao invés de findDependentRowset
     $this->view->eventosTabela = array();
     foreach ($eventoRealizacao as $item) {
         $eventoItem = $item->findDependentRowset('Application_Model_Evento')->current();
         $tipoItem = $eventoItem->findDependentRowset('Application_Model_TipoEvento')->current();
         $this->view->eventosTabela[] = array_merge($item->toArray(), $eventoItem->toArray(), $tipoItem->toArray());
     }
 }