fix(reservation) : allow admins to see reservation even if not owner
This commit is contained in:
parent
d9c50325ad
commit
2eec407143
1 changed files with 80 additions and 76 deletions
|
@ -1,13 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use YesWiki\Bazar\Service\EntryManager;
|
use YesWiki\Bazar\Service\EntryManager;
|
||||||
|
|
||||||
setlocale(LC_ALL, 'fr_FR.UTF8', 'fr_FR','fr','fr','fra','fr_FR@euro');
|
setlocale(LC_ALL, 'fr_FR.UTF8', 'fr_FR', 'fr', 'fr', 'fra', 'fr_FR@euro');
|
||||||
setlocale(LC_TIME, "fr_FR");
|
setlocale(LC_TIME, "fr_FR");
|
||||||
function calculateFreePlaces($fiche) {
|
function calculateFreePlaces($fiche)
|
||||||
|
{
|
||||||
//dump($fiche);
|
//dump($fiche);
|
||||||
$entries = $GLOBALS['wiki']->services->get(EntryManager::class)->search(
|
$entries = $GLOBALS['wiki']->services->get(EntryManager::class)->search(
|
||||||
[
|
[
|
||||||
'queries' => ['trajet'=> $fiche['id_fiche']],
|
'queries' => ['trajet' => $fiche['id_fiche']],
|
||||||
'formsIds' => [6],
|
'formsIds' => [6],
|
||||||
'keywords' => '',
|
'keywords' => '',
|
||||||
'user' => '',
|
'user' => '',
|
||||||
|
@ -21,7 +23,8 @@ function calculateFreePlaces($fiche) {
|
||||||
$nbres = count($entries);
|
$nbres = count($entries);
|
||||||
return (int) $fiche['capacite_de_transport'] - (int) $nbres;
|
return (int) $fiche['capacite_de_transport'] - (int) $nbres;
|
||||||
}
|
}
|
||||||
function getStatus($fiche, $consultable = false) {
|
function getStatus($fiche, $consultable = false)
|
||||||
|
{
|
||||||
$dateFermeture = date(DATE_W3C, strtotime("-1 days", strtotime($fiche['date_du_trajet'])));
|
$dateFermeture = date(DATE_W3C, strtotime("-1 days", strtotime($fiche['date_du_trajet'])));
|
||||||
$dateContrainte = !empty($fiche['bf_contrainte_date']) ? date(DATE_W3C, strtotime($fiche['bf_contrainte_date'])) : null;
|
$dateContrainte = !empty($fiche['bf_contrainte_date']) ? date(DATE_W3C, strtotime($fiche['bf_contrainte_date'])) : null;
|
||||||
if (!empty($dateContrainte)) {
|
if (!empty($dateContrainte)) {
|
||||||
|
@ -29,11 +32,11 @@ function getStatus($fiche, $consultable = false) {
|
||||||
}
|
}
|
||||||
$dateDisparition = date(DATE_W3C, strtotime("+1 hour", strtotime($fiche['date_du_trajet'])));
|
$dateDisparition = date(DATE_W3C, strtotime("+1 hour", strtotime($fiche['date_du_trajet'])));
|
||||||
$dateJour = date(DATE_W3C);
|
$dateJour = date(DATE_W3C);
|
||||||
if (!empty($dateContrainte) && $dateJour<$dateContrainte) {
|
if (!empty($dateContrainte) && $dateJour < $dateContrainte) {
|
||||||
$status = 'Ouvert';
|
$status = 'Ouvert';
|
||||||
} elseif ($dateJour<$dateFermeture) {
|
} elseif ($dateJour < $dateFermeture) {
|
||||||
$status = 'Ouvert';
|
$status = 'Ouvert';
|
||||||
} elseif ($dateJour<$dateDisparition) {
|
} elseif ($dateJour < $dateDisparition) {
|
||||||
$status = 'Fermé';
|
$status = 'Fermé';
|
||||||
} else {
|
} else {
|
||||||
if (!$consultable) {
|
if (!$consultable) {
|
||||||
|
@ -45,18 +48,19 @@ function getStatus($fiche, $consultable = false) {
|
||||||
return $status;
|
return $status;
|
||||||
}
|
}
|
||||||
|
|
||||||
function displayReservation($fiche) {
|
function displayReservation($fiche)
|
||||||
|
{
|
||||||
$output = '';
|
$output = '';
|
||||||
$isProducteur = ($GLOBALS['wiki']->GetUserName() == $GLOBALS['wiki']->GetPageOwner($fiche['listefiche8producteur']));
|
$isProducteur = ($GLOBALS['wiki']->GetUserName() == $GLOBALS['wiki']->GetPageOwner($fiche['listefiche8producteur']));
|
||||||
$status = getStatus($fiche, $GLOBALS['wiki']->UserIsOwner($fiche['id_fiche']) || $isProducteur);
|
$status = getStatus($fiche, $GLOBALS['wiki']->UserIsOwner($fiche['id_fiche']) || $isProducteur);
|
||||||
if ($status == 'Fini consultable' || $status == 'Ouvert' || $status == 'Fermé' ) {
|
if ($status == 'Fini consultable' || $status == 'Ouvert' || $status == 'Fermé') {
|
||||||
// récuperer la fiche producteur
|
// récuperer la fiche producteur
|
||||||
$producteur = baz_valeurs_fiche($fiche['listefiche8producteur']);
|
$producteur = baz_valeurs_fiche($fiche['listefiche8producteur']);
|
||||||
$placesrestantes = calculateFreePlaces($fiche);
|
$placesrestantes = calculateFreePlaces($fiche);
|
||||||
if ($GLOBALS['wiki']->UserIsOwner($fiche['id_fiche']) || $isProducteur) {
|
if ($GLOBALS['wiki']->UserIsOwner($fiche['id_fiche']) || $isProducteur || $GLOBALS['wiki']->UserIsAdmin()) {
|
||||||
$entries = $GLOBALS['wiki']->services->get(EntryManager::class)->search(
|
$entries = $GLOBALS['wiki']->services->get(EntryManager::class)->search(
|
||||||
[
|
[
|
||||||
'queries' => ['trajet'=> $fiche['id_fiche']],
|
'queries' => ['trajet' => $fiche['id_fiche']],
|
||||||
'formsIds' => [6],
|
'formsIds' => [6],
|
||||||
'keywords' => '',
|
'keywords' => '',
|
||||||
'user' => '',
|
'user' => '',
|
||||||
|
@ -70,15 +74,15 @@ function displayReservation($fiche) {
|
||||||
$output .= '<br><strong>Il n\'y a pas encore de personnes qui participent à ce trajet.</strong>';
|
$output .= '<br><strong>Il n\'y a pas encore de personnes qui participent à ce trajet.</strong>';
|
||||||
} else {
|
} else {
|
||||||
$output .= '<br><strong>Liste des personnes qui participent à ce trajet</strong>';
|
$output .= '<br><strong>Liste des personnes qui participent à ce trajet</strong>';
|
||||||
$output .= $GLOBALS['wiki']->Format('{{bazarliste id="6" query="trajet='.$fiche['id_fiche'].'" template="tableau" columnfieldsids=",bf_prenom,bf_nom,bf_telephone,bf_commentaire" {{bazarliste id="6" template="tableau.tpl.html" columnfieldsids=",bf_prenom,bf_nom,bf_telephone,bf_commentaire" search="false" }}');
|
$output .= $GLOBALS['wiki']->Format('{{bazarliste id="6" query="trajet=' . $fiche['id_fiche'] . '" template="tableau" columnfieldsids=",bf_prenom,bf_nom,bf_telephone,bf_commentaire"}}');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($placesrestantes < 1) {
|
if ($placesrestantes < 1) {
|
||||||
$output .= '<a class="disabled btn btn-primary" href="#">Trajet complet</a>';
|
$output .= '<a class="disabled btn btn-primary" href="#">Trajet complet</a>';
|
||||||
} else {
|
} else {
|
||||||
$output .= '<p class="places"><strong>Nombres de places restantes</strong> : '.$placesrestantes.'</p>';
|
$output .= '<p class="places"><strong>Nombres de places restantes</strong> : ' . $placesrestantes . '</p>';
|
||||||
if ($status== 'Ouvert') {
|
if ($status == 'Ouvert') {
|
||||||
$output .= '<a class="btn-participe btn btn-primary" href="'.$GLOBALS['wiki']->href('', 'saisie-participants-trajet', 'trajet='.$fiche['id_fiche'].'&producteur='.urlencode($producteur['id_fiche'])).'"><i class="fa fa-plus"></i> Je profite de ce trajet</a>';
|
$output .= '<a class="btn-participe btn btn-primary" href="' . $GLOBALS['wiki']->href('', 'saisie-participants-trajet', 'trajet=' . $fiche['id_fiche'] . '&producteur=' . urlencode($producteur['id_fiche'])) . '"><i class="fa fa-plus"></i> Je profite de ce trajet</a>';
|
||||||
} else {
|
} else {
|
||||||
$output .= '<a class="disabled btn btn-primary" href="#">Fermé</a>';
|
$output .= '<a class="disabled btn btn-primary" href="#">Fermé</a>';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue