fix(reservation) : allow admins to see reservation even if not owner

This commit is contained in:
Florian Schmitt 2024-01-15 11:51:57 +03:00
parent d9c50325ad
commit 2eec407143

View file

@ -1,9 +1,11 @@
<?php
use YesWiki\Bazar\Service\EntryManager;
setlocale(LC_ALL, 'fr_FR.UTF8', 'fr_FR', 'fr', 'fr', 'fra', 'fr_FR@euro');
setlocale(LC_TIME, "fr_FR");
function calculateFreePlaces($fiche) {
function calculateFreePlaces($fiche)
{
//dump($fiche);
$entries = $GLOBALS['wiki']->services->get(EntryManager::class)->search(
[
@ -21,7 +23,8 @@ function calculateFreePlaces($fiche) {
$nbres = count($entries);
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'])));
$dateContrainte = !empty($fiche['bf_contrainte_date']) ? date(DATE_W3C, strtotime($fiche['bf_contrainte_date'])) : null;
if (!empty($dateContrainte)) {
@ -45,7 +48,8 @@ function getStatus($fiche, $consultable = false) {
return $status;
}
function displayReservation($fiche) {
function displayReservation($fiche)
{
$output = '';
$isProducteur = ($GLOBALS['wiki']->GetUserName() == $GLOBALS['wiki']->GetPageOwner($fiche['listefiche8producteur']));
$status = getStatus($fiche, $GLOBALS['wiki']->UserIsOwner($fiche['id_fiche']) || $isProducteur);
@ -53,7 +57,7 @@ function displayReservation($fiche) {
// récuperer la fiche producteur
$producteur = baz_valeurs_fiche($fiche['listefiche8producteur']);
$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(
[
'queries' => ['trajet' => $fiche['id_fiche']],
@ -70,7 +74,7 @@ function displayReservation($fiche) {
$output .= '<br><strong>Il n\'y a pas encore de personnes qui participent à ce trajet.</strong>';
} else {
$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 {
if ($placesrestantes < 1) {