Skip to content

Commit

Permalink
Mais fixes de perfil e acontecimentos
Browse files Browse the repository at this point in the history
  • Loading branch information
guaycuru committed Jun 1, 2017
1 parent 86905a0 commit 7df5db1
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions classes/GDE/Acontecimento.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,14 @@ public static function Listar(Usuario $Usuario = null, $limit = '-1', $start = '
$AcontecimentoMetaData = self::_EM()->getClassMetadata('GDE\Acontecimento');
if($maior_que)
$qrsr[] = "(R.`id_acontecimento` > :maior_que)";
$qrsr = (count($qrsr) > 0) ? " WHERE ".implode(" AND ", $qrsr) : "";
$qrsr = (count($qrsr) > 0) ? " AND ".implode(" AND ", $qrsr) : "";
$qrd = "O.`id_destino` = :id_usuario OR O.`id_destino` IS NULL";
$maior = ($maior_que) ? " AND O.`id_acontecimento` > '".intval($maior_que)."'" : "";
$originais = "(SELECT O.*, O.`id_acontecimento` AS `ordem` FROM " . $AcontecimentoMetaData->getTableName() . " AS O WHERE O.`id_original` IS NULL ".$maior." AND (".$qrd.") AND (".$qrs.") ORDER BY `ordem` DESC)";
$respostas = "(SELECT O.*, MAX(R.`id_acontecimento`) AS `ordem` FROM " . $AcontecimentoMetaData->getTableName() . " AS R INNER JOIN " . $AcontecimentoMetaData->getTableName() . " AS O ON (O.`id_acontecimento` = R.`id_original` AND (".$qrs.")) ".$qrsr." GROUP BY R.`id_original` ORDER BY `ordem` DESC)";
$respostas = "(SELECT O.*, MAX(R.`id_acontecimento`) AS `ordem` FROM " . $AcontecimentoMetaData->getTableName() . " AS R INNER JOIN " . $AcontecimentoMetaData->getTableName() . " AS O ON (O.`id_acontecimento` = R.`id_original` AND (".$qrs.")) WHERE R.`id_original` IS NOT NULL ".$qrsr." GROUP BY R.`id_original` ORDER BY `ordem` DESC)";
// ToDo: Arrumar pra funcionar com MySQL Mode ONLY_FULL_GROUP_BY, precisa fazer UNION?
// 1055 Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'A.id_original' which is not functionally dependent on columns in GROUP BY clause;
$sql = "SELECT *, MAX(`ordem`) AS `ordem` FROM (".$originais." UNION ".$respostas.") AS A GROUP BY A.`id_acontecimento` ORDER BY ordem DESC LIMIT :limit OFFSET :offset";
$sql = "SELECT *, MAX(`ordem`) AS `ordem` FROM (".$originais." UNION ".$respostas.") AS A GROUP BY A.`id_acontecimento` ORDER BY `ordem` DESC LIMIT :limit OFFSET :offset";
//$sql = "SELECT O.* FROM " . $AcontecimentoMetaData->getTableName() . " AS O WHERE O.id_original IS NULL ".$maior." AND (".$qrd.") AND (".$qrs.") ORDER BY id_acontecimento DESC LIMIT ? OFFSET ?";

$rsm = new \Doctrine\ORM\Query\ResultSetMappingBuilder(self::_EM());
Expand Down
9 changes: 6 additions & 3 deletions classes/GDE/Usuario.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1075,12 +1075,15 @@ public function Amigo(Usuario $Usuario) { // Se eh um amigo atualmente
}

/**
* @param string|null $ordem
* @param bool $ordem_nome Ordernar por nome completo do amigo
* @return ArrayCollection|UsuarioAmigo[] Amizades ja autorizadas
*/
public function Amigos() { // Lista de amizades ja autorizadas
public function Amigos($ordem_nome = false) { // Lista de amizades ja autorizadas
$criteria = Criteria::create()->where(Criteria::expr()->eq("ativo", true));
return $this->getAmigos()->matching($criteria);
$Amigos = $this->getAmigos()->matching($criteria);
if($ordem_nome === true)
return UsuarioAmigo::Ordenar_Por_Nome($Amigos);
return $Amigos;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion views/amigos.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

$Quase_Amigos = $_Usuario->getQuase_Amigos();
$Autorizacoes = $_Usuario->getAmigos_Pendentes();
$Amigos = UsuarioAmigo::Ordenar_Por_Nome($_Usuario->Amigos());
$Amigos = $_Usuario->Amigos(true);

?>
<script type="text/javascript">
Expand Down
2 changes: 1 addition & 1 deletion views/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

require_once('../common/common.inc.php');

$Amigos = UsuarioAmigo::Ordenar_Por_Nome($_Usuario->Amigos(array('amigo' => 'ASC')));
$Amigos = $_Usuario->Amigos(true);
$Recomendacoes = $_Usuario->Amigos_Recomendacoes(2, 15);
$Autorizacoes = $_Usuario->getAmigos_Pendentes();

Expand Down
2 changes: 1 addition & 1 deletion views/perfil.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
$Usr = null;

if($Usr !== null) {
$Amigos = $Usr->getAmigos();
$Amigos = $Usr->Amigos(true);
$total_amigos = 0;
$Em_Comum = $_Usuario->Amigos_Em_Comum($Usr, $total_amigos);
$_sou_eu = ($Usr->getID() == $_Usuario->getID());
Expand Down

0 comments on commit 7df5db1

Please sign in to comment.