Skip to content

Commit 99e612b

Browse files
committed
Notas funcionando
1 parent 925a619 commit 99e612b

File tree

5 files changed

+215
-27
lines changed

5 files changed

+215
-27
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Funciona:
4141
- Login
4242
- Inicial
4343
- Mapa do Campus
44+
- Notas
4445
- Oferecimento
4546
- Perfil (Usuário, Aluno e Professor)
4647
- Perguntas Frequentes (FAQ)
@@ -56,7 +57,6 @@ Ainda não funciona:
5657
- Chat
5758
- Frase do Dia
5859
- Enquetes
59-
- Notas
6060

6161

6262
P: E qual o prazo pra isso ser concluído?

ajax/nota.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace GDE;
4+
5+
define('JSON', true);
6+
require_once('../common/common.inc.php');
7+
8+
if($_POST['tp'] == 'n') {
9+
if(!empty($_POST['i'])) {
10+
$Nota = Nota::Load($_POST['i']);
11+
if($Nota->getID() == null)
12+
Base::Error_JSON('Nota não encontrada.');
13+
if($Nota->getUsuario()->getID() != $_Usuario->getID())
14+
Base::Error_JSON('Acesso negado.');
15+
} else
16+
$Nota = new Nota();
17+
18+
if(strlen($_POST['sigla']) < 1)
19+
Base::Error_JSON("A sigla &eacute; muito curta!");
20+
21+
if($_POST['sigla'] == "Exame")
22+
Base::Error_JSON("Para inserir uma nota de exame, use o campo Adicionar Exame.");
23+
24+
$Nota->setUsuario($_Usuario);
25+
$Oferecimento = Oferecimento::Load($_POST['m']);
26+
if($Oferecimento->getID() == null)
27+
Base::Error_JSON('Oferecimento não encontrado.');
28+
$Nota->setOferecimento($Oferecimento);
29+
$Nota->setSigla($_POST['sigla']);
30+
$Nota->setNota(floatval(str_replace(',', '.', $_POST['nota'])));
31+
$Nota->setPeso(floatval(str_replace(',', '.', $_POST['peso'])));
32+
$Nota->Save_JSON(true);
33+
} elseif($_POST['tp'] == 'e') { // Exame
34+
if(!empty($_POST['i'])) {
35+
$Nota = Nota::Load($_POST['i']);
36+
if($Nota->getID() == null)
37+
Base::Error_JSON('Nota não encontrada.');
38+
if($Nota->getUsuario()->getID() != $_Usuario->getID())
39+
Base::Error_JSON('Acesso negado.');
40+
} else
41+
$Nota = new Nota();
42+
43+
if(strlen($_POST['sigla']) < 1)
44+
Base::Error_JSON("A sigla &eacute; muito curta!");
45+
46+
$Nota->setUsuario($_Usuario);
47+
$Oferecimento = Oferecimento::Load($_POST['m']);
48+
if($Oferecimento->getID() == null)
49+
Base::Error_JSON('Oferecimento não encontrado.');
50+
$Nota->setOferecimento($Oferecimento);
51+
$Nota->setSigla($_POST['sigla']);
52+
$Nota->setNota(floatval(str_replace(',', '.', $_POST['nota'])));
53+
$Nota->setPeso('1');
54+
$Nota->Save_JSON(true);
55+
} elseif($_POST['tp'] == 'x') { // Excluir
56+
$Nota = Nota::Load($_POST['id']);
57+
if($Nota->getID() == null)
58+
Base::Error_JSON('Nota não encontrada.');
59+
if($Nota->getUsuario()->getID() != $_Usuario->getID())
60+
Base::Error_JSON('Acesso negado.');
61+
$Nota->Delete_JSON(true);
62+
}

ajax/notas.php

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
3+
namespace GDE;
4+
5+
define('NO_CACHE', true);
6+
define('NO_HTML', true);
7+
define('NO_REDIRECT', true);
8+
9+
require_once('../common/common.inc.php');
10+
11+
if($_Usuario->getAluno(false) === null)
12+
exit();
13+
14+
if(!empty($_GET['idn'])) {
15+
$Nota = Nota::Load($_GET['idn']);
16+
if(($Nota->getID() == null) || ($Nota->getUsuario(true)->getID() != $_Usuario->getID()))
17+
exit();
18+
?>
19+
<div id="div_nota_<?= $Nota->getID(); ?>" class="nota">
20+
<span class="nota_sigla"><?= $Nota->getSigla(true); ?></span>: <span class="nota_nota"><?= $Nota->getNota(true); ?></span>
21+
<span class="peso_texto">Peso</span>: <span class="peso_valor"><?= $Nota->getPeso(true); ?></span>
22+
<a href="#" onclick="return Alterar_Nota('<?= $Nota->getID(); ?>', '<?= $Nota->getOferecimento()->getID(); ?>');">Alterar</a>
23+
<a href="#" onclick="return Remover_Nota('<?= $Nota->getID(); ?>');">Excluir</a>
24+
</div>
25+
<?php
26+
exit();
27+
}
28+
29+
$Periodo_Selecionado = (!empty($_GET['p'])) ? Periodo::Load($_GET['p']) : Periodo::getAtual();
30+
31+
$Periodos = Periodo::Listar();
32+
$periodos = "";
33+
foreach($Periodos as $Periodo)
34+
$periodos .= '<option value="'.$Periodo->getID().'"'.(($Periodo_Selecionado->getID() == $Periodo->getID())?' selected="selected"':null).'>'.$Periodo->getNome(false).'</option>';
35+
36+
$Oferecimentos = $_Usuario->getAluno()->getOferecimentos($Periodo_Selecionado->getID());
37+
38+
?>
39+
<div class="div_periodo"><strong>Notas de <select id="periodo_notas"><?= $periodos; ?></select></strong></div>
40+
<?php
41+
if(count($Oferecimentos) == 0)
42+
die(' <div style="text-align: center;"><strong>Voc&ecirc; n&atilde;o cursou nenhuma Disciplina em '.$Periodo_Selecionado->getNome(false).'!</strong></div>');
43+
?>
44+
<div style="text-align: center;"><strong>Aviso:</strong> Esta ainda &eacute; uma vers&atilde;o preliminar do controle de notas.</div>
45+
<div id="tabs_notas" class="tabs-bottom">
46+
<ul>
47+
<?php foreach($Oferecimentos as $Oferecimento) { ?>
48+
<li><a href="#tab_notas_<?= $Oferecimento->getID(); ?>"><?= $Oferecimento->getSigla(true); ?> <?= $Oferecimento->getTurma(true); ?></a></li>
49+
<?php } ?>
50+
</ul>
51+
<?php foreach($Oferecimentos as $Oferecimento) { ?>
52+
<div id="tab_notas_<?= $Oferecimento->getID(); ?>" class="tab_content">
53+
<div class="notas_header_sigla"><?= $Oferecimento->getSigla(true); ?> <?= $Oferecimento->getTurma(true); ?></div>
54+
<div class="notas_header_nome"><?= $Oferecimento->getDisciplina()->getNome(true); ?></div>
55+
<div class="notas">
56+
<?php foreach(Nota::Listar($_Usuario, $Oferecimento) as $Nota)
57+
if ($Nota->getSigla() != "Exame") { ?>
58+
<div id="div_nota_<?= $Nota->getID(); ?>" class="nota">
59+
<div class="nota_sigla">
60+
<?= $Nota->getSigla(true); ?>
61+
<a href="#" onclick="return Alterar_Nota('<?= $Nota->getID(); ?>', '<?= $Nota->getOferecimento()->getID(); ?>');"><img src="<?= CONFIG_URL; ?>web/images/EditOFF.png" alt="Alterar" title="Alterar" class="nota_botao_lapis" /></a>
62+
<a href="#" id="excluir_nota_<?= $Nota->getID(); ?>" onclick="return Remover_Nota('<?= $Nota->getID(); ?>');"><img class="nota_botao_x" src="<?= CONFIG_URL; ?>web/images/CancelOFF.png" alt="Excluir" title="Excluir" /></a>
63+
</div>
64+
<div class="nota_texto">
65+
<span class="nota_texto">Nota</span>: <span class="nota_valor"><?= $Nota->getNota(true); ?></span>
66+
</div>
67+
<div class="peso_texto">
68+
<span class="peso_texto">Peso</span>: <span class="peso_valor"><?= $Nota->getPeso(true); ?></span>
69+
</div>
70+
</div>
71+
<?php
72+
}
73+
$totalPeso = 0;
74+
$media = 0;
75+
foreach(Nota::Listar($_Usuario, $Oferecimento) as $Nota)
76+
if($Nota->getSigla() != "Exame"){
77+
$totalPeso += floatval(str_replace(",", ".", $Nota->getPeso(true)));
78+
$media += floatval(str_replace(",", ".", $Nota->getNota(true))) * floatval(str_replace(",", ".", $Nota->getPeso(false)));
79+
}
80+
else
81+
$Exame = $Nota;
82+
if($totalPeso > 0) {
83+
$media = floatval($media / $totalPeso);
84+
?>
85+
<div id="div_media_<?= $Oferecimento->getID(); ?>" class="nota">
86+
<div class="nota_sigla">M&eacute;dia</div>
87+
<div class="nota_texto">
88+
<span class="nota_texto">Nota</span>: <span class="media_valor"><?= number_format($media, 2, ',', '.'); ?></span>
89+
</div>
90+
</div>
91+
<?php }
92+
if(isset($Exame) && ($Exame->getOferecimento()->getID() == $Oferecimento->getID() )) { ?>
93+
<div id="div_nota_<?= $Exame->getID(); ?>" class="nota">
94+
<div class="nota_sigla">Exame <a href="#" onclick="return Alterar_Nota('<?= $Exame->getID(); ?>', '<?= $Exame->getOferecimento()->getID(); ?>');"><img src="<?= CONFIG_URL; ?>web/images/EditOFF.png" alt="Alterar" title="Alterar" class="nota_botao_lapis" /></a> <a href="#" id="excluir_nota_<?= $Exame->getID(); ?>" onclick="return Remover_Nota('<?= $Exame->getID(); ?>');"><img class="nota_botao_x" src="<?= CONFIG_URL; ?>web/images/CancelOFF.png" alt="Excluir" title="Excluir" /></a></div>
95+
<div class="nota_texto">
96+
<span class="nota_texto">Nota</span>: <span class="nota_valor"><?= $Exame->getNota(true); ?></span>
97+
</div>
98+
</div>
99+
<div id="div_media_final_<?= $Oferecimento->getID(); ?>" class="nota">
100+
<div class="media_sigla">M&eacute;dia Final</div>
101+
<span class="nota_texto">Nota</span>: <span class="media_valor"><?=number_format((($media+str_replace(",", ".", $Exame->getNota(false)))/2), 2, ',', '.'); ?></span>
102+
</div>
103+
<?php } ?>
104+
<div id="nota_funcoes_<?= $Oferecimento->getID() ?>" class="nota">
105+
<div class="notas_funcoes" id="funcao_nota_<?= $Oferecimento->getID() ?>">
106+
<a href="#" id="link_nova_nota_<?= $Oferecimento->getID(); ?>" onclick="return Adicionar_Nota('<?= $Oferecimento->getID(); ?>', false);">Nova Nota</a>
107+
</div>
108+
<?php if((count(Nota::Listar($_Usuario, $Oferecimento)) > 0) && (!isset($Exame))) { ?>
109+
<div class="notas_funcoes" id="funcao_exame_<?= $Oferecimento->getID() ?>">
110+
<a href="#" id="link_novo_exame_<?= $Oferecimento->getID(); ?>" onclick="return Adicionar_Nota('<?= $Oferecimento->getID(); ?>', true);" class="nota_funcoes">Adicionar Exame</a>
111+
</div>
112+
<?php
113+
}
114+
unset($Exame);
115+
?>
116+
</div>
117+
</div>
118+
</div>
119+
<?php } ?>
120+
</div>

classes/GDE/Nota.inc.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ class Nota extends Base {
2424
* @var Usuario
2525
*
2626
* @ORM\ManyToOne(targetEntity="Usuario")
27-
* @ORM\JoinColumns({
28-
* @ORM\JoinColumn(name="id_usuario", referencedColumnName="id_usuario")
29-
* })
27+
* @ORM\JoinColumn(name="id_usuario", referencedColumnName="id_usuario")
3028
*/
3129
protected $usuario;
3230

@@ -59,5 +57,13 @@ class Nota extends Base {
5957
*/
6058
protected $peso = '1.00000';
6159

60+
/**
61+
* @param Usuario $Usuario
62+
* @param Oferecimento $Oferecimento
63+
* @return Nota[]|false
64+
*/
65+
public static function Listar(Usuario $Usuario, Oferecimento $Oferecimento) {
66+
return self::FindBy(array('usuario' => $Usuario->getID(), 'oferecimento' => $Oferecimento->getID()));
67+
}
6268

6369
}

0 commit comments

Comments
 (0)