SW/assets/php/common/manager_dao.php

98 lines
2.9 KiB
PHP
Raw Normal View History

<?php
include_once('manager.php');
$template = new Template();
$prefix = $template->get_prefix();
include_once($prefix.'assets/php/dao.php');
class Manager_DAO extends DAO {
//Constructor:
function __construct($bd_name){
parent::__construct($bd_name);
}
//Methods:
//Returns a query to get All the managers.
public function allManagersData(){
2021-05-06 12:16:37 +02:00
$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()){
2021-05-06 12:16:37 +02:00
$managers[] = $this->loadManager($fila["id"], $fila["idcinema"], $fila["username"], $fila["email"], $fila["rol"]);
}
$resul->free();
return $managers;
}
//Returns a manager data .
public function GetManager($id){
2021-05-06 12:16:37 +02:00
$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;
}
2021-05-06 12:16:37 +02:00
/*public function selectManager($username){
$username = $this->mysqli->real_escape_string($username);
$sql = sprintf( "SELECT * FROM users WHERE username = '%s'", $username );
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
$resul->data_seek(0);
while ($fila = $resul->fetch_assoc()) {
$user = $this->loadUser($fila['id'], $fila['username'], $fila['email'], $fila['passwd'], $fila['rol']);
}
//mysqli_free_result($selectUser);
$resul->free();
return $user;
2021-05-06 12:16:37 +02:00
} */
//Deleted manager by "id".
public function deleteManager($id){
2021-05-06 12:16:37 +02:00
$sql = sprintf( "DELETE FROM `manager` WHERE manager.id = '%d' ;",$id);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Edit manager.
2021-05-06 12:16:37 +02:00
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');
return $resul;
}
//Create a new Manager Data Transfer Object.
2021-05-06 12:16:37 +02:00
public function loadManager($id, $idcinema, $username, $email, $rol){
return new Manager($id, $idcinema, $username, $email, $rol);
}
}
?>