Modificado o modulo usuário para suportar a relação com o TipoUsuario

parent 4f022c4c
<?php
return array(
'db' => array(
'host' => getenv('IP'),
'host' => 'localhost',
'dbname' => 'RU',
'login' => getenv('C9_USER'),
'login' => 'root',
'password'=>''
)
);
......@@ -7,6 +7,8 @@ namespace Usuario\Controller;
use FrameworkMvc\Mvc\Controller;
use Usuario\Model\Usuario;
use FrameworkMvc\Hydrator\Hydrator;
use Usuario\Model\Dao\TipoUsuarioDao;
use Usuario\Model\TipoUsuario;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
......@@ -75,9 +77,9 @@ class UsuarioController extends Controller {
public function createAction() {
$viewData = array();
$user = new Usuario();
if (!empty($_POST)) {
$userDao = new \Usuario\Model\Dao\UsuarioDao(\FrameworkMvc\Dao\Conexao::getInstance());
......@@ -86,10 +88,17 @@ class UsuarioController extends Controller {
$hydrator->hydrate($_POST,$user);
$user->setSenha($user->getCarteirinha());
$userDao->inserir($user);
}
//Busca os tipos usuários da base
$tipoUsuarioDao = new TipoUsuarioDao(\FrameworkMvc\Dao\Conexao::getInstance());
$tipoUsuarios = $tipoUsuarioDao->recuperar();
$viewData['tiposUsuario'] = $tipoUsuarios;
$viewData['user'] = $user;
return $viewData;
}
......
......@@ -3,7 +3,7 @@
namespace Usuario\Model\Dao;
use FrameworkMvc\Hydrator\Hydrator;
use Usuario\Model\TipoUsuario;
use Usuario\Model\Dao\TipoUsuarioDao;
class UsuarioDao extends \FrameworkMvc\Dao\GenericDao{
......@@ -21,7 +21,31 @@ class UsuarioDao extends \FrameworkMvc\Dao\GenericDao{
return array('id');
}
protected function getAttributesPersist($usuario){
$data = parent::getAttributesPersist($usuario);
unset($data['tipoUsuario']);
if(is_object($usuario->getTipoUsuario()))
$data['tbTipoUsuario_nome'] = $usuario->getTipoUsuario()->getNome();
else
$data['tbTipoUsuario_nome'] = $usuario->getTipoUsuario();
return $data;
}
public function recuperar(array $where = array()){
$result = parent::recuperar($where);
foreach ($result as $key => $user) {
$tipoUserDao = new TipoUsuarioDao($this->conexao);
$tipo = $tipoUserDao->recuperar(array('nome'=>$user->getTipoUsuario()));
//$result[$key]->setTipoUsuario($tipo[0]);
}
return $result;
}
protected function makeDatabaseAttrClassAttr(array $value){
$tipo = $value['tbTipoUsuario_nome'];
unset($value['tbTipoUsuario_nome']);
$value['tipousuario'] = $tipo;
return $value;
}
public function getTipoUsuario($idUsuario){
try {
......@@ -38,7 +62,7 @@ class UsuarioDao extends \FrameworkMvc\Dao\GenericDao{
return NULL;
} catch (PDOException $e) {
throw new \Exception("Erro ao inserir:{$e->getMessage()}");
throw new \Exception("Erro ao recuperar:{$e->getMessage()}");
}
}
......
......@@ -15,7 +15,7 @@ class TipoUsuario {
}
public function setNome($nome){
$this->id = $nome;
$this->nome = $nome;
}
public function setValor($valor){
......
......@@ -20,6 +20,7 @@ class Usuario {
private $saldo;
private $email;
private $senha;
private $tipoUsuario;
public function getId(){
......@@ -68,6 +69,14 @@ class Usuario {
$this->senha = $senha;
}
public function getTipoUsuario() {
return $this->tipoUsuario;
}
public function setTipoUsuario($tipoUsuario) {
$this->tipoUsuario = $tipoUsuario;
}
}
......
......@@ -12,31 +12,20 @@
?>
<fieldset>
<legend> Cadastro Usuário </legend>
Nome: <input type="text" name="nome" value="<?php echo $this->data['user']->getNome() ?>"/>
<br> </br>
CPF: <input type="text" name="cpf" value="<?php echo $this->data['user']->getCpf() ?>"/>
<label for="nome">Nome:</label> <input type="text" name="nome" value="<?php echo $this->data['user']->getNome() ?>"/>
<br>
<label for="carteirinha">Carteirinha:</label> <input type="text" name="carteirinha" value="<?php echo $this->data['user']->getCarteirinha() ?>"/>
<br>
RG: <input type="text" name="rg" value="<?php echo $this->data['user']->getRg() ?>"/>
<br>
Matrícula: <input type="text" name="matricula" value="<?php echo $this->data['user']->getMatricula() ?>"/>
<br>
Carteirinha: <input type="text" name="carteirinha" value="<?php echo $this->data['user']->getCarteirinha() ?>"/>
<fieldset >
<legend> <br>Dados da Conta </legend>
<br>
PRAE:<fieldset> <input type="radio" name="prae" value="1" <?php if($this->data['user']->isPrae()) {echo "checked";} ?>>Sim<br>
<input type="radio" name="prae" value="0" <?php if(!($this->data['user']->isPrae())) {echo "checked";} ?>>Não<br>
</fieldset>
<br>
Saldo: <input type="text" name="saldo" value="<?php echo $this->data['user']->getSaldo() ?>"/>
<br>
Email: <input type="email" name="email" value="<?php echo $this->data['user']->getEmail() ?>"/>
Confirmar Email: <input type="email" name="confirmaEmail" />
<br>
Senha: <input type="password" name="senha" />
Confirmar Senha: <input type="password" name="confirmaSenha" />
</fieldset>
<input type="submit" value="Enviar"/>
<label for="tipoUsuario">Tipo Usuario:</label>
<select name="tipoUsuario">
<?php foreach ($this->data['tiposUsuario'] as $tipo) :
?>
<option value="<?php echo $tipo->getNome()?>"><?php echo $tipo->getNome()?></option>
<?php
endforeach;
?>
</select>
<input type="submit" value="Enviar"/>
</fieldset>
<br>
<br>
......
......@@ -17,7 +17,7 @@
<tr>
<th><?php echo $user->getCarteirinha()?></th>
<th><?php echo $user->getNome()?></th>
<th><?php echo $user->getEmail()?></th>
<th><?php echo $user->getTipoUsuario()->getNome()?></th>
<th><a href='?module=usuario&controller=usuario&action=update&id=<?php echo $user->getId()?>'>Editar</a></th>
<th><a href='?module=usuario&controller=usuario&action=delete&id=<?php echo $user->getId()?>'>Remover</a></th>
</tr>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment