Debud / new function in user_dao.php

This commit is contained in:
Daniel Muñoz Garcia 2021-05-06 12:16:37 +02:00 committed by GitHub
parent 4c0522b4a5
commit 042333b96c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 40 deletions

View File

@ -6,15 +6,14 @@
private $_id; //Manager ID.
private $_username; //Manager username.
private $_email; //Email.
private $_pass; //Pass.
private $_roll; //Roll
//Constructor:
function __construct($id, $username, $email, $pass, $roll){
function __construct($id, $idcinema, $username, $email, $roll){
$this->_id = $id;
$this->_idcinema = $idcinema;
$this->_username = $username;
$this->_email = $email;
$this->_pass = $pass;
$this->_roll = $roll;
}
@ -23,14 +22,14 @@
//Getters && Setters:
public function setId($id){ $this->_id = $id; }
public function getId(){ return $this->_id; }
public function setIdcinema($idcinema){ $this->_idcinema = $idcinema; }
public function getIdcinema(){ return $this->_idcinema; }
public function setUsername($username){$this->_username = $username; }
public function getUsername(){ return $this->_username = $username; }
public function getUsername(){ return $this->_username;}
public function setEmail($email){$this->_email = $email;}
public function getEmail(){return $this->_email = $email;}
public function setPass($pass){$this->_pass = $pass;}
public function getPass(){return $this->pass;}
public function getEmail(){return $this->_email;}
public function setRoll($roll){$this->_roll = $roll;}
public function getRoll(){return $this->_roll = $roll;}
public function getRoll(){return $this->_roll;}
}
?>

View File

@ -12,33 +12,14 @@
}
//Methods:
//Create a new user Manager.
public function createManager($id, $username, $email, $pass, $rol){
$password = $this->encryptPass($pass);
$sql = sprintf( "INSERT INTO `users`( `id`, `username`, `email`, `passwd`, `rol`)
VALUES ( '%d', '%s', '%s', '%s', '%s')",
$id, $username, $email, $password, $rol);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
private function encryptPass($password){
//$password = hash('sha256', $password);
$password = password_hash($password, PASSWORD_DEFAULT);
return $password;
}
//Returns a query to get All the managers.
public function allManagersData(){
$sql = sprintf( "SELECT * FROM users WHERE users.rol=manager");
$sql = sprintf( "SELECT * FROM `users` JOIN `manager` ON manager.id = users.id");
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
while($fila=$resul->fetch_assoc()){
$managers[] = $this->loadManager($fila["id"], $fila["username"], $fila["email"], $fila["password"], $fila["rol"]);
$managers[] = $this->loadManager($fila["id"], $fila["idcinema"], $fila["username"], $fila["email"], $fila["rol"]);
}
$resul->free();
return $managers;
@ -46,12 +27,29 @@
//Returns a manager data .
public function GetManager($id){
$sql = sprintf( "SELECT * FROM users WHERE users.id = '%d'", $id );
$sql = sprintf( "SELECT * FROM `manager` WHERE manager.id = '%d'", $id );
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Returns a manager data .
public function GetManagerCinema($id, $idcinema){
$sql = sprintf( "SELECT * FROM `manager` WHERE manager.id = '%d' AND manager.idcinema ='%d'", $id, $idcinema );
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Create a new Session.
public function createManager($id, $idcinema){
$sql = sprintf( "INSERT INTO `manager`( `id`, `idcinema`)
VALUES ( '%d', '%d')",
$id, $idcinema);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
public function selectManager($username){
/*public function selectManager($username){
$username = $this->mysqli->real_escape_string($username);
$sql = sprintf( "SELECT * FROM users WHERE username = '%s'", $username );
@ -66,12 +64,12 @@
$resul->free();
return $user;
}
} */
//Deleted manager by "id".
public function deleteManager($id){
$sql = sprintf( "DELETE FROM users WHERE users.id = '%d' ;",$id);
$sql = sprintf( "DELETE FROM `manager` WHERE manager.id = '%d' ;",$id);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
@ -79,11 +77,10 @@
}
//Edit manager.
public function editManager($id, $username, $email, $pass, $rol){
$password = $this->encryptPass($pass);
$sql = sprintf( "UPDATE users SET email = '%s' , passwd = '%s',
WHERE users.id = '%d';",
$email, $password, $id);
public function editManager($id, $idcinema){
$sql = sprintf( "UPDATE `manager` SET manager.idcinema = '%d'
WHERE manager.id = '%d';",
$idcinema, $id);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
@ -91,8 +88,8 @@
}
//Create a new Manager Data Transfer Object.
public function loadManager($id, $username, $email, $pass, $rol){
return new Manager($id, $username, $email, $pass, $rol);
public function loadManager($id, $idcinema, $username, $email, $rol){
return new Manager($id, $idcinema, $username, $email, $rol);
}
}

View File

@ -31,6 +31,18 @@
return password_verify($password, $passwd);
}
//All users
public function allUsersNotM(){
$sql = sprintf( "SELECT * FROM `users` WHERE users.id NOT IN (SELECT id FROM `manager`)");
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
while($fila=$resul->fetch_assoc()){
$users[] = $this->loadUser($fila['id'], $fila['username'], $fila['email'], $fila['passwd'], $fila['rol']);
}
$resul->free();
return $users;
}
//Create a new User.
public function createUser($id, $username, $email, $password, $rol){
$password = $this->encryptPass($password);