Commit initial
This commit is contained in:
75
server/webplatform/apps/CameraMonitor/Model/ModelUser.php
Normal file
75
server/webplatform/apps/CameraMonitor/Model/ModelUser.php
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user