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

89 lines
3.5 KiB
PHP
Raw Permalink Normal View History

2023-11-09 13:59:05 +03:00
<?php
namespace YesWiki\Custom\Field;
include_once 'custom/templates/bazar/circuitscourt.php';
use YesWiki\Bazar\Field\BazarField;
use Psr\Container\ContainerInterface;
/**
* @Field({"reservation"})
*/
class ReservationField 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)
{
return;
}
protected function renderStatic($entry)
{
return displayReservation($entry);
}
public function formatValuesBeforeSave($entry)
{
$mail_receiver = 'cyrille.bombard@lilo.org'; // todo prendre l'email du owner
$producteur = baz_valeurs_fiche($entry['listefiche8producteur']);
setlocale(LC_ALL, 'fr_FR.UTF8', 'fr_FR','fr','fr','fra','fr_FR@euro');
setlocale(LC_TIME, "fr_FR");
2023-11-09 14:39:06 +03:00
$dateTimeObj = new \DateTime($entry['date_du_trajet'], new \DateTimeZone('Europe/Paris'));
$date =
2023-11-09 14:39:06 +03:00
str_replace(' à 0:00', '', \IntlDateFormatter::formatObject(
$dateTimeObj,
'eeee d MMMM y à HH:mm',
'fr'
));
2023-11-09 13:59:05 +03:00
$users = $GLOBALS['wiki']->LoadAll("select email from ".$GLOBALS['wiki']->config["table_prefix"]."users");
$u = [];
//$url = $GLOBALS['wiki']->href('', 'saisie-participants-trajet', 'trajet='.$entry['id_fiche'].'&producteur='.urlencode($producteur['id_fiche']));
$url = $GLOBALS['wiki']->href('', 'PagePrincipale');
$message = 'Un nouveau trajet pour le producteur '.$producteur['bf_titre'].' le '.$date.' vient dêtre proposé par '.$GLOBALS['wiki']->GetUsername().'.
Nature des productions de ce producteur : '.$producteur['nature_des_productions'].'
Si vous êtes intéressé par profiter de ce trajet pour vous approvisionner chez ce producteur et ainsi augmenter la résilience alimentaire de votre territoire, inscrivez-vous en cliquant sur '.$url.' , puis allez dans le menu "Je profite d\'un 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 ($GLOBALS['wiki']->getPageTag() == $entry['id_fiche']) {
// modification : on ne fait pas de mail
} else {
// creation : on envoie un mail a tous
foreach ($users as $user) {
//$u[] = $user["email"];
if (!empty($user["email"])) {
2023-11-09 14:22:00 +03:00
include_once 'tools/contact/libs/contact.functions.php';
2023-11-09 14:44:01 +03:00
send_mail('noreply@yeswiki.pro', 'Outil Circuit Court', $user["email"], '[Outil CC] un nouveau trajet pour '.$producteur['bf_titre'].' le '.$date, $message , $message_html);
2023-11-09 13:59:05 +03:00
}
}
}
//$message = 'Ce message sera envoyé à :'.implode(', ', $u)."\n\n";
return array_merge(
['trajet' => $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>'
]
);
}
}