<?php
namespace App\Controller\Api\Publique;
use App\Entity\Campagneprospect;
use App\Entity\Utilisateur;
use App\Helpers\Fonctions\Fonctions;
use App\Helpers\Mailing;
use Exception;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use function json_decode;
/**
* @Route("/publique")
*/
class ApiPubliqueController extends ApiController
{
/**
* @Route("/versionlogs", name="api_versionlogs", methods={"GET"})
*/
public function versionlogs()
{
$data = file_get_contents("versionlogs.md");
return $this->apiOk($data);
}
/**
* @Route("/fonctionnalitelogs", name="api_fonctionnaliteslogs", methods={"GET"})
*/
public function fonctionnaliteslogs()
{
$data = file_get_contents("fonctionnalitelogs.md");
return $this->apiOk($data);
}
/**
* @Route("/rappelnotifications", name="api_rappelnotifications", methods={"GET"})
*/
public function rappelnotifications()
{
$send = false;
$fileName = 'log_'.date('Y-m-d').'.txt';
$filePath = "notificationRappelPerso/" . $fileName;
// Get the directory path
$directory = dirname($filePath);
// Check if the directory exists, if not, create it
if (!is_dir($directory)) {
mkdir($directory, 0755, true);
}
if (!file_exists($filePath)) {
$send = true;
}
if($send){
// Recuperer la liste des rappels++ d'aujourdhui et grouped by user !
$today = new \DateTime();
$today->setTime(0, 0, 0); // Ensure time is set to midnight for accurate date comparison
$listeRappel = $this->em->getRepository(Campagneprospect::class)->createQueryBuilder('c')
->where('c.rappelprive = :rappelprive')
->andWhere('DATE(c.daterappel) = :today')
->setParameter('rappelprive', 1)
->setParameter('today', $today->format('Y-m-d'))
->getQuery()
->getResult();
// group by $utilisateur
$RappelUtilisateurs = $this->groupRappelsByUtilisateur($listeRappel);
foreach ($RappelUtilisateurs as $item){
(new Mailing($this->mailer, $this->templating))->notificationRappelPerso($item);
}
$text = PHP_EOL."---------------------".date("Y-m-d H:i:s")."------------------------------".PHP_EOL.serialize($RappelUtilisateurs);
file_put_contents($filePath,$text);
return $this->apiOk("1");
}
return $this->apiOk("0");
}
}