Skip to content

Commit

Permalink
Merge pull request #13 from bhamidou/user
Browse files Browse the repository at this point in the history
Merge branch user to develop
  • Loading branch information
bhamidou authored Oct 17, 2023
2 parents 496e204 + 27b62ba commit 78e03f6
Show file tree
Hide file tree
Showing 10 changed files with 774 additions and 165 deletions.
4 changes: 2 additions & 2 deletions Controller/Conexion/Conexion.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
class Conexion
{

static $conexion;
public static $conexion;

public function conectar()
{
try {
self::$conexion = new mysqli(Constantes::$host, Constantes::$user, Constantes::$pass, Constantes::$database, Constantes::$port);
self::$conexion = new mysqli(Constantes::$DB_host, Constantes::$DB_user, Constantes::$DB_pass, Constantes::$DB_database, Constantes::$DB_port);
} catch (Exception $e) {
die();
}
Expand Down
148 changes: 128 additions & 20 deletions Controller/Conexion/ConexionPartida.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

require __DIR__.'/Controller/Conexion.php';
class ConexionPartida{
public function getPartidas(){
require __DIR__.'../../../Factories/FactoryPartida.php';
class ConexionPartida
{
public function getPartidas()
{
$con = new Conexion();
$con->conectar();

Expand All @@ -14,16 +16,17 @@ public function getPartidas(){
$resultados = mysqli_stmt_get_result($stmt);
$con->desconectar();

$rtn= [];
$rtn = [];

while ($fila = mysqli_fetch_row($resultados)) {
$rtn[] = $fila[0].",". $fila[1].",".$fila[2].",".$fila[3];
$rtn[] = $fila[0] . "," . $fila[1] . "," . $fila[2] . "," . $fila[3];
}

echo json_encode($rtn);
}

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

Expand All @@ -36,52 +39,157 @@ public function getPartida($id){
$resultados = mysqli_stmt_get_result($stmt);
$con->desconectar();

$rtn= [];
$rtn = [];

while ($fila = mysqli_fetch_row($resultados)) {
$rtn[] = $fila[0].",". $fila[1].",".$fila[2].",".$fila[3];
$rtn[] = $fila[0] . "," . $fila[1] . "," . $fila[2] . "," . $fila[3];
}

echo json_encode($rtn);
}

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

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

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

$stmt->execute();

$con->desconectar();
}

public function updatePartida($posicion){
public function insertPosPartida()
{
$con = new Conexion();
$con->conectar();

$con->desconectar();
}

public function insertPosPartida(){

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

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

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

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

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

$rtnUser=$resultados->fetch_array();


$con->desconectar();

return $rtnUser;
}

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

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

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

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

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

$rtnUser=$resultados->fetch_array();


$con->desconectar();

return $rtnUser;
}

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";

$stmt = mysqli_prepare(Conexion::$conexion, $consulta);
mysqli_stmt_bind_param($stmt, "s", $idUser);
mysqli_stmt_execute($stmt);
$resultados = mysqli_stmt_get_result($stmt);
$con->desconectar();

$rtn= [];

while ($fila = mysqli_fetch_row($resultados)) {
$rtn[] = $fila[3];
}
$rtn = mysqli_fetch_row($resultados);

return json_encode($rtn);
}


public function insertNewPartida($idUser, $tab1, $tab2)
{

$tabResuelto= implode(",", $tab1);
$tabJugando= implode(",", $tab2);

$con = new Conexion();
$con->conectar();

$consulta = "INSERT INTO " . Constantes::$TABLE_partida . " (idUsuario, jugando ,resuelto, resultado) VALUES (?, ?, ?, 0)";

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


$stmt->bind_param("iss", $idUser, $tabJugando, $tabResuelto);

$stmt->execute();
$con->desconectar();
}

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

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

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

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

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

$rtnResultado = $resultados->fetch_array();

$con->desconectar();

return $rtnResultado;
}

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

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

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

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

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

$rtnResultado = $resultados->fetch_array();

$con->desconectar();

return $rtnResultado;
}
}
Loading

0 comments on commit 78e03f6

Please sign in to comment.