Ejemplo n.º 1
0
 public function ajax_update(Context $context)
 {
     $response = new JsonResponse();
     $unidade = $context->getUnidade();
     $filaService = new FilaService($this->em());
     if ($unidade) {
         $ids = $context->request()->get('ids');
         $ids = Arrays::valuesToInt(explode(',', $ids));
         if (count($ids)) {
             $response->data['total'] = 0;
             $servicos = $this->servicos($unidade, ' e.servico IN (' . implode(',', $ids) . ') ');
             $em = $context->database()->createEntityManager();
             if ($servicos) {
                 foreach ($servicos as $su) {
                     $rs = $filaService->filaServico($unidade, $su->getServico());
                     $total = count($rs);
                     // prevent overhead
                     if ($total) {
                         $fila = [];
                         foreach ($rs as $atendimento) {
                             $arr = $atendimento->jsonSerialize(true);
                             $fila[] = $arr;
                         }
                         $response->data['servicos'][$su->getServico()->getId()] = $fila;
                         ++$response->data['total'];
                     }
                 }
             }
             $response->success = true;
         }
     }
     return $response;
 }
Ejemplo n.º 2
0
 public function ajax_update(Context $context)
 {
     $response = new JsonResponse();
     $unidade = $context->getUnidade();
     if ($unidade) {
         $ids = $context->request()->get('ids');
         $ids = Arrays::valuesToInt(explode(',', $ids));
         $senhas = array();
         if (sizeof($ids)) {
             $dql = "\n                    SELECT \n                        s.id, COUNT(e) as total \n                    FROM \n                        Novosga\\Model\\Atendimento e\n                        JOIN e.servico s\n                    WHERE \n                        e.unidade = :unidade AND \n                        e.servico IN (:servicos)\n                ";
             // total senhas do servico (qualquer status)
             $rs = $this->em()->createQuery($dql . " GROUP BY s.id")->setParameter('unidade', $unidade)->setParameter('servicos', $ids)->getArrayResult();
             foreach ($rs as $r) {
                 $senhas[$r['id']] = array('total' => $r['total'], 'fila' => 0);
             }
             // total senhas esperando
             $rs = $this->em()->createQuery($dql . " AND e.status = :status GROUP BY s.id")->setParameter('unidade', $unidade)->setParameter('servicos', $ids)->setParameter('status', AtendimentoService::SENHA_EMITIDA)->getArrayResult();
             foreach ($rs as $r) {
                 $senhas[$r['id']]['fila'] = $r['total'];
             }
             $service = new AtendimentoService($this->em());
             $response->success = true;
             $response->data = array('ultima' => $service->ultimaSenhaUnidade($unidade), 'servicos' => $senhas);
         }
     }
     return $response;
 }
Ejemplo n.º 3
0
 public function save()
 {
     $filename = $this->filename();
     // verifica se será possível escrever a configuração no arquivo de configuracao
     if (file_exists($filename) && !is_writable($filename)) {
         throw new Exception(sprintf(_('Arquivo de configuação (%s) somente leitura'), $this->filename));
     }
     $arr = Arrays::toString($this->data);
     file_put_contents($filename, "<?php\nreturn {$arr};");
 }
Ejemplo n.º 4
0
 /**
  * Invoke a app hook.
  *
  * @param string $name
  * @param array  $args
  *
  * @return AppConfig
  */
 public function hook($name, $args)
 {
     $hook = \Novosga\Util\Arrays::value($this->hooks(), $name);
     if (is_callable($hook)) {
         if (!is_array($args)) {
             $args = [$args];
         }
         call_user_func_array($hook, $args);
     }
     return $this;
 }
Ejemplo n.º 5
0
 public function create(Context $context, array $config = array())
 {
     $type = Arrays::value($config, 'type');
     $providerConfig = Arrays::value($config, $type, array());
     $em = $context->database()->createEntityManager();
     switch ($type) {
         case 'ldap':
             return new LdapProvider($em, $providerConfig);
         default:
             return new DatabaseProvider($em, $providerConfig);
     }
 }
Ejemplo n.º 6
0
 public function init(array $config)
 {
     if (!empty($config)) {
         parent::init($config);
         $this->host = Arrays::value($config, 'host');
         $this->baseDn = Arrays::value($config, 'baseDn');
         $this->loginAttribute = Arrays::value($config, 'loginAttribute');
         $this->username = Arrays::value($config, 'username');
         $this->password = Arrays::value($config, 'password');
         $this->filter = Arrays::value($config, 'filter');
     }
 }
Ejemplo n.º 7
0
 public static function getValue($obj, $prop)
 {
     if (is_array($obj)) {
         return Arrays::value($obj, $prop, null);
     }
     if (is_object($obj)) {
         try {
             return self::getPropertyValue($obj, $prop);
         } catch (Exception $e) {
             try {
                 return self::invokeMethod($obj, 'get' . ucfirst($prop));
             } catch (Exception $e) {
                 try {
                     return self::invokeMethod($obj, "get_{$prop}");
                 } catch (Exception $e) {
                 }
             }
         }
     }
     throw new Exception("Cannot find value of {$prop} in object " . get_class($obj));
 }
Ejemplo n.º 8
0
 /**
  * Extra route configuration
  * @return array
  */
 public function routes()
 {
     return \Novosga\Util\Arrays::value($this->extra(), 'routes', array());
 }
Ejemplo n.º 9
0
 /**
  * Retorna os serviços habilitados na unidade informada. Descartando os serviços com ids informados no parâmetro exceto
  * @param Novosga\Context $context
  */
 public function servicos_unidade(Context $context)
 {
     $response = new JsonResponse(true);
     $id = (int) $context->request()->get('unidade');
     $exceto = $context->request()->get('exceto');
     $exceto = Arrays::valuesToInt(explode(',', $exceto));
     $exceto = join(',', $exceto);
     $service = new \Novosga\Service\ServicoService($this->em());
     $response->data = $service->servicosUnidade($id, "e.status = 1 AND s.id NOT IN ({$exceto})");
     return $response;
 }
Ejemplo n.º 10
0
 /**
  * Marca o atendimento como encerrado e codificado.
  *
  * @param Novosga\Context $context
  */
 public function codificar(Context $context)
 {
     $response = new JsonResponse(false);
     try {
         if (!$context->request()->isPost()) {
             throw new Exception(_('Somente via POST'));
         }
         $unidade = $context->getUnidade();
         if (!$unidade) {
             throw new Exception(_('Nenhum unidade escolhida'));
         }
         $usuario = $context->getUser();
         $atual = $this->atendimentoService->atendimentoAndamento($usuario->getId());
         if (!$atual) {
             throw new Exception(_('Nenhum atendimento em andamento'));
         }
         $servicos = $context->request()->post('servicos');
         $servicos = Arrays::valuesToInt(explode(',', $servicos));
         if (empty($servicos)) {
             throw new Exception(_('Nenhum serviço selecionado'));
         }
         $this->em()->beginTransaction();
         foreach ($servicos as $s) {
             $codificado = new \Novosga\Model\AtendimentoCodificado();
             $codificado->setAtendimento($atual);
             $codificado->setServico($this->em()->find('Novosga\\Model\\Servico', $s));
             $codificado->setPeso(1);
             $this->em()->persist($codificado);
         }
         // verifica se esta encerrando e redirecionando
         $redirecionar = $context->request()->post('redirecionar');
         if ($redirecionar) {
             $servico = $context->request()->post('novoServico');
             $redirecionado = $this->atendimentoService->redirecionar($atual, $usuario->getWrapped(), $unidade, $servico);
             if (!$redirecionado->getId()) {
                 throw new Exception(sprintf(_('Erro ao redirecionar atendimento %s para o serviço %s'), $atual->getId(), $servico));
             }
         }
         $response->success = $this->mudaStatusAtendimento($atual, AtendimentoService::ATENDIMENTO_ENCERRADO, AtendimentoService::ATENDIMENTO_ENCERRADO_CODIFICADO, 'dataFim');
         if (!$response->success) {
             throw new Exception(sprintf(_('Erro ao codificar o atendimento %s'), $atual->getId()));
         }
         $this->em()->commit();
         $this->em()->flush();
     } catch (Exception $e) {
         try {
             $this->em()->rollback();
         } catch (Exception $ex) {
         }
         $response->message = $e->getMessage();
     }
     return $response;
 }
Ejemplo n.º 11
0
 public function getParameter($key)
 {
     return Arrays::value($this->parameters, $key);
 }
Ejemplo n.º 12
0
 /**
  * Remove o Atendimento da posicao especifica da fila.
  *
  * @param int $i (index)
  *
  * @return bool
  */
 public function remove($i)
 {
     Arrays::removeKey($this->atendimentos, (int) $i);
 }
Ejemplo n.º 13
0
 /**
  * @return array
  */
 public function getScripts()
 {
     return Arrays::value($this->data, 'scripts', array());
 }
Ejemplo n.º 14
0
 public function save(Context $context)
 {
     $response = new JsonResponse();
     try {
         $id = (int) $context->request()->post('id');
         $type = $context->request()->post('type');
         $data = $context->request()->post('data');
         if (Arrays::contains(['js', 'css'], $type)) {
             throw new Exception(_('Tipo de recurso inválido'));
         }
         $modulo = $this->find($id);
         if (!$modulo) {
             throw new Exception(_('Módulo inválido'));
         }
         $filename = $type == 'css' ? '/public/css/style.css' : '/public/js/script.js';
         $filename = $modulo->getRealPath() . $filename;
         if (!is_writable($filename)) {
             throw new Exception(_('Permissão negada'));
         }
         file_put_contents($filename, $data);
         $response->success = true;
     } catch (Exception $e) {
         $response->success = false;
         $response->message = $e->getMessage();
     }
     return $response;
 }
Ejemplo n.º 15
0
 /**
  * Retorna o valor da chave guardada no cookie.
  *
  * @param String $key
  *
  * @return mixed
  */
 public function get($key)
 {
     return Arrays::value($_COOKIE, $key);
 }