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,89 +1,93 @@
|
|||
<?php
|
||||
|
||||
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");
|
||||
function calculateFreePlaces($fiche) {
|
||||
//dump($fiche);
|
||||
$entries = $GLOBALS['wiki']->services->get(EntryManager::class)->search(
|
||||
function calculateFreePlaces($fiche)
|
||||
{
|
||||
//dump($fiche);
|
||||
$entries = $GLOBALS['wiki']->services->get(EntryManager::class)->search(
|
||||
[
|
||||
'queries' => ['trajet' => $fiche['id_fiche']],
|
||||
'formsIds' => [6],
|
||||
'keywords' => '',
|
||||
'user' => '',
|
||||
'minDate' => '',
|
||||
'correspondance' => ''
|
||||
],
|
||||
true, // filter on read ACL,
|
||||
true // use Guard
|
||||
);
|
||||
//dump($entries);
|
||||
$nbres = count($entries);
|
||||
return (int) $fiche['capacite_de_transport'] - (int) $nbres;
|
||||
}
|
||||
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)) {
|
||||
$dateFermeture = $dateContrainte;
|
||||
}
|
||||
$dateDisparition = date(DATE_W3C, strtotime("+1 hour", strtotime($fiche['date_du_trajet'])));
|
||||
$dateJour = date(DATE_W3C);
|
||||
if (!empty($dateContrainte) && $dateJour < $dateContrainte) {
|
||||
$status = 'Ouvert';
|
||||
} elseif ($dateJour < $dateFermeture) {
|
||||
$status = 'Ouvert';
|
||||
} elseif ($dateJour < $dateDisparition) {
|
||||
$status = 'Fermé';
|
||||
} else {
|
||||
if (!$consultable) {
|
||||
$status = 'Fini';
|
||||
} else {
|
||||
$status = 'Fini consultable';
|
||||
}
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
function displayReservation($fiche)
|
||||
{
|
||||
$output = '';
|
||||
$isProducteur = ($GLOBALS['wiki']->GetUserName() == $GLOBALS['wiki']->GetPageOwner($fiche['listefiche8producteur']));
|
||||
$status = getStatus($fiche, $GLOBALS['wiki']->UserIsOwner($fiche['id_fiche']) || $isProducteur);
|
||||
if ($status == 'Fini consultable' || $status == 'Ouvert' || $status == 'Fermé') {
|
||||
// récuperer la fiche producteur
|
||||
$producteur = baz_valeurs_fiche($fiche['listefiche8producteur']);
|
||||
$placesrestantes = calculateFreePlaces($fiche);
|
||||
if ($GLOBALS['wiki']->UserIsOwner($fiche['id_fiche']) || $isProducteur || $GLOBALS['wiki']->UserIsAdmin()) {
|
||||
$entries = $GLOBALS['wiki']->services->get(EntryManager::class)->search(
|
||||
[
|
||||
'queries' => ['trajet'=> $fiche['id_fiche']],
|
||||
'formsIds' => [6],
|
||||
'keywords' => '',
|
||||
'user' => '',
|
||||
'minDate' => '',
|
||||
'correspondance' => ''
|
||||
'queries' => ['trajet' => $fiche['id_fiche']],
|
||||
'formsIds' => [6],
|
||||
'keywords' => '',
|
||||
'user' => '',
|
||||
'minDate' => '',
|
||||
'correspondance' => ''
|
||||
],
|
||||
true, // filter on read ACL,
|
||||
true // use Guard
|
||||
);
|
||||
//dump($entries);
|
||||
$nbres = count($entries);
|
||||
return (int) $fiche['capacite_de_transport'] - (int) $nbres;
|
||||
}
|
||||
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)) {
|
||||
$dateFermeture = $dateContrainte;
|
||||
}
|
||||
$dateDisparition = date(DATE_W3C, strtotime("+1 hour", strtotime($fiche['date_du_trajet'])));
|
||||
$dateJour = date(DATE_W3C);
|
||||
if (!empty($dateContrainte) && $dateJour<$dateContrainte) {
|
||||
$status = 'Ouvert';
|
||||
} elseif ($dateJour<$dateFermeture) {
|
||||
$status = 'Ouvert';
|
||||
} elseif ($dateJour<$dateDisparition) {
|
||||
$status = 'Fermé';
|
||||
);
|
||||
if (count($entries) == 0) {
|
||||
$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"}}');
|
||||
}
|
||||
} else {
|
||||
if (!$consultable) {
|
||||
$status = 'Fini';
|
||||
if ($placesrestantes < 1) {
|
||||
$output .= '<a class="disabled btn btn-primary" href="#">Trajet complet</a>';
|
||||
} else {
|
||||
$output .= '<p class="places"><strong>Nombres de places restantes</strong> : ' . $placesrestantes . '</p>';
|
||||
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>';
|
||||
} else {
|
||||
$status = 'Fini consultable';
|
||||
$output .= '<a class="disabled btn btn-primary" href="#">Fermé</a>';
|
||||
}
|
||||
}
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
function displayReservation($fiche) {
|
||||
$output = '';
|
||||
$isProducteur = ($GLOBALS['wiki']->GetUserName() == $GLOBALS['wiki']->GetPageOwner($fiche['listefiche8producteur']));
|
||||
$status = getStatus($fiche, $GLOBALS['wiki']->UserIsOwner($fiche['id_fiche']) || $isProducteur);
|
||||
if ($status == 'Fini consultable' || $status == 'Ouvert' || $status == 'Fermé' ) {
|
||||
// récuperer la fiche producteur
|
||||
$producteur = baz_valeurs_fiche($fiche['listefiche8producteur']);
|
||||
$placesrestantes = calculateFreePlaces($fiche);
|
||||
if ($GLOBALS['wiki']->UserIsOwner($fiche['id_fiche']) || $isProducteur) {
|
||||
$entries = $GLOBALS['wiki']->services->get(EntryManager::class)->search(
|
||||
[
|
||||
'queries' => ['trajet'=> $fiche['id_fiche']],
|
||||
'formsIds' => [6],
|
||||
'keywords' => '',
|
||||
'user' => '',
|
||||
'minDate' => '',
|
||||
'correspondance' => ''
|
||||
],
|
||||
true, // filter on read ACL,
|
||||
true // use Guard
|
||||
);
|
||||
if (count($entries) == 0) {
|
||||
$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" }}');
|
||||
}
|
||||
} else {
|
||||
if ($placesrestantes < 1) {
|
||||
$output .= '<a class="disabled btn btn-primary" href="#">Trajet complet</a>';
|
||||
} else {
|
||||
$output .= '<p class="places"><strong>Nombres de places restantes</strong> : '.$placesrestantes.'</p>';
|
||||
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>';
|
||||
} else {
|
||||
$output .= '<a class="disabled btn btn-primary" href="#">Fermé</a>';
|
||||
}
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue