src/Controller/TextesController.php line 297

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\RefRole;
  4. use App\Entity\RefFederation;
  5. use App\Entity\RefAffectation;
  6. use App\Entity\ParametrageTexte;
  7. use Doctrine\Persistence\ManagerRegistry;
  8. use App\Entity\DateRapportAnnuelActiviteType;
  9. use App\Services\Lib\SpecializedJsonResponse;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Component\HttpFoundation\JsonResponse;
  14. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  15. class TextesController extends AbstractController
  16. {
  17.     private ManagerRegistry $doctrine;
  18.     private SpecializedJsonResponse $specializedJsonResponse;
  19.     public function __construct(ManagerRegistry $doctrineSpecializedJsonResponse $specializedJsonResponse)
  20.     {
  21.         $this->doctrine $doctrine;
  22.         $this->specializedJsonResponse $specializedJsonResponse;
  23.     }
  24.     #[Route(path'/api/set_parametrage_texte_lm'name'cts_web_set_parametrage_texte_lm')]
  25.     public function SetParametrageTexteLm(Request $request)
  26.     {
  27.         $role $this->getUser()->getUtilisateur()->getIdRole();
  28.         $data json_decode($request->getContent(), true512JSON_THROW_ON_ERROR);
  29.         $request->request->replace(is_array($data) ? $data : []);
  30.         $params $request->request->all();
  31.         $entityManager $this->doctrine->getManager();
  32.         try {
  33.             if (
  34.                 RefRole::ROLE_FEDE === $role
  35.                 || RefRole::ROLE_FEDE_INVITE === $role
  36.             ) {
  37.                 $federation $this->getUser()->getIdFederation();
  38.                 $text_RefFede $this->doctrine->getRepository(RefFederation::class)->find($federation->getIdFederation());
  39.                 $text_RefFede->settext_DTG_dtn($params['textes_general_cts']['directiveTechDTN']);
  40.                 $entityManager->persist($text_RefFede);
  41.             }
  42.             if (
  43.                 RefRole::ROLE_DR === $role
  44.                 || RefRole::ROLE_DR_SIGNATAIRE === $role
  45.             ) {
  46.                 $affectation $this->getUser()->getIdAffectation();
  47.                 $text_RefAffe $this->doctrine->getRepository(RefAffectation::class)->find($affectation->getIdAffectation());
  48.                 $text_RefAffe->settext_DGCS_dr_ds($params['textes_general_cts']['directiveChefService']);
  49.                 $entityManager->persist($text_RefAffe);
  50.             }
  51.             if (
  52.                 RefRole::ROLE_DS_ADMIN === $role
  53.                 || RefRole::ROLE_DS_SIGNATAIRE === $role
  54.             ) {
  55.                 $text_RefAffe $this->doctrine->getRepository(RefAffectation::class)->find(1);
  56.                 $text_RefAffe->settext_DGCS_dr_ds($params['textes_general_cts']['directiveChefService']);
  57.                 $entityManager->persist($text_RefAffe);
  58.             }
  59.             $entityManager->flush();
  60.             return new JsonResponse(
  61.                 [
  62.                     'success' => true
  63.                 ],
  64.                 JsonResponse::HTTP_CREATED
  65.             );
  66.         } catch (\Exception $e) {
  67.             echo $e->getMessage();
  68.             $result = [
  69.                 'success' => false,
  70.                 'data' => $e->getMessage()
  71.             ];
  72.         }
  73.         return new JsonResponse($resultJsonResponse::HTTP_BAD_REQUEST);
  74.     }
  75.     #[Route(path'/api/get_parametrage_texte_lm'name'cts_web_get_parametrage_texte_lm')]
  76.     public function GetParametrageTexteLm()
  77.     {
  78.         $role $this->getUser()->getUtilisateur()->getIdRole();
  79.         $data = ['directiveTechDTN' => null'directiveChefService' => null];
  80.         try {
  81.             if (
  82.                 RefRole::ROLE_FEDE === $role
  83.                 || RefRole::ROLE_FEDE_INVITE === $role
  84.             ) {
  85.                 $federation $this->getUser()->getIdFederation();
  86.                 $text_RefFede $this->doctrine->getRepository(RefFederation::class)->find($federation->getIdFederation());
  87.                 $data['directiveTechDTN'] = $text_RefFede->gettext_DTG_dtn();
  88.             }
  89.             if (
  90.                 RefRole::ROLE_DR === $role
  91.                 || RefRole::ROLE_DR_SIGNATAIRE === $role
  92.             ) {
  93.                 $affectation $this->getUser()->getIdAffectation();
  94.                 $text_RefAffe $this->doctrine->getRepository(RefAffectation::class)->find($affectation->getIdAffectation());
  95.                 $data['directiveChefService'] = $text_RefAffe->gettext_DGCS_dr_ds();
  96.             }
  97.             if (RefRole::ROLE_DS_SIGNATAIRE === $role || RefRole::ROLE_DS_ADMIN === $role) {
  98.                 $affectation $this->getUser()->getIdAffectation();
  99.                 $text_RefAffe $this->doctrine->getRepository(RefAffectation::class)->find(1); // NATIONAL
  100.                 $data['directiveChefService'] = $text_RefAffe->gettext_DGCS_dr_ds();
  101.             }
  102.             $success true;
  103.         } catch (\Exception $e) {
  104.             $success false;
  105.             $data $e->getMessage();
  106.         }
  107.         return $this->specializedJsonResponse->getJson($success$data);
  108.     }
  109.     /**
  110.      * @throws \JsonException
  111.      */
  112.     #[Route(path'/api/set_parametrage_carriere'name'cts_web_set_parametrage_carriere')]
  113.     public function SetParametrageCarriere(Request $request)
  114.     {
  115.         $entityManager $this->doctrine->getManager();
  116.         $repo $this->doctrine->getRepository(DateRapportAnnuelActiviteType::class);
  117.         $data json_decode($request->getContent(), true512JSON_THROW_ON_ERROR);
  118.         $request->request->replace(is_array($data) ? $data : []);
  119.         $params $request->request->all();
  120.         $t $repo->getList();
  121.         if ((is_countable($t) ? count($t) : 0) > 0) {
  122.             $t $t[0];
  123.         } else {
  124.             $t = new DateRapportAnnuelActiviteType();
  125.         }
  126.         $t->setNoteInfoEcranCarriere($params['NOTE_INFO_ECRAN_CARRIERE']);
  127.         $t->setNoteInfoRapportAnnuelActivite($params['NOTE_INFO_RAPPORT_ANNUEL_ACTIVITE']);
  128.         $entityManager->persist($t);
  129.         $entityManager->flush();
  130.         return $this->specializedJsonResponse->getJson(true$data);
  131.     }
  132.     #[Route(path'/api/get_parametrage_carriere'name'cts_web_get_parametrage_carriere')]
  133.     public function GetParametrageCarriere()
  134.     {
  135.         $result = [];
  136.         $repo $this->doctrine->getRepository(DateRapportAnnuelActiviteType::class)->getList();
  137.         $text_info array_map(function ($text) {
  138.             return [
  139.                 'NOTE_INFO_ECRAN_CARRIERE' => $text->getNoteInfoEcranCarriere(),
  140.                 'NOTE_INFO_RAPPORT_ANNUEL_ACTIVITE' => $text->getNoteInfoRapportAnnuelActivite()
  141.             ];
  142.         }, $repo);
  143.         if (sizeof($text_info) > 0) {
  144.             $data = [
  145.                 'status' => Response::HTTP_OK,
  146.                 'data' => $text_info
  147.             ];
  148.         } else {
  149.             $data = [
  150.                 'status' => Response::HTTP_NOT_FOUND,
  151.                 'data' => 'Aucun texte trouvé'
  152.             ];
  153.         }
  154.         return new JsonResponse($data);
  155.     }
  156.     /**
  157.      * @throws \JsonException
  158.      */
  159.     #[Route(path'/api/set_parametrage_texte'name'cts_web_set_parametrage_texte')]
  160.     public function SetParametrageTexte(Request $request)
  161.     {
  162.         $data json_decode($request->getContent(), true512JSON_THROW_ON_ERROR);
  163.         $entityManager $this->doctrine->getManager();
  164.         $repo $this->doctrine->getRepository(ParametrageTexte::class);
  165.         foreach ($data as $code => $texte) {
  166.             $ta $repo->getByCode($code);
  167.             if ((is_countable($ta) ? count($ta) : 0) > 0) {
  168.                 $t $ta[0];
  169.                 $t->setTexte($texte);
  170.             } else {
  171.                 $t = new ParametrageTexte();
  172.                 $t->setCode($code);
  173.                 $t->setTexte($texte);
  174.             }
  175.             $entityManager->persist($t);
  176.         }
  177.         $entityManager->flush();
  178.         return $this->specializedJsonResponse->getJson(true$data);
  179.     }
  180.     #[Route(path'/api/get_date_rapport'name'cts_web_get_date_rapport')]
  181.     public function GetDateRapport(Request $requestSpecializedJsonResponse $specializedJsonResponse)
  182.     {
  183.         if ($request->getContent() == '') {
  184.             $data = [];
  185.         } else {
  186.             $data json_decode($request->getContent(), true512JSON_THROW_ON_ERROR);
  187.         }
  188.         $repo $this->doctrine->getRepository(DateRapportAnnuelActiviteType::class);
  189.         $result = [];
  190.         $t $repo->getList();
  191.          $result['DATE_DEBUT'] =  $t[0]->getDateDebutSaisi();
  192.          $result['DATE_FIN'] =  $t[0]->getDateFinSaisi();
  193.         // return $specializedJsonResponse->getJson(true, $result);      // Crée le tableau items avec les valeurs récupérées
  194.         $annee =Date('Y');
  195.             $items = [
  196.                 'annee' => $annee,
  197.                 'dateDebutSaisi' => isset($result['DATE_DEBUT']) ?  $result['DATE_DEBUT']->format('Y-m-d H:i:s') : null,
  198.                 'dateFinSaisi' => isset( $result['DATE_FIN']) ?  $result['DATE_FIN']->format('Y-m-d H:i:s') : null,
  199.              
  200.             ];
  201.             $jsonv['items'] = $items;
  202.             $json_merge json_encode($jsonv);
  203.             return new JsonResponse($json_mergeJsonResponse::HTTP_OK, [], true);
  204.     
  205.     }
  206.     #[Route(path'/api/get_parametrage_texte'name'cts_web_get_parametrage_texte')]
  207.     public function GetParametrageTexte(Request $requestSpecializedJsonResponse $specializedJsonResponse)
  208.     {
  209.         //ajout controle
  210.         if ($request->getContent() == '') {
  211.             $data = [];
  212.         } else {
  213.             $data json_decode($request->getContent(), true512JSON_THROW_ON_ERROR);
  214.         }
  215.         $repo $this->doctrine->getRepository(ParametrageTexte::class);
  216.         $result = [];
  217.         foreach ($data as $code) {
  218.             $t $repo->getByCode($code);
  219.             if ((is_countable($t) ? count($t) : 0) > 0)
  220.                 $result[$code] = $t[0]->getTexte();
  221.             else
  222.                 $result[$code] = '';
  223.         }
  224.         return $specializedJsonResponse->getJson(true$result);
  225.     }
  226.     #[Route(path'/api/saveTextInfoProfil'name'cts_web_set_texte_profil')]
  227.     public function SetTextInfoProfil(Request $request)
  228.     {
  229.         $role $this->getUser()->getUtilisateur()->getIdRole();
  230.         if (RefRole::ROLE_DS_ADMIN !== $role) {
  231.             return new JsonResponse(nullJsonResponse::HTTP_BAD_REQUEST);
  232.         }
  233.         $data json_decode($request->getContent(), true512JSON_THROW_ON_ERROR);
  234.         $entityManager $this->doctrine->getManager();
  235.         $repo $this->doctrine->getRepository(ParametrageTexte::class);
  236.         foreach ($data as $code => $texte) {
  237.             $ta $repo->getByCode($code);
  238.             if ((is_countable($ta) ? count($ta) : 0) > 0) {
  239.                 $t $ta[0];
  240.                 $t->setTexte($texte);
  241.             } else {
  242.                 $t = new ParametrageTexte();
  243.                 $t->setCode($code);
  244.                 $t->setTexte($texte);
  245.             }
  246.             $entityManager->persist($t);
  247.         }
  248.         $entityManager->flush();
  249.         return $this->specializedJsonResponse->getJson(true$data);
  250.     }
  251.     #[Route(path'/api/loadTextInfoProfil'name'cts_web_get_texte_profil')]
  252.     public function GetTextInfoProfil()
  253.     {
  254.         $data = ['textCts''textDs''textDtn''TextSh'];
  255.         $repo $this->doctrine->getRepository(ParametrageTexte::class);
  256.         $result = [];
  257.         foreach ($data as $code) {
  258.             $t $repo->getByCode($code);
  259.             if ((is_countable($t) ? count($t) : 0) > 0)
  260.                 $result[$code] = $t[0]->getTexte();
  261.             else
  262.                 $result[$code] = '';
  263.         }
  264.         return $this->specializedJsonResponse->getJson(true$result);
  265.     }
  266. }