yeswiki-custom-mutualisatio.../fields/DemandeField.php
2023-12-21 14:11:34 +03:00

86 lines
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({"demande"})
*/
class DemandeField 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;
}
public function formatValuesBeforeSave($entry)
{
$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");
$dateTimeObj = new \DateTime($entry['date_souhaitee'], new \DateTimeZone('Europe/Paris'));
$date =
str_replace(' à 0:00', '', \IntlDateFormatter::formatObject(
$dateTimeObj,
'eeee d MMMM y',
'fr'
));
$dateTimeObj = new \DateTime($entry['date_souhaitee_fin'], new \DateTimeZone('Europe/Paris'));
$datefin =
str_replace(' à 0:00', '', \IntlDateFormatter::formatObject(
$dateTimeObj,
'eeee d MMMM y',
'fr'
));
$users = $GLOBALS['wiki']->LoadAll("select email from " . $GLOBALS['wiki']->config["table_prefix"] . "users");
$url = $GLOBALS['wiki']->href('', 'PagePrincipale');
$message = 'Une personne de votre commune a besoin de vous pour sapprovisionner chez le producteur ' . $producteur['bf_titre'] . ' entre le ' . $date . ' et le ' . $date . '.
Si vous en avez la possibilité, soyez solidaire et créez une proposition de trajet dans la période correspondante.
Pour cela, rendez-vous sur le site de mutualisation de trajet de votre commune ou cliquez directement sur le lien : ' . $url . ' puis sur « Je propose un trajet".
Nature des productions du producteur concerné : ' . $producteur['nature_des_productions'] . '
Par avance merci !
La solidarité est une clé du bien vivre ensemble.
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) {
if (!empty($user["email"])) {
include_once 'tools/contact/libs/contact.functions.php';
send_mail('noreply@yeswiki.pro', 'Outil Circuit Court', $user["email"], '[Outil CC] un habitant a BESOIN de vous pour un trajet à ' . $producteur['bf_titre'] . ' entre le ' . $date . ' et le ' . $datefin, $message, $message_html);
}
}
}
}
// change return of this method to keep compatible with php 7.3 (mixed is not managed)
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return;
}
}