diff --git a/ajax/cardapios.php b/ajax/cardapios.php index 8d9d49a..7fabf1d 100644 --- a/ajax/cardapios.php +++ b/ajax/cardapios.php @@ -1,39 +1,28 @@ $cardapio) { - $d = $_GDE['DB']->UserDate($cardapio['data'], "w") + 1; - if($cardapio['tipo'] == 1) - echo "\r\n \r\n \r\n \r\n \r\n \r\n \r\n "; - echo "\r\n"; - if($cardapio['tipo'] == 2) +foreach($Cardapios as $k => $Cardapio) { + if($Cardapio->getTipo(false) == Cardapio::TIPO_ALMOCO) + echo "\r\n \r\n \r\n \r\n \r\n \r\n \r\n "; + echo "\r\n"; + if($Cardapio->getTipo(false) == Cardapio::TIPO_JANTAR) echo "\r\n "; } ?> -
".$d."ª-feira (".$_GDE['DB']->UserDate($cardapio['data'], "d/m/Y").")
AlmoçoJantar
".Formata_Cardapio($cardapio, false)."
".$Cardapio->Dia_Da_Semana()." (".$Cardapio->getData("d/m/Y").")
AlmoçoJantar
".$Cardapio->Formatado(false)."
\ No newline at end of file + diff --git a/classes/GDE/Acontecimento.inc.php b/classes/GDE/Acontecimento.inc.php index bfde593..ba1be13 100644 --- a/classes/GDE/Acontecimento.inc.php +++ b/classes/GDE/Acontecimento.inc.php @@ -87,7 +87,7 @@ public function getTexto($html = false, $processa = false, $meu = false, Usuario // Amizade if($this->getTipo() == 'ua') return (!$meu) - ? " agora é amig".$this->getOrigem()->getSexo(true, true)." de ".$_GDE['Usuario']->Apelido_Ou_Nome($this->getDestino(), true)."." + ? " agora é amig".$this->getOrigem()->getSexo(true, true)." de ".$_Usuario->Apelido_Ou_Nome($this->getDestino(), false, true)."." : " agora é ".(($this->getOrigem()->getSexo() == 'f')?'sua amiga':'seu amigo')."."; // Mensagem, Status de Usuario elseif(($this->getTipo() == 'um') || ($this->getTipo() == 'us') || ($this->getTipo() == 'rs')) { @@ -96,7 +96,7 @@ public function getTexto($html = false, $processa = false, $meu = false, Usuario elseif($this->getTipo() == 'rs') $texto_pre = " (anúncio)"; 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 .= ": "; @@ -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ção do GDE"; else diff --git a/classes/GDE/Cardapio.inc.php b/classes/GDE/Cardapio.inc.php index f1612d7..cbea7b6 100644 --- a/classes/GDE/Cardapio.inc.php +++ b/classes/GDE/Cardapio.inc.php @@ -92,6 +92,9 @@ class Cardapio extends Base { */ protected $ultima_atualizacao; + /** + * @return Cardapio + */ public static function Atual() { $hora = date('H'); $dia = date('d'); @@ -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); @@ -124,21 +165,30 @@ 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ça-feira', 'Quarta-feira', 'Quinta-feira', 'Sexta-feira', 'Sábado'); - return (($cabecalho)?"".(($this->getTipo(false) == self::TIPO_ALMOCO)?"ALMOÇO":"JANTAR")." de ".$ds[$this->getData('w')].", ".$this->getData("d/m/Y").":
":null)."Prato Principal: ".$this->getPrincipal(true)."
". + return (($cabecalho)?"".(($this->getTipo(false) == self::TIPO_ALMOCO)?"ALMOÇO":"JANTAR")." de ".$this->Dia_Da_Semana().", ".$this->getData("d/m/Y").":
":null)."Prato Principal: ".$this->getPrincipal(true)."
". ((!empty($this->getGuarnicao(false)))? "Guarnição: ".$this->getGuarnicao(true)."
" : null). ((!empty($this->getPTS(false)))? "PTS: ".$this->getPTS(true)."
" : null). "Salada: ".$this->getSalada(true)."
". @@ -146,4 +196,8 @@ public function Formatado($cabecalho = true) { "Suco: ".$this->getSuco(true)."
". ((!empty($this->getVegetariano(false)))? "Vegetariano: ".$this->getVegetariano(true)."
" : null); } + + public function Dia_Da_Semana() { + return Util::Dia_Da_Semana($this->getData('w')); + } } diff --git a/classes/GDE/Usuario.inc.php b/classes/GDE/Usuario.inc.php index 967417f..f8f48cb 100644 --- a/classes/GDE/Usuario.inc.php +++ b/classes/GDE/Usuario.inc.php @@ -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 @@ -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); } /** diff --git a/classes/GDE/UsuarioAmigo.inc.php b/classes/GDE/UsuarioAmigo.inc.php index 4a06acd..7884a15 100644 --- a/classes/GDE/UsuarioAmigo.inc.php +++ b/classes/GDE/UsuarioAmigo.inc.php @@ -2,6 +2,7 @@ namespace GDE; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; /** @@ -29,9 +30,7 @@ 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; @@ -39,9 +38,7 @@ class UsuarioAmigo extends Base { * @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; @@ -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)); + } } diff --git a/classes/GDE/Util.inc.php b/classes/GDE/Util.inc.php index 3f19915..4f33181 100644 --- a/classes/GDE/Util.inc.php +++ b/classes/GDE/Util.inc.php @@ -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ça-feira', 'Quarta-feira', 'Quinta-feira', 'Sexta-feira', 'Sábado')[$d]; + } + } diff --git a/views/index.php b/views/index.php index 7e9addd..6e0ecd3 100644 --- a/views/index.php +++ b/views/index.php @@ -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(); @@ -243,12 +243,6 @@ 'hideOnContentClick': false, 'autoDimensions': true }); -Ja_Votou($_Usuario) === false) { ?> - //$("a#enquete").click(); - $("#lista_amigos2 div.sliding_top").live("click", function() { Adicionar_Amigo_Sugestao(($(this).attr("id").split('_'))[1]); return false; @@ -372,13 +366,13 @@ foreach($Amigos as $Amigo) { ?>
- - <?= $Amigo->getAmigo()->getNome(true) ?> + + <?= $Amigo->Apelido_Ou_Nome(false, true); ?>
? - getApelido(true), 10); ?> + Apelido_Ou_Nome(false, true), 10); ?>