yeswiki-custom-mutualisatio.../fields/TrajetField.php

107 lines
4.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace YesWiki\Custom\Field;
use YesWiki\Bazar\Field\BazarField;
use YesWiki\Core\Service\PageManager;
use Psr\Container\ContainerInterface;
/**
* @Field({"trajet"})
*/
class TrajetField extends BazarField
{
public function __construct(array $values, ContainerInterface $services)
{
parent::__construct($values, $services);
$this->size = null;
$this->maxChars = null;
$this->default = "";
}
protected function renderInput($entry)
{
if (!empty($_GET['trajet'])) {
$traj = baz_valeurs_fiche($_GET['trajet']);
setlocale(LC_ALL, 'fr_FR.UTF8', 'fr_FR','fr','fr','fra','fr_FR@euro');
$date = str_replace(' à 0:00', '', strftime("%A %d %B %Y à %k:%M", strtotime($traj['date_du_trajet'])));
$prod = baz_valeurs_fiche($_GET['producteur']);
// Do the page change in any case (useful for attach or grid)
$oldPage = $GLOBALS['wiki']->GetPageTag();
$oldPageArray = $GLOBALS['wiki']->page;
$GLOBALS['wiki']->tag = $_GET['producteur'];
$GLOBALS['wiki']->page = $GLOBALS['wiki']->LoadPage($_GET['producteur']);
$output = '<div class="text-left"><h3>Trajet proposé le '.$date.' par '.$traj['owner'].'</h3>';
$output .= $GLOBALS['wiki']->Format('===Comment commander==='."\n".$prod["bf_process_commande"]);
$output .= $GLOBALS['wiki']->Format('===Produits commandables==='."\n".$prod["bf_produits_commandables"]);
$output .= $GLOBALS['wiki']->Format('===RIB pour paiement==='."\n".$prod["bf_rib"]);
$output .= '</div>';
$output .= '<input type="hidden" name="trajet" value="'.$_GET['trajet'].'" />';
$GLOBALS['wiki']->tag = $oldPage;
$GLOBALS['wiki']->page = $oldPageArray;
return $output;
} else {
return 'Pas normal';
}
}
public function formatValuesBeforeSave($entry)
{
if (!empty($entry['bf_telephone']) && !empty($entry['trajet'])) {
$traj = baz_valeurs_fiche($entry['trajet']);
$u = $GLOBALS['wiki']->services->get(PageManager::class)->getOwner($traj['id_fiche']);
$u = $GLOBALS['wiki']->LoadUser($u);
$mail_receiver = $u['email'];
setlocale(LC_ALL, 'fr_FR.UTF8', 'fr_FR','fr','fr','fra','fr_FR@euro');
setlocale(LC_TIME, "fr_FR");
$dateTimeObj = new \DateTime($traj['date_du_trajet'], new \DateTimeZone('Europe/Paris'));
$date =
str_replace(' à 0:00', '', \IntlDateFormatter::formatObject(
$dateTimeObj,
'eeee d MMMM y à HH:mm',
'fr'
));
$urlperso = $GLOBALS['wiki']->href('', 'espace-perso');
$message = 'Une nouvelle personne souhaite profiter du trajet que vous avez proposé le '.$date.'.
Prénom : '.$entry['bf_prenom'].'
Nom : '.$entry['bf_nom'].'
Téléphone : '.$entry['bf_telephone'].'
Son commentaire lors de son inscription : '.$entry['bf_commentaire'].'
Ses coordonnées figureront sur la liste des participants à votre trajet que nous vous invitons à éditer avant de partir chez le producteur concerné. Cela vous permettra de vérifier sur place, le jour même avec le producteur, que les commandes de toutes les personnes qui se sont inscrites vous soient bien remises.
Pour éditer la liste des participants à votre trajet, cliquez sur ce lien : '.$urlperso.'.
Merci pour la proposition de ce trajet.
En cas de souci avec loutil numérique, vous pouvez contacter Cyrille Bombard au 06 63 28 13 11 ou par mail à cyrille.bombard@wision.info';
$message_html = nl2br($message);
if (!empty($mail_receiver)) {
include_once 'tools/contact/libs/contact.functions.php';
send_mail('noreply@yeswiki.pro', 'Outil Circuit Court', $mail_receiver, '[Outil CC] Une nouvelle personne pour votre trajet du '.$date, $message , $message_html);
}
}
return array_merge(
['trajet' => $entry['trajet']],
);
}
protected function renderStatic($entry)
{
return 'Trajet concerné : '.$GLOBALS['wiki']->Format($entry['trajet']);
}
// change return of this method to keep compatible with php 7.3 (mixed is not managed)
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return array_merge(
parent::jsonSerialize(),
[
//'reservation_button' => '<a class="btn btn-primary" href="#"><i class="fa fa-plus"></i>&nbsp;Je profite de ce trajet</a>'
]
);
}
}