yeswiki-custom-mutualisatio.../fields/ReservationField.php
2023-11-09 14:22:00 +03:00

82 lines
3.3 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;
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");
$date = str_replace(' à 0:00', '', strftime("%A %d %B %Y à %k:%M", strtotime($entry['date_du_trajet'])));
$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"])) {
include_once 'tools/contact/libs/contact.functions.php';
send_mail('noreply@yeswiki.pro', 'Outil CC', $user["email"], '[Outil CC] un nouveau trajet pour '.$producteur['bf_titre'].' le '.$date, $message , $message_html);
}
}
}
//$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>'
]
);
}
}