Commit 8c10793d authored by Victor Mocelin's avatar Victor Mocelin

Funcionario: listar funcionando

parent c0b25956
<?php
namespace Func\Controller;
use FrameworkMvc\Mvc\Controller;
use Func\Model\Func;
/*@author Ana Bovs*/
class FuncController extends Controller{
public function indexAction(){
return array(['funcionarios'] => array(['login'], 'Oi'));
}
private function validaSenha($senha1, $senha2){
if ( ( empty($senha1) || empty($senha2) ) || ($senha1 != $senha2) )
return false;
else
return true;
}
public function createAction(){
$func = new Func();
$viewData = array();
if(!empty($_POST)){
$func->setID($_POST['id']);
$func->setLogin($_POST['login']);
if (!empty($_POST['admin']))
$func->setAdmin($_POST['admin']);
else
$func->setAdmin(0);
if ($this->validaSenha($_POST['senha1'], $_POST['senha2'])){
$func->setSenha($_POST['senha1']);
$viewData['success'] = true;
}
else
$viewData['sucess'] = false;
}
$viewData['func'] = $func;
return $viewData;
}
}
?>
<?php
namespace Func\Controller;
use FrameworkMvc\Mvc\Controller;
use Func\Model\Func;
/*@author Ana Bovs*/
class FuncController extends Controller{
public function indexAction(){
return array(['funcionarios'] => array(['login'], 'Oi'));
}
protected function validaSenha($senha1, $senha2){
if ( ( empty($senha1) || empty($senha2) ) || ($senha1 != $senha2) )
return false;
else
return true;
}
public function createAction(){
$func = new Func();
$viewData = array();
if(!empty($_POST)){
$func->setID($_POST['id']);
$func->setLogin($_POST['login']);
if (!empty($_POST['admin']))
$func->setAdmin($_POST['admin']);
else
$func->setAdmin(0);
if (validaSenha($_POST['senha1'], $_POST['senha2'])){
$func->setSenha($_POST['senha1']);
$viewData['success'] = true;
}
else
$viewData['sucess'] = false;
}
$viewData['func'] = $func;
return $viewData;
}
}
?>
<?php
namespace Func\Model;
/*@author Ana Bovs*/
class Func {
private $id;
private $login;
private $senha;
private $admin;
public function getID(){
return $this->id;
}
public function getLogin(){
return $this->login;
}
public function getSenha(){
return $this->senha;
}
public function getAdmin(){
return $this->admin;
}
public function setID($id){
$this->id = $id;
}
public function setLogin($login){
$this->login = $login;
}
public function setSenha($senha){
$this->senha = $senha;
}
public function setAdmin($admin){
$this->admin = $admin;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Index</title>
</head>
<body>
<?php
echo "<pre>";
print_r($this->data);
echo "</pre>";
?>
<li>
<?php
foreach($this->data['usuarios'] as $func){
?>
<ul> <?php echo $func['login'];?> </ul>
<?php } ?>
</li>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Index</title>
</head>
<body>
<?php
echo '<pre>';
print_r($this->data);
echo '</pre>';
?>
<li>
<?php
foreach($this->data['usuarios'] as $func){
?>
<ul> <?php echo $func['login'];?> </ul>
<?php } ?>
</li>
</body>
</html>
<?php
namespace Funcionario\Controller;
use FrameworkMvc\Mvc\Controller;
use FrameworkMvc\Hydrator\Hydrator;
use FrameworkMvc\Dao\GenericDao;
use FrameworkMvc\Dao\Conexao;
use Funcionario\Model\Funcionario;
use Funcionario\Model\Dao\FuncionarioDao;
/*@author Ana Bovs*/
class FuncionarioController extends Controller{
public function indexAction(){
header("location:?module=funcionario&controller=funcionario&action=listar");
}
private function validaSenha($senha1, $senha2){
if ( ($senha1 != $senha2) )
return false;
else
return true;
}
public function createAction(){
$func = new Funcionario();
$viewData = array();
if(!empty($_POST)){
$FuncionarioDao = new FuncionarioDao(Conexao::getInstance());
$hydrator = new Hydrator();
$hydrator->hydrate($_POST, $func);
if ($func->getAdministrador() != 1)
$func->setAdministrador(0);
$senha = $func->getSenha();
$senha2 = $_POST['confirmasenha'];
if (!empty($senha) && !empty($senha2))
if ($this->validaSenha($func->getSenha(), $_POST['confirmasenha'])){
try{
$FuncionarioDao->inserir($func);
}
catch(\Exception $ex){
$viewData['success'] = false;
}
header("location:?module=funcionario&controller=funcionario&action=listar&success=create");
}
else
$viewData['success'] = false;
else
$viewData['success'] = false;
}
$viewData['func'] = $func;
return $viewData;
}
public function updateAction(){
$viewData = array();
if (isset($_GET['id'])){
$result = array();
$FuncionarioDao = new FuncionarioDao(Conexao::getInstance());
$result = $FuncionarioDao->recuperar(array('id' => $_GET['id']));
if (!empty($result)){
$func = $result[0];
if(!empty($_POST)){
$hydrator = new Hydrator();
$hydrator->hydrate($_POST, $func);
if ($this->validaSenha($func->getSenha(), trim($_POST['confirmasenha']))){
try{
$result = $FuncionarioDao->atualizar($func, array('id' => $func->getId()));
}catch(\Exception $ex){
$viewData['success'] = false;
}
header("location:?module=funcionario&controller=funcionario&action=listar&success=update");
}
else{
$viewData['success'] = false;
}
}
$viewData['funcionario'] = $func;
return $viewData;
}
else{
header("location:?module=funcionario&controller=funcionario&action=listar&success=notupdate");
}
}
else
{
header("location:?module=funcionario&controller=funcionario&action=listar&success=notupdate");
}
}
public function deleteAction(){
$viewData = array();
if (isset($_GET['id'])){
$FuncionarioDao = new FuncionarioDao(Conexao::getInstance());
$result = $FuncionarioDao->deletar(array('id' => $_GET['id']));
if ($result > 0){
header("location:?module=funcionario&controller=funcionario&action=listar&success=delete");
}
else{
header("location:?module=funcionario&controller=funcionario&action=listar&success=notdelete");
}
}
else
{
header("location:?module=funcionario&controller=funcionario&action=listar&success=notdelete");
}
}
public function listarAction(){
$viewData = array();
$FuncionarioDao = new FuncionarioDao(Conexao::getInstance());
if (isset($_GET['success']))
$viewData['success'] = $_GET['success'];
if(empty($_POST['busca'])){
$viewData['funcionarios'] = $FuncionarioDao->recuperar();
}
else{
$viewData['funcionarios'] = $FuncionarioDao->buscar($_POST['busca']);
}
return $viewData;
}
}
?>
<?php
namespace Funcionario\Model\Dao;
use PDO;
class FuncionarioDao extends \FrameworkMvc\Dao\GenericDao{
protected function getNomeTabela(){
return 'tbFuncionario';
}
protected function getModelClassName(){
return 'Funcionario\Model\Funcionario';
}
protected function getAutoIncrementedColumns(){
return array('id');
}
public function buscar($where) {
try {
$modelClassName = $this->getModelClassName();
$stmt = $this->conexao->prepare("select * from tbFuncionario where login like :login");
$stmt->bindValue(':login',"%$where%",PDO::PARAM_STR);
$stmt->execute();
$data = $stmt->fetchAll();
$resultSet = array();
foreach ($data as $value) {
$objeto = new $modelClassName;
$this->hydrator->hydrate($value, $objeto);
$resultSet[] = $objeto;
}
return $resultSet;
} catch (PDOException $e) {
throw new \Exception("Erro ao inserir:{$e->getMessage()}");
}
}
}
<?php
namespace Func\Model;
namespace Funcionario\Model;
/*@author Ana Bovs*/
class Func {
class Funcionario {
private $id;
private $login;
private $senha;
private $admin;
private $administrador;
public function getID(){
public function getId(){
return $this->id;
}
......@@ -20,16 +20,15 @@ class Func {
return $this->senha;
}
public function getAdmin(){
return $this->admin;
public function getAdministrador(){
return $this->administrador;
}
public function isAdmin(){
return $this->admin;
public function isAdministrador(){
return $this->administrador;
}
public function setID($id){
public function setId($id){
$this->id = $id;
}
......@@ -38,13 +37,11 @@ class Func {
}
public function setSenha($senha){
$this->senha = $senha;
}
public function setAdmin($admin){
$this->admin = $admin;
$this->senha = trim($senha);
}
public function setAdministrador($admin){
$this->administrador = $admin;
}
}
?>
......@@ -7,22 +7,18 @@
<body>
<form method="POST">
<?php
print_r($this->data);
//exit;
echo isset($this->data['success'])?
$this->data['success'] ? "Cadastrado com Sucesso" : "Erro ao Cadastrar" : "oi";
$this->data['success'] ? "Cadastrado com Sucesso" : "Erro ao Cadastrar" : "";
?>
<fieldset>
<legend> Cadastro Funcionário</legend>
ID: <input type="text" name= "id" value="<?php echo $this->data['func']->getID() ?>"/>
<br><br>
Login: <input type="text" name="login" value="<?php echo $this->data['func']->getLogin() ?>"/>
<br><br>
Senha: <input type="text" name="senha1" value="<?php echo $this->data['func']->getSenha() ?>"/>
Senha: <input type="password" name="senha"/>
<br><br>
Confirme a Senha: <input type="text" name="senha2" value=""/>
Confirme a Senha: <input type="password" name="confirmasenha"/>
<br><br>
Administrador: <input type="checkbox" name="admin" value="1" <?php if ($this->data['func']->isAdmin()) echo "checked";?>/>
Administrador: <input type="checkbox" name="administrador" value="1" <?php if ($this->data['func']->isAdministrador()) echo "checked";?>/>
<br><br>
<input type="submit" value="Enviar"/>
</fieldset>
......
<!DOCTYPE html>
<html>
<head>
<title> Cadastro Funcionário </title>
<meta http-equiv="Content-Type" content="text/html" charset="UTF-8">
</head>
<body>
<form method="POST">
<?php
if (isset($this->data['success']))
{
if ($this->data['success'] == 'delete')
echo 'Deletado com Sucesso';
if ($this->data['success'] == 'create')
echo 'Inserido com Sucesso';
if ($this->data['success'] == 'update')
echo 'Atualizado com Sucesso';
if ($this->data['success'] == 'notdelete')
echo 'Erro ao Deletar.';
if ($this->data['success'] == 'notcreate')
echo 'Erro ao Inserir';
if ($this->data['success'] == 'notupdate')
echo 'Erro ao Atualizar';
}
?>
<fieldset>
<legend> Cadastro Funcionário</legend>
Buscar: <input type="text" name= "busca"/>
<input type="submit" value="Enviar"/>
<input type="button" value="Inserir" onClick="location.href='?module=funcionario&controller=funcionario&action=create'"/>
</fieldset>
<fieldset>
<table border ='1'>
<thead>
<tr>
<th>Login</th>
<th>Senha</th>
<th>Admin</th>
<th colspan="2">Ação</th>
</tr>
</thead>
<?php
foreach ($this->data['funcionarios'] as $funcionario)
{
?>
<tr>
<th><?php echo $funcionario->getLogin()?></th>
<th><?php echo $funcionario->getSenha()?></th>
<th><?php echo $funcionario->getAdministrador()?></th>
<th><a href='?module=funcionario&controller=funcionario&action=update&id=<?php echo $funcionario->getId()?>'>edit</a></th>
<th><a href='?module=funcionario&controller=funcionario&action=delete&id=<?php echo $funcionario->getId()?>'>delete</a></th>
</tr>
<?php
}
?>
</table>
</fieldset>
</form>
</body>
</html>
......@@ -7,22 +7,18 @@
<body>
<form method="POST">
<?php
print_r($this->data);
//exit;
echo isset($this->data['success'])?
$this->data['success'] ? 'Cadastrado com Sucesso' : "Erro ao Cadastrar" : "oi";
$this->data['success'] ? "Atualizado com Sucesso" : "Erro ao atualizar" : "";
?>
<fieldset>
<legend> Cadastro Funcionário</legend>
ID: <input type="text" name= "id" value="<?php echo $this->data['func']->getID() ?>"/>
Login: <input type="text" name="login" value="<?php echo $this->data['funcionario']->getLogin() ?>"/>
<br><br>
Login: <input type="text" name="login" value="<?php echo $this->data['func']->getLogin() ?>"/>
Senha: <input type="password" name="senha"/>
<br><br>
Senha: <input type="text" name="senha1" value="<?php echo $this->data['func']->getSenha() ?>"/>
Confirme a Senha: <input type="password" name="confirmasenha"/>
<br><br>
Confirme a Senha: <input type="text" name="senha2" value=""/>
<br><br>
Administrador: <input type="checkbox" name="admin" value="1" <?php if ($this->data['func']->isAdmin()) echo "checked";?>/>
Administrador: <input type="checkbox" name="administrador" value="1" <?php if ($this->data['funcionario']->isAdministrador()) echo "checked";?>/>
<br><br>
<input type="submit" value="Enviar"/>
</fieldset>
......
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