Commit initial

This commit is contained in:
2020-05-15 12:27:34 +02:00
commit 70f72f2e54
87 changed files with 12684 additions and 0 deletions

View File

@ -0,0 +1,122 @@
<?php
class Camera
{
private $id;
private $name;
private $product_key;
private $available;
private $enabled;
private $rtmp_handle;
function __construct($id, $name, $product_key, $available, $enabled, $rtmp_handle)
{
$this->name = $name;
$this->available = $available;
$this->enabled = $enabled;
$this->id = $id;
$this->product_key = $product_key;
$this->rtmp_handle = $rtmp_handle;
}
/**
* @return mixed
*/
public function getRtmpHandle()
{
return $this->rtmp_handle;
}
/**
* @param mixed $rtmp_handle
*/
public function setRtmpHandle($rtmp_handle)
{
$this->rtmp_handle = $rtmp_handle;
}
/**
* @return mixed
*/
public function getProductKey()
{
return $this->product_key;
}
/**
* @param mixed $product_key
*/
public function setProductKey($product_key)
{
$this->product_key = $product_key;
}
/**
* @return mixed
*/
public function getName()
{
return $this->name;
}
/**
* @param mixed $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* @return mixed
*/
public function getAvailable()
{
return $this->available;
}
/**
* @param mixed $available
*/
public function setAvailable($available)
{
$this->available = $available;
}
/**
* @return mixed
*/
public function getEnabled()
{
return $this->enabled;
}
/**
* @param mixed $enabled
*/
public function setEnabled($enabled)
{
$this->enabled = $enabled;
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @param mixed $id
*/
public function setId($id)
{
$this->id = $id;
}
}
?>

View File

@ -0,0 +1,64 @@
<?php
class User {
private $id;
private $login;
private $password;
public function __construct($id, $login, $password) {
$this->id = $id;
$this->login = $login;
$this->password = $password;
}
/**
* @return mixed
*/
public function getLogin()
{
return $this->login;
}
/**
* @param mixed $login
*/
public function setLogin($login)
{
$this->login = $login;
}
/**
* @return mixed
*/
public function getPassword()
{
return $this->password;
}
/**
* @param mixed $password
*/
public function setPassword($password)
{
$this->password = $password;
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @param mixed $id
*/
public function setId($id)
{
$this->id = $id;
}
}

View File

@ -0,0 +1,85 @@
<?php
require_once $GLOBALS['app_path'].'Framework/Model.php';
require_once $GLOBALS['app_path'].'Model/Entity/Camera.php';
class ModelCamera extends Model{
public function getCamera($camera_id, $user_id)
{
$sql = "select * from camera where id=?";
$result = $this->executeRequest($sql, array($camera_id));
if ( $result->rowCount() == 1)
{
$result = $result->fetch();
$name = $this->getNameCameraByUser($user_id, $camera_id);
return new Camera($result['id'], $name, $result['product_key'],$result['available'],$result['enabled'],$result['rtmp_handle']);
}
else
throw new Exception("Aucune caméra ne correspond à cet identifiant");
}
public function getNameCameraByUser($user_id, $camera_id)
{
$sql = "select name from user_camera where user_id=? and camera_id=?";
$result = $this->executeRequest($sql, array($user_id, $camera_id));
if($result->rowCount() == 1)
return $result->fetch()['name'];
else
throw new Exception("Cet utilisateur n'as pas accès à cet caméra");
}
public function addCamera($id, $product_key, $available, $enabled, $rtmp_handle)
{
$sql = "insert into camera values(?,?,?,?,?)";
$this->executeRequest($sql, array($id, $product_key, $available, $enabled, $rtmp_handle));
}
public function getAllCameraByUser($user_id)
{
$sql = "select * from user_camera where user_id=?";
$result = $this->executeRequest($sql, array($user_id));
$result = $result->fetchAll();
$cameras = null;
foreach($result as $cam)
{
$cameras[] = $this->getCamera($cam['camera_id'], $user_id);
}
return $cameras;
}
public function userCanAccessCam($user_id, $camera_id)
{
$sql = "select name from user_camera where user_id=? and camera_id=?";
$result = $this->executeRequest($sql, array($user_id, $camera_id));
return $result->rowCount() == 1;
}
public function delete($id)
{
$sql = "delete from camera where id=?";
$this->executeRequest($sql,array($id));
}
public function exist($camera_id)
{
$sql = "select * from camera where id=? ";
$result = $this->executeRequest($sql, array($camera_id));
return ($result->rowCount() == 1);
}
public function getCameraOnly($camera_id)
{
$sql = "select * from camera where id=?";
$result = $this->executeRequest($sql, array($camera_id));
if ( $result->rowCount() == 1)
{
$result = $result->fetch();
return new Camera($result['id'], "", $result['product_key'],$result['available'],$result['enabled'],$result['rtmp_handle']);
}
else
throw new Exception("Aucune caméra ne correspond à cet identifiant");
}
}

View File

@ -0,0 +1,75 @@
<?php
require_once $GLOBALS['app_path'].'Framework/Model.php';
require_once $GLOBALS['app_path'].'Model/Entity/User.php';
class ModelUser extends Model{
public function exist($login, $password)
{
$sql = "select id from user where login=? and password=?";
$user = $this->executeRequest($sql, array($login, $password));
return ($user->rowCount() == 1);
}
public function getUser($login, $password)
{
$sql = "select * from user where login=? and password=?";
$result = $this->executeRequest($sql, array($login, $password));
if ( $result->rowCount() == 1)
{
$result = $result->fetch();
return new User($result['id'],$result['login'],$result['password']);
}
else
throw new Exception("Aucun utilisateur ne correspond aux identifiants fournis");
}
public function addUser($login, $password)
{
$sql = "insert into user values('',?,?)";
$this->executeRequest($sql, array($login, $password));
}
public function getUserById($id)
{
$sql = "select * from user where id=?";
$result = $this->executeRequest($sql, array($id));
if ( $result->rowCount() == 1)
{
$result = $result->fetch();
return new User($result['id'],$result['login'],$result['password']);
}
else
throw new Exception("Aucun utilisateur ne correspond à l'id fournis");
}
public function update($id,$login,$password)
{
$sql = "update user Set login=?, password=? where id=?";
$this->executeRequest($sql, array($login,$password,$id));
}
public function deleteCam($user_id, $camera_id)
{
$sql = "delete from user_camera where user_id=? and camera_id=?";
$this->executeRequest($sql,array($user_id,$camera_id));
}
public function addCam($user_id, $camera_id, $name)
{
$sql = "insert into user_camera values(?,?,?)";
$this->executeRequest($sql, array($user_id, $camera_id, $name));
}
public function haveCam($user_id, $camera_id)
{
$sql = "select * from user_camera where user_id=? and camera_id=?";
$result = $this->executeRequest($sql,array($user_id, $camera_id));
if($result->rowCount() == 1)
return true;
return false;
}
}