Skip to content

Commit

Permalink
Varios fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
guaycuru committed May 21, 2017
1 parent c95264f commit 57796da
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 46 deletions.
31 changes: 10 additions & 21 deletions ajax/cardapios.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,28 @@
<?php

namespace GDE;

define('NO_CACHE', true);
define('NO_HTML', true);
define('NO_REDIRECT', true);

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

$data = strtotime($_GET['d']);

$ds = date('w', $data);

if($ds == 6)
$df = 2;
elseif($ds == 0)
$df = 1;
else
$df = 1 - $ds;

$data_inicial = date('Y-m-d', mktime(12, 0, 0, date('m', $data), date('d', $data)+$df));
$data_final = date('Y-m-d', mktime(12, 0, 0, date('m', $data), date('d', $data)+$df+4));
$data = (!empty($_GET['d'])) ? strtotime($_GET['d']) : time();

$cardapios = Carrega_Cardapios($data_inicial, $data_final);
$Cardapios = Cardapio::Cardapios_Semana($data);

?>
<table width="95%" align="center" border="1">
<?php

foreach($cardapios as $k => $cardapio) {
$d = $_GDE['DB']->UserDate($cardapio['data'], "w") + 1;
if($cardapio['tipo'] == 1)
echo "\r\n <tr>\r\n <td colspan=\"2\" align=\"center\"><strong>".$d."&ordf;-feira (".$_GDE['DB']->UserDate($cardapio['data'], "d/m/Y").")</strong></td>\r\n </tr><tr>\r\n <td align=\"center\"><strong>Almo&ccedil;o</strong></td>\r\n <td align=\"center\"><strong>Jantar</strong></td>\r\n </tr>\r\n <tr>";
echo "\r\n<td>".Formata_Cardapio($cardapio, false)."</td>";
if($cardapio['tipo'] == 2)
foreach($Cardapios as $k => $Cardapio) {
if($Cardapio->getTipo(false) == Cardapio::TIPO_ALMOCO)
echo "\r\n <tr>\r\n <td colspan=\"2\" align=\"center\"><strong>".$Cardapio->Dia_Da_Semana()." (".$Cardapio->getData("d/m/Y").")</strong></td>\r\n </tr><tr>\r\n <td align=\"center\"><strong>Almo&ccedil;o</strong></td>\r\n <td align=\"center\"><strong>Jantar</strong></td>\r\n </tr>\r\n <tr>";
echo "\r\n<td>".$Cardapio->Formatado(false)."</td>";
if($Cardapio->getTipo(false) == Cardapio::TIPO_JANTAR)
echo "\r\n </tr>";
}

?>
</table>
</table>
6 changes: 3 additions & 3 deletions classes/GDE/Acontecimento.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function getTexto($html = false, $processa = false, $meu = false, Usuario
// Amizade
if($this->getTipo() == 'ua')
return (!$meu)
? " agora &eacute; amig".$this->getOrigem()->getSexo(true, true)." de ".$_GDE['Usuario']->Apelido_Ou_Nome($this->getDestino(), true)."."
? " agora &eacute; amig".$this->getOrigem()->getSexo(true, true)." de ".$_Usuario->Apelido_Ou_Nome($this->getDestino(), false, true)."."
: " agora &eacute; ".(($this->getOrigem()->getSexo() == 'f')?'sua amiga':'seu amigo').".";
// Mensagem, Status de Usuario
elseif(($this->getTipo() == 'um') || ($this->getTipo() == 'us') || ($this->getTipo() == 'rs')) {
Expand All @@ -96,7 +96,7 @@ public function getTexto($html = false, $processa = false, $meu = false, Usuario
elseif($this->getTipo() == 'rs')
$texto_pre = "<span class=\"atualizacao_tipo\"> (an&uacute;ncio)</span>";
elseif(($this->getOriginal() !== null) && ($this->getDestino() !== null) && ($this->getDestino()->getID() != $Usuario->getID())) // Tinha um ($meu) && ali, mas acho q nao faz sentido
$texto_pre = " -> ".$_Usuario->Apelido_Ou_Nome($this->getDestino(), true);
$texto_pre = " -> ".$_Usuario->Apelido_Ou_Nome($this->getDestino(), false, true);
else
$texto_pre = "";
$texto_pre .= ": ";
Expand Down Expand Up @@ -124,7 +124,7 @@ public function getLink() {
public function getNome($completo = false) {
global $_Usuario;
if($this->getOrigem() !== null)
return ($completo) ? $this->getOrigem()->getNome_Completo(true) : $_Usuario->Apelido_Ou_Nome($this->getOrigem(), true);
return ($completo) ? $this->getOrigem()->getNome_Completo(true) : $_Usuario->Apelido_Ou_Nome($this->getOrigem(), false, true);
elseif($this->tipo == 'ga')
return "Atualiza&ccedil;&atilde;o do GDE";
else
Expand Down
58 changes: 56 additions & 2 deletions classes/GDE/Cardapio.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class Cardapio extends Base {
*/
protected $ultima_atualizacao;

/**
* @return Cardapio
*/
public static function Atual() {
$hora = date('H');
$dia = date('d');
Expand All @@ -114,6 +117,44 @@ public static function Atual() {
}
}

/**
* @param null $time
* @return Cardapio[]
*/
public static function Cardapios_Semana($time = null) {
if($time == null)
$time = time();
$ds = date('w', $time);

if($ds == 6)
$df = 2;
elseif($ds == 0)
$df = 1;
else
$df = 1 - $ds;

$inicio = mktime(12, 0, 0, date('m', $time), date('d', $time)+$df);
$fim = mktime(12, 0, 0, date('m', $time), date('d', $time)+$df+4);
return self::Cardapios_Por_Datas(\DateTime::createFromFormat('U', $inicio), \DateTime::createFromFormat('U', $fim));
}

/**
* @param \DateTime $inicio
* @param \DateTime $fim
* @return Cardapio[]
*/
public static function Cardapios_Por_Datas(\DateTime $inicio, \DateTime $fim) {
$inicio->setTime(0, 0, 0);
$fim->setTime(0, 0, 0);
$query = self::_EM()->createQuery("SELECT C FROM GDE\\Cardapio C WHERE C.data >= ?1 AND C.data <= ?2 ORDER BY C.data ASC");
$query->setParameter(1, $inicio);
$query->setParameter(2, $fim);
return $query->getResult();
}

/**
* @return int
*/
public static function Ultimo_ID() {
$dql = "SELECT MAX(C.id_cardapio) FROM GDE\\Cardapio C";
$query = self::_EM()->createQuery($dql);
Expand All @@ -124,26 +165,39 @@ public static function Ultimo_ID() {
}
}

/**
* @return bool|int
*/
public function ID_Anterior() {
if($this->getID() == null)
return false;
return ($this->getID() > 1) ? $this->getID() - 1 : false;
}

/**
* @return bool|int
*/
public function ID_Proximo() {
if($this->getID() == null)
return false;
return ($this->getID() < self::Ultimo_ID()) ? $this->getID() + 1 : false;
}

/**
* @param bool $cabecalho
* @return string
*/
public function Formatado($cabecalho = true) {
$ds = array('Domingo', 'Segunda-feira', 'Ter&ccedil;a-feira', 'Quarta-feira', 'Quinta-feira', 'Sexta-feira', 'S&aacute;bado');
return (($cabecalho)?"<strong>".(($this->getTipo(false) == self::TIPO_ALMOCO)?"ALMO&Ccedil;O":"JANTAR")."</strong> de <strong>".$ds[$this->getData('w')].", ".$this->getData("d/m/Y")."</strong>:<br />":null)."<strong>Prato Principal:</strong> ".$this->getPrincipal(true)."<br />".
return (($cabecalho)?"<strong>".(($this->getTipo(false) == self::TIPO_ALMOCO)?"ALMO&Ccedil;O":"JANTAR")."</strong> de <strong>".$this->Dia_Da_Semana().", ".$this->getData("d/m/Y")."</strong>:<br />":null)."<strong>Prato Principal:</strong> ".$this->getPrincipal(true)."<br />".
((!empty($this->getGuarnicao(false)))? "<strong>Guarni&ccedil;&atilde;o:</strong> ".$this->getGuarnicao(true)."<br />" : null).
((!empty($this->getPTS(false)))? "<strong>PTS:</strong> ".$this->getPTS(true)."<br />" : null).
"<strong>Salada:</strong> ".$this->getSalada(true)."<br />".
"<strong>Sobremesa:</strong> ".$this->getSobremesa(true)."<br />".
"<strong>Suco:</strong> ".$this->getSuco(true)."<br />".
((!empty($this->getVegetariano(false)))? "<strong>Vegetariano:</strong> ".$this->getVegetariano(true)."<br />" : null);
}

public function Dia_Da_Semana() {
return Util::Dia_Da_Semana($this->getData('w'));
}
}
10 changes: 6 additions & 4 deletions classes/GDE/Usuario.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,7 @@ public function Amigo(Usuario $Usuario) { // Se eh um amigo atualmente
}

/**
* @param string|null $ordem
* @return ArrayCollection|UsuarioAmigo[] Amizades ja autorizadas
*/
public function Amigos() { // Lista de amizades ja autorizadas
Expand Down Expand Up @@ -1177,15 +1178,16 @@ public function Autorizar_Amigo(Usuario $Usuario, $flush = true) {
* Apelido_Ou_Nome
*
* @param Usuario $Usuario
* @param bool|true $completo
* @param bool|true $html
* @return string
*/
public function Apelido_Ou_Nome(Usuario $Usuario, $html = true) {
public function Apelido_Ou_Nome(Usuario $Usuario, $completo = false, $html = true) {
$Amigo = $this->Amigo($Usuario);
if(($Amigo !== false) && ($Amigo->getApelido(false) != null))
return $Amigo->getApelido($html);
if($Amigo !== false)
return $Amigo->Apelido_Ou_Nome($completo, $html);
else
return $Usuario->getNome($html);
return ($completo) ? $Usuario->getNome_Completo($html) : $Usuario->getNome($html);
}

/**
Expand Down
28 changes: 22 additions & 6 deletions classes/GDE/UsuarioAmigo.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace GDE;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;

/**
Expand Down Expand Up @@ -29,19 +30,15 @@ class UsuarioAmigo extends Base {
* @var Usuario
*
* @ORM\ManyToOne(targetEntity="Usuario")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="id_amigo", referencedColumnName="id_usuario")
* })
* @ORM\JoinColumn(name="id_amigo", referencedColumnName="id_usuario")
*/
protected $amigo;

/**
* @var Usuario
*
* @ORM\ManyToOne(targetEntity="Usuario")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="id_usuario", referencedColumnName="id_usuario")
* })
* @ORM\JoinColumn(name="id_usuario", referencedColumnName="id_usuario")
*/
protected $usuario;

Expand All @@ -59,5 +56,24 @@ class UsuarioAmigo extends Base {
*/
protected $ativo = false;

/**
* @param bool $completo
* @param bool $html
* @return mixed
*/
public function Apelido_Ou_Nome($completo = false, $html = true) {
if($this->getApelido(false) != null)
return $this->getApelido($html);
else
return ($completo) ? $this->getAmigo(true)->getNome_Completo($html) : $this->getAmigo(true)->getNome($html);
}

public static function Ordenar_Por_Nome($Amigos) {
$iterator = $Amigos->getIterator();
$iterator->uasort(function ($A, $B) {
return strcmp($A->getAmigo()->getNome_Completo(false), $B->getAmigo()->getNome_Completo(false));
});
return new ArrayCollection(iterator_to_array($iterator));
}

}
6 changes: 6 additions & 0 deletions classes/GDE/Util.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,10 @@ public static function Validar_Email($email) {
return (preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i', $email) > 0);
}

public static function Dia_Da_Semana($d) {
if($d < 0 || $d > 6)
return '';
return array('Domingo', 'Segunda-feira', 'Ter&ccedil;a-feira', 'Quarta-feira', 'Quinta-feira', 'Sexta-feira', 'S&aacute;bado')[$d];
}

}
14 changes: 4 additions & 10 deletions 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 = $_Usuario->Amigos();
$Amigos = UsuarioAmigo::Ordenar_Por_Nome($_Usuario->Amigos(array('amigo' => 'ASC')));
$Recomendacoes = $_Usuario->Amigos_Recomendacoes(2, 15);
$Autorizacoes = $_Usuario->getAmigos_Pendentes();

Expand Down Expand Up @@ -243,12 +243,6 @@
'hideOnContentClick': false,
'autoDimensions': true
});
<?php
//require_once('../classes/Enquete.inc.php');
//$Enquete = new Enquete(5, $_GDE['DB']);
//if($Enquete->Ja_Votou($_Usuario) === false) { ?>
//$("a#enquete").click();
<?php //} ?>
$("#lista_amigos2 div.sliding_top").live("click", function() {
Adicionar_Amigo_Sugestao(($(this).attr("id").split('_'))[1]);
return false;
Expand Down Expand Up @@ -372,13 +366,13 @@
foreach($Amigos as $Amigo) { ?>
<div class="amigo" id="amigo_<?= $Amigo->getAmigo()->getID(); ?>">
<div class="amigo_foto">
<a href="<?= CONFIG_URL; ?>perfil/?usuario=<?= $Amigo->getAmigo()->getLogin() ?>" class="link_sem_decoracao" title="<?= $Amigo->getAmigo()->getNome(true).' '.$Amigo->getAmigo()->getSobrenome(true) ?>">
<img src="<?= $Amigo->getAmigo()->getFoto(true, true) ?>" border="0" alt="<?= $Amigo->getAmigo()->getNome(true) ?>" />
<a href="<?= CONFIG_URL; ?>perfil/?usuario=<?= $Amigo->getAmigo()->getLogin() ?>" class="link_sem_decoracao" title="<?= $Amigo->Apelido_Ou_Nome(false, true); ?>">
<img src="<?= $Amigo->getAmigo()->getFoto(true, true) ?>" border="0" alt="<?= $Amigo->Apelido_Ou_Nome(false, true); ?>" />
</a>
</div>
<div class="amigo_nome">
<img src="<?= CONFIG_URL; ?>web/images/status_vs.png" class="status_icone status_icone_<?= $Amigo->getAmigo()->getID(); ?>" alt="?" />
<a href="<?= CONFIG_URL; ?>perfil/?usuario=<?= $Amigo->getAmigo()->getLogin() ?>" class="amigo" title="<?= $Amigo->getAmigo()->getNome_Completo(true) ?>"><?= Util::Limita($Amigo->getApelido(true), 10); ?></a>
<a href="<?= CONFIG_URL; ?>perfil/?usuario=<?= $Amigo->getAmigo()->getLogin(); ?>" class="amigo" title="<?= $Amigo->Apelido_Ou_Nome(true, true); ?>"><?= Util::Limita($Amigo->Apelido_Ou_Nome(false, true), 10); ?></a>
</div>
</div>
<?php } } ?>
Expand Down

0 comments on commit 57796da

Please sign in to comment.