2020-12-18 20:29:24 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
class User extends Model
|
|
|
|
{
|
|
|
|
private $data;
|
|
|
|
|
|
|
|
public function __construct($data = null)
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
$_col = get_class()::getColumns();
|
|
|
|
if($data !== null){
|
|
|
|
forEach($data as $key=>$value){
|
|
|
|
if(!key_exists($key, $_col)){
|
|
|
|
throw new Exception('Invalid data entry');
|
|
|
|
}else{
|
|
|
|
$this->data[$key] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Getters
|
|
|
|
*/
|
2020-12-20 03:56:05 +01:00
|
|
|
public function getEmail(): string
|
|
|
|
{
|
2020-12-18 20:29:24 +01:00
|
|
|
if(isset($this->data['email']))
|
|
|
|
return $this->data['email'];
|
|
|
|
return false;
|
|
|
|
}
|
2020-12-20 03:56:05 +01:00
|
|
|
public function getFirstName(): string
|
|
|
|
{
|
2020-12-18 20:29:24 +01:00
|
|
|
if(isset($this->data['firstName']))
|
|
|
|
return $this->data['firstName'];
|
|
|
|
return false;
|
|
|
|
}
|
2020-12-20 03:56:05 +01:00
|
|
|
public function getLastName(): string
|
|
|
|
{
|
2020-12-18 20:29:24 +01:00
|
|
|
if(isset($this->data['lastName']))
|
|
|
|
return $this->data['lastName'];
|
|
|
|
return false;
|
|
|
|
}
|
2020-12-20 03:56:05 +01:00
|
|
|
public function getPhoneNumber(): string
|
|
|
|
{
|
2020-12-18 20:29:24 +01:00
|
|
|
if(isset($this->data['phoneNumber']))
|
|
|
|
return $this->data['phoneNumber'];
|
|
|
|
return false;
|
|
|
|
}
|
2020-12-20 03:56:05 +01:00
|
|
|
public function getType(): string
|
|
|
|
{
|
|
|
|
if(isset($this->data['UserTypeName']))
|
|
|
|
return $this->data['UserTypeName'];
|
|
|
|
return false;
|
2020-12-18 20:29:24 +01:00
|
|
|
}
|
2020-12-20 03:56:05 +01:00
|
|
|
public function getAccomodationId(): string
|
|
|
|
{
|
|
|
|
if(isset($this->data['AccomodationId']))
|
|
|
|
return $this->data['AccomodationId'];
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Session
|
|
|
|
*/
|
2021-01-11 17:30:13 +01:00
|
|
|
public function refresh(): void
|
2020-12-20 03:56:05 +01:00
|
|
|
{
|
|
|
|
if (isset($this->data['email'])){
|
|
|
|
$exist = User::fetch(array(['email','=',$this->data['email']]));
|
|
|
|
if(count($exist) === 1){
|
2020-12-20 04:25:09 +01:00
|
|
|
$_SESSION['USER'] = $exist[0];
|
2020-12-20 03:56:05 +01:00
|
|
|
}else{
|
|
|
|
/*
|
|
|
|
* Account must have been deleted
|
|
|
|
*/
|
|
|
|
$_SESSION = array();
|
|
|
|
session_destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function isLoggedIn(): bool
|
|
|
|
{
|
|
|
|
return (isset($this->data['email']));
|
|
|
|
}
|
2020-12-18 20:29:24 +01:00
|
|
|
}
|