Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buscaminas #15

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 97 additions & 19 deletions Controller/Conexion/ConexionPartida.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,42 @@ public function getPartidas()
echo json_encode($rtn);
}

public function getPartida($id)
public function getPartidaByUserId($idUser)
{
$con = new Conexion();
$con->conectar();

$consulta = "SELECT * FROM PARTIDA WHERE id = ?";
$consulta = "SELECT * FROM ". Constantes::$TABLE_partida." WHERE idUsuario = ? and resultado = 0";

$stmt = mysqli_prepare(Conexion::$conexion, $consulta);
mysqli_stmt_bind_param($stmt, "i", $id);
mysqli_stmt_execute($stmt);
$stmt = Conexion::$conexion->prepare($consulta);

$stmt->bind_param("i", $idUser);

$stmt->execute();
$resultados = $stmt->get_result();

$partida=$resultados->fetch_array();

$rtnPartida = new Partida();
$rtnPartida->setPartida($partida);

$resultados = mysqli_stmt_get_result($stmt);
$con->desconectar();

return $rtnPartida;
}

$rtn = [];
public function setWin($idUser){
$con = new Conexion();
$con->conectar();

$consulta = "UPDATE ". Constantes::$TABLE_partida." SET resultado = 1 WHERE idUsuario = ? and resultado = 0";
$stmt = Conexion::$conexion->prepare($consulta);

while ($fila = mysqli_fetch_row($resultados)) {
$rtn[] = $fila[0] . "," . $fila[1] . "," . $fila[2] . "," . $fila[3];
}
$stmt->bind_param("i", $idUser);

echo json_encode($rtn);
$stmt->execute();

$con->desconectar();
}

public function updatePartidaRendirse($idUser)
Expand All @@ -63,6 +78,34 @@ public function updatePartidaRendirse($idUser)
$con->desconectar();
}

public function setPosicionJugando($idUser, $tablero)
{
$con = new Conexion();
$con->conectar();

$consulta = "UPDATE ". Constantes::$TABLE_partida." SET jugando = ? WHERE idUsuario = ? and resultado = 0";
$stmt = Conexion::$conexion->prepare($consulta);
$stmt->bind_param("si",$tablero, $idUser);

$stmt->execute();

$con->desconectar();
}

public function setPosicionResuelto($idUser, $tablero)
{
$con = new Conexion();
$con->conectar();

$consulta = "UPDATE ". Constantes::$TABLE_partida." SET resuelto = ? WHERE idUsuario = ? and resultado = 0";
$stmt = Conexion::$conexion->prepare($consulta);
$stmt->bind_param("si",$tablero, $idUser);

$stmt->execute();

$con->desconectar();
}

public function insertPosPartida()
{
$con = new Conexion();
Expand All @@ -85,12 +128,12 @@ public function getTableroInvisible($idUser)
$stmt->execute();
$resultados = $stmt->get_result();

$rtnUser=$resultados->fetch_array();

$partida=$resultados->fetch_array();


$con->desconectar();

return $rtnUser;
return $partida;
}

public function getTableroJugando($idUser)
Expand Down Expand Up @@ -120,7 +163,8 @@ public function getRanking()
$con = new Conexion();
$con->conectar();

$consulta = "SELECT USUARIO.nombre, count(resuelto) as ganadas FROM PARTIDA inner join USUARIO ON PARTIDA.idUsuario = USUARIO.ID where resuelto=1 GROUP by idUsuario order by ganadas";
$consulta = "SELECT USUARIO.nombre, count(resuelto) as ganadas FROM PARTIDA inner join USUARIO ON PARTIDA.idUsuario = USUARIO.ID where resuelto=1 GROUP by idUsuario order by ganadas desc";


$stmt = mysqli_prepare(Conexion::$conexion, $consulta);
mysqli_stmt_execute($stmt);
Expand All @@ -129,7 +173,7 @@ public function getRanking()

$rtn = mysqli_fetch_row($resultados);

return json_encode($rtn);
return $rtn;
}


Expand Down Expand Up @@ -157,7 +201,7 @@ public function getLastPartida($idUser){
$con = new Conexion();
$con->conectar();

$consulta = "SELECT resultado FROM ". Constantes::$TABLE_partida." where idUsuario = ? order by ID desc";
$consulta = "SELECT * FROM ". Constantes::$TABLE_partida." where idUsuario = ? order by ID desc";

$stmt = Conexion::$conexion->prepare($consulta);

Expand All @@ -166,11 +210,45 @@ public function getLastPartida($idUser){
$stmt->execute();
$resultados = $stmt->get_result();

$rtnResultado = $resultados->fetch_array();
$partida = $resultados->fetch_array();

$rtnPartida = new Partida();

$rtnPartida->setPartida($partida);

// $rtnPartida = null;
// if($rtnPartida != null){
// $rtnPartida = new Partida();
// $rtnPartida->setPartida($partida);
// }

$con->desconectar();
return $rtnPartida;
}

public function getTableroByIdUser($idUser){
$con = new Conexion();
$con->conectar();

$consulta = "SELECT * FROM ". Constantes::$TABLE_partida." WHERE idUsuario = ?";

$stmt = Conexion::$conexion->prepare($consulta);

$stmt->bind_param("i", $idUser);

$stmt->execute();
$resultados = $stmt->get_result();

$partida=$resultados->fetch_array();

$rtnPartida = new Partida();
$rtnPartida->setPartida($partida);



$con->desconectar();

return $rtnResultado;
return $rtnPartida;
}

public function getTableroResuelto($idUser){
Expand Down
30 changes: 29 additions & 1 deletion Controller/Conexion/ConexionUsuario.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

require __DIR__.'../Conexion.php';
require __DIR__.'/Conexion.php';

class ConexionUsuario{

Expand Down Expand Up @@ -179,4 +179,32 @@ public function getEmail($email){
return $email;

}

public function updateCountJugadaPartida($idUser, $jugadas){
$con = new Conexion();
$con->conectar();

$consulta = "UPDATE ". Constantes::$TABLE_usuario." SET partidasJugadas = ? WHERE ID = ?";
$stmt = Conexion::$conexion->prepare($consulta);

$stmt->bind_param("ii", $jugadas, $idUser);

$stmt->execute();

$con->desconectar();
}

public function updateCountGanadaPartida($idUser, $jugadas){
$con = new Conexion();
$con->conectar();

$consulta = "UPDATE ". Constantes::$TABLE_usuario." SET partidasGanadas = ? WHERE ID = ?";
$stmt = Conexion::$conexion->prepare($consulta);

$stmt->bind_param("ii", $jugadas, $idUser);

$stmt->execute();

$con->desconectar();
}
}
22 changes: 10 additions & 12 deletions Controller/Mail/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;

require_once 'phpmailer/src/Exception.php';
require_once 'phpmailer/src/PHPMailer.php';
require_once 'phpmailer/src/SMTP.php';

require_once __DIR__.'/phpmailer/src/Exception.php';
require_once __DIR__.'/phpmailer/src/PHPMailer.php';
require_once __DIR__.'/phpmailer/src/SMTP.php';
class Mail {
public function sendmail($destinomail, $destinonombre, $asunto, $newPass)
static function sendmail($email, $name, $newpass)
{

try {
$mail = new PHPMailer();
//Configuración del servidor
Expand All @@ -29,7 +26,7 @@ public function sendmail($destinomail, $destinonombre, $asunto, $newPass)
$mail->setFrom(Constantes::$MAILUsername, Constantes::$MAILFromName);

//Destinatarios
$mail->addAddress($destinomail, $destinonombre); //Añadir un destinatario, el nombre es opcional
$mail->addAddress($email, $name); //Añadir un destinatario, el nombre es opcional

//Destinatarios opcionales
// $mail->addReplyTo('[email protected]', 'Information'); //Responder a
Expand All @@ -41,14 +38,15 @@ public function sendmail($destinomail, $destinonombre, $asunto, $newPass)

//Nombre opcional
$mail->isHTML(true); //Establecer el formato de correo electrónico en HTMl
$mail->Subject = $asunto;
$mail->Body = `<meta charset="ISO-8859-1"> ¡Su nueva contraseña es: <b>$newPass</b>`;
$mail->AltBody = 'Desde Gitignore Tech esperemos que disfrute de su cuenta';
$mail->Subject = "New Password!";
$mail->Body = "Su nueva contrase&ntilde;a es: <b>$newpass</b> <br>Desde Gitignore Tech esperemos que disfrute de su cuenta";


$mail->send(); //Enviar correo eletrónico

echo "llego hasta aquí";
} catch (Exception $e) {

echo $e;
}
}
}
34 changes: 23 additions & 11 deletions Controller/Partida.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
<?php

class Partida {
private $id;
private $idUsuario;
private $tVacio;
private $tFinal;
private $resultado;
public $id;
public $idUsuario;
public $tVacio;
public $tFinal;
public $resultado;

public function __construct($id, $idUsuario) {
// public function __toString()
// {
// return 'id: '.$this->$id.''..''..''..''...;
// }

$this->id = $id;
$this->idUsuario = $idUsuario;
public function setPartida($arrValues){
$this->setIdUsuario($arrValues["idUsuario"]);
$this->setTVacio($arrValues["jugando"]);
$this->setTFinal($arrValues["resuelto"]);
$this->setResultado($arrValues["resultado"]);
}

public function setPartida2($arrValues){
$this->setIdUsuario($arrValues["idUsuario"]);
$this->setTVacio($arrValues["tVacio"]);
$this->setTFinal($arrValues["tFinal"]);
$this->setResultado($arrValues["resultado"]);
}

public function getId() {
return $this->id;
}
Expand Down Expand Up @@ -46,11 +58,11 @@ public function setTFinal($value) {
$this->tFinal = $value;
}

public function getResultad() {
public function getResultado() {
return $this->resultado;
}

public function setResultad($value) {
public function setResultado($value) {
$this->resultado = $value;
}
}
2 changes: 1 addition & 1 deletion Controller/Service/ServiceJSON.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public function send($code, $msg, $extra=null){
echo json_encode($rtnArr);
}

header("HTTP/1.1 $code $msg");
header("HTTP/1.1 $code $msg");
}
}
Loading