/** * * @return type */ public function ultimoEncaminhamentoExterno($idDoc) { try { $obj = $this->manager->createQuery("SELECT e FROM ProtocoloBundle:Encaminhamentos e " . "JOIN e.documentosDocumento d " . "JOIN e.entradasExterna en " . "WHERE d.idDocumento = ?1 AND en.statusEntrada = false ORDER BY e.idEncaminhamento DESC ")->setParameter("1", $idDoc)->setMaxResults('1'); return $obj->getResult(); } catch (Exception $ex) { return null; } }
/** * * @param type $codigo * @return type */ public function searchDocTramitado($codigo) { try { $obj = $this->manager->createQuery("SELECT e FROM ProtocoloBundle:EntradasExterna e " . "JOIN e.encaminhamentos ec " . "JOIN ec.documentosDocumento d " . "WHERE d.codIndentificadorDocumento = :cod AND e.statusEntrada = false ")->setParameter("cod", $codigo); return $obj->getResult(); } catch (Exception $ex) { return null; } }
/** * * @param type $idSecretaria * @return boolean */ public function getSubsecretariaBySecretaria($idSecretaria) { try { $query = $this->manager->createQuery("SELECT s FROM ProtocoloBundle:Subsecretaria s " . "JOIN s.secretarias se " . "WHERE se.idSecretaria = :id ")->setParameter("id", $idSecretaria); return $result = $query->getArrayResult(); } catch (Exception $ex) { return false; } }
/** * * @return type */ public function findByProPendentes() { try { $obj = $this->manager->createQuery("SELECT e FROM ProtocoloBundle:Entradas e " . "JOIN e.usuarios u " . "WHERE e.statusEnvio = false AND e.statusEntrada = true AND e.statusPendencia = true "); return $obj->getResult(); } catch (Exception $ex) { return null; } }
/** * */ public function builderQuery() { try { $dqlWhere = " "; if (!empty($this->whereValueMain)) { $dqlWhere .= " WHERE {$this->columnWhereMain} = {$this->whereValueMain}"; } else { //$dqlWhere .= " WHERE "; } if (!empty($this->whereFull)) { $dqlWhere .= " WHERE {$this->whereFull}"; } $whereGlobal = false; $wherePerson = false; $filterValue = array(); $filterKey = array(); $dqlStart = $this->start; $dqlLength = $this->length; $dqlColumn = $this->columns; $dqlFilter = $this->filter($this->parametros, $dqlColumn); if (count($dqlFilter) > 0) { $this->filterBool = true; } $dqlOrder = $this->order($this->parametros, $dqlColumn); $letras = array('b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'); $entityJoin = $this->entityJOIN; $sqlJoin = ""; //$entityJoinMain = $this->entityJOINWhereMain; for ($i = 0; $i < count($entityJoin); $i++) { $verifyJoin = explode(".", $entityJoin[$i]); $verifyLeft = explode(":", $entityJoin[$i]); if (count($verifyLeft) == 2) { $sqlJoin .= " LEFT JOIN {$verifyLeft[0]} {$letras[$i]} "; } else { if (count($verifyJoin) == 2) { $sqlJoin .= " JOIN {$entityJoin[$i]} {$letras[$i]} "; } else { $sqlJoin .= " JOIN a.{$entityJoin[$i]} {$letras[$i]} "; } } } if (!empty($dqlFilter)) { if (!empty($this->whereValueMain) || !empty($this->whereFull)) { $dqlWhere .= " AND ("; } else { $dqlWhere .= " WHERE ("; } if (is_array($dqlFilter)) { $wherePerson = true; $filterKey = array_keys($dqlFilter); $filterValue = array_values($dqlFilter); for ($i = 0; $i < count($filterKey); $i++) { $index = $i + 1; $dqlWhere .= " {$filterKey[$i]} LIKE ?{$index} AND "; } } else { $whereGlobal = true; foreach ($dqlColumn as $valor) { $dqlWhere .= " {$valor} LIKE ?1 OR "; } } $dqlWhere = substr($dqlWhere, 0, -4) . ")"; } $query = $this->em->createQuery("SELECT distinct a FROM {$this->entity} a" . " {$sqlJoin} " . " {$dqlWhere} " . "ORDER BY {$dqlOrder}")->setFirstResult($dqlStart)->setMaxResults($dqlLength); if ($whereGlobal) { $query->setParameter(1, strtoupper("%{$dqlFilter}%")); } else { if ($wherePerson) { for ($i = 0; $i < count($filterValue); $i++) { $index = $i + 1; $query->setParameter($index, strtoupper("%{$filterValue[$i]}%")); } } } //var_dump($query); exit(); $result = $query->getResult(); //var_dump($result); exit(); return $result; } catch (Exception $ex) { print_r($ex); } }