1
0
Fork 0

Completed Routing and Added User sessions updates

This commit is contained in:
p1907961 2020-12-20 04:25:09 +01:00
parent c276e3ff58
commit 86dc860290
6 changed files with 47 additions and 9 deletions

View file

@ -3,10 +3,21 @@ if($_SESSION['USER']->isLoggedIn()) {
if(isset($path[1])) { if(isset($path[1])) {
switch ($path[1]) { switch ($path[1]) {
case 'add': 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; break;
case 'edit': 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; break;
default: default:
redirect(); redirect();

View file

@ -21,7 +21,7 @@ class Accomodation extends Model
return $this; return $this;
} }
public static function getByUser(User $user) public static function fetchByUser(User $user)
{ {
if($user->getAccomodationId()) { if($user->getAccomodationId()) {
$data = Accomodation::fetch(array(['id','=', $user->getAccomodationId()])); $data = Accomodation::fetch(array(['id','=', $user->getAccomodationId()]));

View file

@ -3,5 +3,28 @@
class AccomodationServices extends Model 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;
}
} }

View file

@ -68,7 +68,7 @@ class User extends Model
if (isset($this->data['email'])){ if (isset($this->data['email'])){
$exist = User::fetch(array(['email','=',$this->data['email']])); $exist = User::fetch(array(['email','=',$this->data['email']]));
if(count($exist) === 1){ if(count($exist) === 1){
$_SESSION['USER'] = $exist[0];
}else{ }else{
/* /*
* Account must have been deleted * Account must have been deleted

View file

@ -2,7 +2,7 @@
require_once('template/head.php'); require_once('template/head.php');
?> ?>
<div class="container-fluid section"> <div class="container-fluid section">
<h1>Bienvenue M. <?=htmlspecialchars(strtoupper($_SESSION['user']->getLastName()))?>,</h1> <h1>Bienvenue M. <?=htmlspecialchars(strtoupper($_SESSION['USER']->getLastName()))?>,</h1>
<h2>Il semblerait que vous n'ayez pas encore ajouté d'hebergement...</h2> <h2>Il semblerait que vous n'ayez pas encore ajouté d'hebergement...</h2>
</div> </div>
<div class="container-fluid section"> <div class="container-fluid section">
@ -39,12 +39,13 @@ require_once('template/head.php');
<label for="typeSelect">Quels services proposez-vous ?</label><br> <label for="typeSelect">Quels services proposez-vous ?</label><br>
<?php <?php
$c = 0; $c = 0;
foreach ($services as $service){ foreach ($services as $service){
$c++; $c++;
?> ?>
<div class="form-check form-check-inline"> <div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="inlineCheckbox<?=$c?>" value="<?=htmlspecialchars($service['name'])?>"> <input class="form-check-input" type="checkbox" id="inlineCheckbox<?=$c?>" value="<?=htmlspecialchars($service->getName())?>">
<label class="form-check-label" for="inlineCheckbox<?=$c?>"><?=htmlspecialchars($service['name'])?></label> <label class="form-check-label" for="inlineCheckbox<?=$c?>"><?=htmlspecialchars($service->getName())?></label>
</div> </div>
<?php <?php
} }

View file

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