Debud / new function in user_dao.php
This commit is contained in:
parent
4c0522b4a5
commit
042333b96c
@ -6,15 +6,14 @@
|
|||||||
private $_id; //Manager ID.
|
private $_id; //Manager ID.
|
||||||
private $_username; //Manager username.
|
private $_username; //Manager username.
|
||||||
private $_email; //Email.
|
private $_email; //Email.
|
||||||
private $_pass; //Pass.
|
|
||||||
private $_roll; //Roll
|
private $_roll; //Roll
|
||||||
|
|
||||||
//Constructor:
|
//Constructor:
|
||||||
function __construct($id, $username, $email, $pass, $roll){
|
function __construct($id, $idcinema, $username, $email, $roll){
|
||||||
$this->_id = $id;
|
$this->_id = $id;
|
||||||
|
$this->_idcinema = $idcinema;
|
||||||
$this->_username = $username;
|
$this->_username = $username;
|
||||||
$this->_email = $email;
|
$this->_email = $email;
|
||||||
$this->_pass = $pass;
|
|
||||||
$this->_roll = $roll;
|
$this->_roll = $roll;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,14 +22,14 @@
|
|||||||
//Getters && Setters:
|
//Getters && Setters:
|
||||||
public function setId($id){ $this->_id = $id; }
|
public function setId($id){ $this->_id = $id; }
|
||||||
public function getId(){ return $this->_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 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 setEmail($email){$this->_email = $email;}
|
||||||
public function getEmail(){return $this->_email = $email;}
|
public function getEmail(){return $this->_email;}
|
||||||
public function setPass($pass){$this->_pass = $pass;}
|
|
||||||
public function getPass(){return $this->pass;}
|
|
||||||
public function setRoll($roll){$this->_roll = $roll;}
|
public function setRoll($roll){$this->_roll = $roll;}
|
||||||
public function getRoll(){return $this->_roll = $roll;}
|
public function getRoll(){return $this->_roll;}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
@ -12,33 +12,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Methods:
|
//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.
|
//Returns a query to get All the managers.
|
||||||
public function allManagersData(){
|
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');
|
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
|
||||||
|
|
||||||
while($fila=$resul->fetch_assoc()){
|
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();
|
$resul->free();
|
||||||
return $managers;
|
return $managers;
|
||||||
@ -46,12 +27,29 @@
|
|||||||
|
|
||||||
//Returns a manager data .
|
//Returns a manager data .
|
||||||
public function GetManager($id){
|
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');
|
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
|
||||||
return $resul;
|
return $resul;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function selectManager($username){
|
/*public function selectManager($username){
|
||||||
$username = $this->mysqli->real_escape_string($username);
|
$username = $this->mysqli->real_escape_string($username);
|
||||||
|
|
||||||
$sql = sprintf( "SELECT * FROM users WHERE username = '%s'", $username );
|
$sql = sprintf( "SELECT * FROM users WHERE username = '%s'", $username );
|
||||||
@ -66,12 +64,12 @@
|
|||||||
$resul->free();
|
$resul->free();
|
||||||
|
|
||||||
return $user;
|
return $user;
|
||||||
}
|
} */
|
||||||
|
|
||||||
|
|
||||||
//Deleted manager by "id".
|
//Deleted manager by "id".
|
||||||
public function deleteManager($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');
|
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
|
||||||
|
|
||||||
@ -79,11 +77,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Edit manager.
|
//Edit manager.
|
||||||
public function editManager($id, $username, $email, $pass, $rol){
|
public function editManager($id, $idcinema){
|
||||||
$password = $this->encryptPass($pass);
|
$sql = sprintf( "UPDATE `manager` SET manager.idcinema = '%d'
|
||||||
$sql = sprintf( "UPDATE users SET email = '%s' , passwd = '%s',
|
WHERE manager.id = '%d';",
|
||||||
WHERE users.id = '%d';",
|
$idcinema, $id);
|
||||||
$email, $password, $id);
|
|
||||||
|
|
||||||
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
|
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
|
||||||
|
|
||||||
@ -91,8 +88,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Create a new Manager Data Transfer Object.
|
//Create a new Manager Data Transfer Object.
|
||||||
public function loadManager($id, $username, $email, $pass, $rol){
|
public function loadManager($id, $idcinema, $username, $email, $rol){
|
||||||
return new Manager($id, $username, $email, $pass, $rol);
|
return new Manager($id, $idcinema, $username, $email, $rol);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,18 @@
|
|||||||
return password_verify($password, $passwd);
|
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.
|
//Create a new User.
|
||||||
public function createUser($id, $username, $email, $password, $rol){
|
public function createUser($id, $username, $email, $password, $rol){
|
||||||
$password = $this->encryptPass($password);
|
$password = $this->encryptPass($password);
|
||||||
|
Loading…
Reference in New Issue
Block a user