diff --git a/controller/accomodation.php b/controller/accomodation.php index 60c0165..6b5f211 100644 --- a/controller/accomodation.php +++ b/controller/accomodation.php @@ -3,10 +3,21 @@ if($_SESSION['USER']->isLoggedIn()) { if(isset($path[1])) { switch ($path[1]) { case 'add': - require_once(VIEW_PATH.$path[1] . '_' . $path[0].'.php'); + if(!$_SESSION['USER']->getAccomodationId()) + { + $services = AccomodationServices::fetch(); + require_once(VIEW_PATH.$path[1] . '_' . $path[0].'.php'); + }else{ + redirect(); + } break; case 'edit': - require_once(VIEW_PATH.$path[1] . '_' . $path[0].'.php'); + if($_SESSION['USER']->getAccomodationId()) + { + require_once(VIEW_PATH.$path[1] . '_' . $path[0].'.php'); + }else{ + redirect(); + } break; default: redirect(); diff --git a/models/Accomodation.php b/models/Accomodation.php index 2805194..627b208 100644 --- a/models/Accomodation.php +++ b/models/Accomodation.php @@ -21,7 +21,7 @@ class Accomodation extends Model return $this; } - public static function getByUser(User $user) + public static function fetchByUser(User $user) { if($user->getAccomodationId()) { $data = Accomodation::fetch(array(['id','=', $user->getAccomodationId()])); diff --git a/models/AccomodationServices.php b/models/AccomodationServices.php index 556636d..92a8274 100644 --- a/models/AccomodationServices.php +++ b/models/AccomodationServices.php @@ -3,5 +3,28 @@ class AccomodationServices 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; + } + + public function getName(): string + { + if(isset($this->data['name'])) + return $this->data['name']; + return false; + } } \ No newline at end of file diff --git a/models/User.php b/models/User.php index 44562f2..b5170a4 100644 --- a/models/User.php +++ b/models/User.php @@ -68,7 +68,7 @@ class User extends Model if (isset($this->data['email'])){ $exist = User::fetch(array(['email','=',$this->data['email']])); if(count($exist) === 1){ - + $_SESSION['USER'] = $exist[0]; }else{ /* * Account must have been deleted diff --git a/view/add_accomodation.php b/view/add_accomodation.php index 2170524..de5efae 100644 --- a/view/add_accomodation.php +++ b/view/add_accomodation.php @@ -2,7 +2,7 @@ require_once('template/head.php'); ?>
-

Bienvenue M. getLastName()))?>,

+

Bienvenue M. getLastName()))?>,

Il semblerait que vous n'ayez pas encore ajouté d'hebergement...

@@ -39,12 +39,13 @@ require_once('template/head.php');
- - + +
isLoggedIn()){ switch($_SESSION['USER']->getType()){ case 'AccomodationOwner': - echo navItem('Ajout Hebergement',genURL('accomodation/add')); - echo navItem('Edition de l\'hebergement',genURL('accomodation/edit')); + if(!$_SESSION['USER']->getAccomodationId()){ + echo navItem('Ajout Hebergement',genURL('accomodation/add')); + } else { + echo navItem('Edition de l\'hebergement', genURL('accomodation/edit')); + } break; case 'Staff': echo navItem('Gestion des disponibilités',genURL('accomodation/manager'));