<?php
|
|
class MySQLDao {
|
|
var $dbhost = null;
|
|
var $dbuser = null;
|
|
var $dbpass = null;
|
|
var $conn = null;
|
|
var $dbname = null;
|
|
var $result = null;
|
|
|
|
public function dameListaEntrenadores()
|
|
{
|
|
$arrayFinal = array();
|
|
|
|
$result = $this->conn->query("SELECT IdUsuario,Nombre,Apellidos,Mail FROM Usuarios WHERE Tipo = 'E'");
|
|
|
|
if ($result != null && (mysqli_num_rows($result) >= 1)) {
|
|
$longi = mysqli_num_rows($result);
|
|
while($row = $result->fetch_array(MYSQLI_ASSOC)) {
|
|
$subArray = array();
|
|
$subArray['IdUsuario'] = $row['IdUsuario'];
|
|
$subArray['Nombre'] = $row['Nombre'];
|
|
$subArray['Apellidos'] = $row['Apellidos'];
|
|
$subArray['Mail'] = $row['Mail'];
|
|
|
|
array_push($arrayFinal,$subArray);//empujamos un nuevo elemento al array
|
|
}
|
|
}
|
|
return $arrayFinal;
|
|
|
|
}
|
|
|
|
public function buscaDeportistas($email)
|
|
{
|
|
// $email es el Mail del Entrenador
|
|
|
|
$arrayFinal = array();
|
|
|
|
$idEntrenador = $this->getUserId($email);
|
|
|
|
$result = $this->conn->query("SELECT IdUsuario,Nombre,Apellidos FROM Usuarios WHERE IdEntrenador = ".$idEntrenador);
|
|
// Para probar, devuelto todos los registros
|
|
//$result = $this->conn->query("SELECT IdUsuario,Nombre,Apellidos FROM Usuarios WHERE 1");
|
|
|
|
if ($result != null && (mysqli_num_rows($result) >= 1)) {
|
|
$longi = mysqli_num_rows($result);
|
|
while($row = $result->fetch_array(MYSQLI_ASSOC)) {
|
|
$subArray = array();
|
|
$subArray['IdUsuario'] = $row['IdUsuario'];
|
|
$subArray['Nombre'] = $row['Nombre'];
|
|
$subArray['Apellidos'] = $row['Apellidos'];
|
|
|
|
array_push($arrayFinal,$subArray);//empujamos un nuevo elemento al array
|
|
}
|
|
}
|
|
return $arrayFinal;
|
|
}
|
|
|
|
public function buscaMacroCiclos($deportista, $entrenador)
|
|
{
|
|
|
|
$arrayFinal = array();
|
|
|
|
$result = $this->conn->query("SELECT IdMacrociclo,Nombre,Tipo,Desde,Hasta FROM Macrociclos WHERE IdEntrenador = ".$entrenador. " and IdDeportista = ".$deportista." ORDER by Desde ASC");
|
|
// Para probar, devuelto todos los registros
|
|
//$result = $this->conn->query("SELECT IdMacrociclo,Nombre,Tipo FROM Macrociclos WHERE 1");
|
|
|
|
if ($result != null && (mysqli_num_rows($result) >= 1)) {
|
|
$longi = mysqli_num_rows($result);
|
|
while($row = $result->fetch_array(MYSQLI_ASSOC)) {
|
|
$subArray = array();
|
|
$subArray['IdMacrociclo'] = $row['IdMacrociclo'];
|
|
$subArray['Nombre'] = $row['Nombre'];
|
|
$subArray['Tipo'] = $row['Tipo'];
|
|
$subArray['Desde'] = $row['Desde'];
|
|
$subArray['Hasta'] = $row['Hasta'];
|
|
|
|
|
|
array_push($arrayFinal,$subArray);//empujamos un nuevo elemento al array
|
|
}
|
|
}
|
|
return $arrayFinal;
|
|
|
|
}
|
|
|
|
public function cualEsMientrenador($email)
|
|
{
|
|
$arrayFinal = array();
|
|
|
|
$sql = "select IdEntrenador from Usuarios where Mail='" . $email . "'";
|
|
$result = $this->conn->query($sql);
|
|
if ($result != null && (mysqli_num_rows($result) >= 1)) {
|
|
$row = $result->fetch_array(MYSQLI_ASSOC);
|
|
if (!empty($row)) {
|
|
/*
|
|
$subArray = array();
|
|
|
|
$subArray["IdEntrenador"] = $row["IdEntrenador"];
|
|
array_push($arrayFinal,$subArray);
|
|
*/
|
|
$arrayFinal["IdEntrenador"] = $row["IdEntrenador"];
|
|
}
|
|
}
|
|
return $arrayFinal;
|
|
}
|
|
|
|
public function getUserId($email)
|
|
{
|
|
$id = -1;
|
|
$sql = "select IdUsuario from Usuarios where Mail='" . $email . "'";
|
|
$result = $this->conn->query($sql);
|
|
if ($result != null && (mysqli_num_rows($result) >= 1)) {
|
|
$row = $result->fetch_array(MYSQLI_ASSOC);
|
|
if (!empty($row)) {
|
|
$id = $row["IdUsuario"];
|
|
}
|
|
}
|
|
return $id;
|
|
}
|
|
|
|
public function insertaUsuarioEnDeportistas($email)
|
|
{
|
|
$id = $this->getUserId($email);
|
|
|
|
$sql = "insert into Deportistas set Id=?,IdEntrenador=0";
|
|
$statement = $this->conn->prepare($sql);
|
|
|
|
if (!$statement)
|
|
throw new Exception($statement->error);
|
|
|
|
$statement->bind_param("i",$id);
|
|
$returnValue = $statement->execute();
|
|
|
|
return $returnValue;
|
|
}
|
|
|
|
public function insertaMacrociclo($nombre,$desde,$hasta,$tipo,$deportista,$entrenador)
|
|
{
|
|
$sql = "insert into Macrociclos set Nombre=?,Desde=?,Hasta=?,Tipo=?,idDeportista=?,idEntrenador=?";
|
|
$statement = $this->conn->prepare($sql);
|
|
|
|
if (!$statement)
|
|
throw new Exception($statement->error);
|
|
|
|
$statement->bind_param("ssssss",$nombre,$desde,$hasta,$tipo,$deportista,$entrenador);
|
|
|
|
$returnValue = $statement->execute();
|
|
|
|
return $returnValue;
|
|
|
|
}
|
|
|
|
|
|
public function insertaUsuarioEnEntrenadores($email)
|
|
{
|
|
$id = $this->getUserId($email);
|
|
|
|
$sql = "insert into Entrenadores set Id=?";
|
|
$statement = $this->conn->prepare($sql);
|
|
|
|
if (!$statement)
|
|
throw new Exception($statement->error);
|
|
|
|
$statement->bind_param("i",$id);
|
|
$returnValue = $statement->execute();
|
|
|
|
return $returnValue;
|
|
|
|
}
|
|
|
|
function __construct() {
|
|
$this->dbhost = Conn::$dbhost;
|
|
$this->dbuser = Conn::$dbuser;
|
|
$this->dbpass = Conn::$dbpass;
|
|
$this->dbname = Conn::$dbname;
|
|
}
|
|
|
|
public function openConnection() {
|
|
$this->conn = new mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname);
|
|
if (mysqli_connect_errno())
|
|
echo new Exception("No pude establecer conexión con la base de datos");
|
|
}
|
|
|
|
public function getConnection() {
|
|
return $this->conn;
|
|
}
|
|
|
|
public function closeConnection() {
|
|
if ($this->conn != null)
|
|
$this->conn->close();
|
|
}
|
|
|
|
public function getUserDetails($email)
|
|
{
|
|
$returnValue = array();
|
|
$sql = "select * from Usuarios where Mail='" . $email . "'";
|
|
|
|
$result = $this->conn->query($sql);
|
|
if ($result != null && (mysqli_num_rows($result) >= 1)) {
|
|
$row = $result->fetch_array(MYSQLI_ASSOC);
|
|
if (!empty($row)) {
|
|
$returnValue = $row;
|
|
}
|
|
}
|
|
return $returnValue;
|
|
}
|
|
|
|
public function getEntrenadorById($idUsuario)
|
|
{
|
|
$returnValue = array();
|
|
$sql = "select * from Usuarios where IdUsuario='" . $idUsuario . "' and Tipo='E'";
|
|
|
|
$result = $this->conn->query($sql);
|
|
if ($result != null && (mysqli_num_rows($result) >= 1)) {
|
|
$row = $result->fetch_array(MYSQLI_ASSOC);
|
|
if (!empty($row)) {
|
|
$returnValue = $row;
|
|
}
|
|
}
|
|
return $returnValue;
|
|
}
|
|
|
|
public function ponIdEntrenador($email,$entrenador)
|
|
{
|
|
$sql = "UPDATE Usuarios SET IdEntrenador=? WHERE Mail=?";
|
|
|
|
$statement = $this->conn->prepare($sql);
|
|
|
|
if (!$statement)
|
|
throw new Exception($statement->error);
|
|
|
|
$statement->bind_param("ss",$entrenador,$email);
|
|
$returnValue = $statement->execute();
|
|
|
|
return $returnValue;
|
|
}
|
|
|
|
public function getUserDetailsWithPassword($email, $userPassword)
|
|
{
|
|
$returnValue = array();
|
|
$sql = "select * from Usuarios where Mail='" . $email . "' and Password='" .$userPassword . "'";
|
|
|
|
$result = $this->conn->query($sql);
|
|
if ($result != null && (mysqli_num_rows($result) >= 1)) {
|
|
$row = $result->fetch_array(MYSQLI_ASSOC);
|
|
if (!empty($row)) {
|
|
$returnValue = $row;
|
|
}
|
|
}
|
|
return $returnValue;
|
|
}
|
|
|
|
public function registerUser($tipo,$nombre,$apellidos,$alias,$telefono,$email,$password,$genero)
|
|
{
|
|
$sql = "insert into Usuarios set Tipo=?,Nombre=?, Apellidos=?,Alias=?,Telefono=?, Mail=?, Password=?, Genero=?";
|
|
$statement = $this->conn->prepare($sql);
|
|
|
|
if (!$statement)
|
|
throw new Exception($statement->error);
|
|
|
|
$statement->bind_param("ssssssss",$tipo,$nombre,$apellidos,$alias,$telefono,$email,$password,$genero);
|
|
$returnValue = $statement->execute();
|
|
|
|
if($tipo=="D") {
|
|
$this->insertaUsuarioEnDeportistas($email);
|
|
} else {
|
|
$this->insertaUsuarioEnEntrenadores($email);
|
|
}
|
|
|
|
return $returnValue;
|
|
}
|
|
}
|
|
?>
|