You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
3.4 KiB
116 lines
3.4 KiB
<?php
|
|
namespace Model;
|
|
use Entity\User;
|
|
use Entity\UserEntity;
|
|
use Gateway\UserGateway;
|
|
|
|
class UserModel
|
|
{
|
|
private UserGateway $gateway;
|
|
|
|
public function __construct(UserGateway $gate){
|
|
$this->gateway = $gate;
|
|
}
|
|
|
|
public function insertUser(string $username,string $email,string $passwd) : bool{
|
|
/*global $rep,$image;*/
|
|
return $this->gateway->insertUser($this->getNumberOfUsers() + 1, $username, $email, $passwd, false, 0);
|
|
}
|
|
|
|
public function getNumberOfUsers() : int
|
|
{
|
|
|
|
return $this->gateway->getNumberOfUsers()[0]['count'] ?? 0;
|
|
}
|
|
|
|
public function deleteUser(string $id) : bool{
|
|
return $this->gateway->delete($id);
|
|
}
|
|
|
|
|
|
// public function getFavoriteUser(string $id) : array{
|
|
// $res[0] = array();
|
|
// $data = $this->gateway->getFavorite($id);
|
|
// foreach ($data as $favoris) {
|
|
// $res[0][] = new Quote();
|
|
// }
|
|
// }
|
|
|
|
public function getDataUser(int $id) : ?UserEntity {
|
|
$res = $this->gateway->findDataUser($id);
|
|
if ($res)
|
|
return new UserEntity(
|
|
$res[0]['id_user'],
|
|
$res[0]['username'],
|
|
$res[0]['pssword'],
|
|
$res[0]['email'],
|
|
$res[0]['img_prfl'],
|
|
$res[0]['is_admin'],
|
|
$res[0]['creation']
|
|
);
|
|
return null;
|
|
}
|
|
|
|
public function getUsername(string $username) : ?UserEntity
|
|
{
|
|
$res = $this->gateway->findUsername($username);
|
|
if ($res)
|
|
return new UserEntity(
|
|
$res[0]['id_user'],
|
|
$res[0]['username'],
|
|
$res[0]['pssword'],
|
|
$res[0]['email'],
|
|
$res[0]['img_prfl'],
|
|
$res[0]['is_admin'],
|
|
$res[0]['creation']
|
|
);
|
|
return null;
|
|
}
|
|
|
|
public function getEmail(string $email) : ?UserEntity
|
|
{
|
|
$res = $this->gateway->findEmail($email);
|
|
if ($res)
|
|
return new UserEntity(
|
|
$res[0]['id_user'],
|
|
$res[0]['username'],
|
|
$res[0]['pssword'],
|
|
$res[0]['email'],
|
|
$res[0]['img_prfl'],
|
|
$res[0]['is_admin'],
|
|
$res[0]['creation']
|
|
);
|
|
return null;
|
|
}
|
|
|
|
public function setUsername(int $id, string $newUsername){
|
|
$res = $this->gateway->updateUsername($id,$newUsername);
|
|
$src[] = $res[0]['username'];
|
|
|
|
return $src;
|
|
}
|
|
|
|
public function setEmail(int $id, string $newEmail){
|
|
$res = $this->gateway->updateEmail($id,$newEmail);
|
|
$src[] = $res[0]['email'];
|
|
|
|
return $src;
|
|
}
|
|
|
|
public function setImg(int $id, int $newImg){
|
|
$res = $this->gateway->updateImg($id,$newImg);
|
|
$src[] = $res[0]['img'];
|
|
|
|
return $src;
|
|
}
|
|
|
|
public function setPassWd(int $id, string $newPassWd){
|
|
$res = $this->gateway->updatePasswd($id,$newPassWd);
|
|
$src[] = $res[0]['pssword'];
|
|
|
|
return $src;
|
|
}
|
|
}
|
|
|
|
?>
|