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])) {
switch ($path[1]) {
case 'add':
if(!$_SESSION['USER']->getAccomodationId())
{
$services = AccomodationServices::fetch();
require_once(VIEW_PATH.$path[1] . '_' . $path[0].'.php');
}else{
redirect();
}
break;
case 'edit':
if($_SESSION['USER']->getAccomodationId())
{
require_once(VIEW_PATH.$path[1] . '_' . $path[0].'.php');
}else{
redirect();
}
break;
default:
redirect();

View file

@ -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()]));

View file

@ -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;
}
}

View file

@ -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

View file

@ -2,7 +2,7 @@
require_once('template/head.php');
?>
<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>
</div>
<div class="container-fluid section">
@ -39,12 +39,13 @@ require_once('template/head.php');
<label for="typeSelect">Quels services proposez-vous ?</label><br>
<?php
$c = 0;
foreach ($services as $service){
$c++;
?>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="inlineCheckbox<?=$c?>" value="<?=htmlspecialchars($service['name'])?>">
<label class="form-check-label" for="inlineCheckbox<?=$c?>"><?=htmlspecialchars($service['name'])?></label>
<input class="form-check-input" type="checkbox" id="inlineCheckbox<?=$c?>" value="<?=htmlspecialchars($service->getName())?>">
<label class="form-check-label" for="inlineCheckbox<?=$c?>"><?=htmlspecialchars($service->getName())?></label>
</div>
<?php
}

View file

@ -14,8 +14,11 @@
if($_SESSION['USER']->isLoggedIn()){
switch($_SESSION['USER']->getType()){
case 'AccomodationOwner':
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'));