src/Controller/Api/ConfigurationController.php line 93

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api;
  3. use App\Entity\ApiToken;
  4. use App\Entity\Laboratory\Laboratoire;
  5. use App\Entity\Laboratory\Product;
  6. use App\Entity\Laboratory\QrCode;
  7. use App\Entity\Localisation\Cities;
  8. use App\Entity\RepresentativesCode;
  9. use App\Entity\Localisation\Localisation;
  10. use App\Entity\Configuration;
  11. use App\Entity\Configuration\ConditionGeneral;
  12. use App\Entity\Configuration\UserAcceptConditionGeneral;
  13. use App\Entity\Configuration\ConditionGeneralVersion;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use App\Entity\AppVersion;
  16. use App\Entity\PointVente;
  17. use App\Notifiers\FirebaseNotifier;
  18. use App\Entity\User;
  19. use App\Entity\Users\Vendor;
  20. use App\Entity\Users\WarehouseMan;
  21. use App\Entity\Users\Representative;
  22. use App\Entity\Users\SuperVisor;
  23. use App\Entity\Users\LaboAdmin;
  24. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  25. use Symfony\Component\HttpClient\HttpClient;
  26. use Symfony\Component\HttpFoundation\JsonResponse;
  27. use Symfony\Component\HttpFoundation\Request;
  28. use Symfony\Component\Routing\Annotation\Route;
  29. use Symfony\Contracts\HttpClient\HttpClientInterface;
  30. use Symfony\Component\HttpFoundation\UrlHelper;
  31. class ConfigurationController extends AbstractController
  32. {
  33.     /**
  34.      * @Route("/check_app_version", name="check_app_update")
  35.      */
  36.     public function checkAppVersion(Request $request){
  37.        // return new JsonResponse([
  38.     //         'message' => '',
  39.     //         'status' => true,
  40.     //     ]);
  41.         $data json_decode($request->getContent(),true);
  42.         $app = isset($data['app']) ? $data['app'] : null;
  43.         $version = isset($data['version']) ? $data['version'] : null;
  44.         $em $this->getDoctrine()->getManager();
  45.         $configuration $em->getRepository(Configuration::class)->findOneBy(['app'=>$app]);
  46.         if($configuration){
  47.             if($configuration->getVersion()){
  48.                 if($configuration->getVersion()->getName() != $version){
  49.                     return new JsonResponse([
  50.                         'message' => 'Configuration introuvable',
  51.                         'status' => false,
  52.                         'data'   => [
  53.                             'maintenance' => $configuration->getMaintenance(),
  54.                             'is_obligatory' => $configuration->getVersion()->getIsObligatory(),
  55.                             'link_store'=> $configuration->getLinkStore(),
  56.                             'link_apple_store'=> $configuration->getLinkAppleStore(),
  57.                         ]
  58.                     ]);
  59.                 }
  60.                 return new JsonResponse([
  61.                     'message' => '',
  62.                     'status' => true
  63.                 ]);
  64.             }
  65.             return new JsonResponse([
  66.                 'message' => 'Version introuvable',
  67.                 'status' => true
  68.             ]);
  69.         }else{
  70.             return new JsonResponse([
  71.                 'message' => 'Configuration introuvable',
  72.                 'status' => true
  73.             ]);
  74.         }
  75.     }
  76.      /**
  77.      * @Route("/api/login", name="api_login",methods={"POST"})
  78.      */
  79.     public function appLogin(Request $request,$app){
  80.     }
  81.      /**
  82.      * @Route("/condition_general/{app}", name="condition_general",methods={"GET"})
  83.      */
  84.     public function conditionGeneral(Request $request,$app){
  85.         $em $this->getDoctrine()->getManager();
  86.         $condition_general $em->getRepository(ConditionGeneral::class)->findOneByApp($app);
  87.         if($condition_general){
  88.             if($condition_general->getVersion()){
  89.                 return new Response($condition_general->getVersion()->getContent());
  90.             }
  91.             return null;
  92.         }else{
  93.             return null;
  94.         }
  95.     }
  96.     /**
  97.      * @Route("/api/accepte_condition_general_version", name="accepte_condition_general_version")
  98.      */
  99.     public function accepteConditionGeneralVersion(Request $request){
  100.         $em $this->getDoctrine()->getManager();
  101.         $data json_decode($request->getContent(),true);
  102.         $app = isset($data['app']) ? $data['app'] : null;
  103.         $condition_general $em->getRepository(ConditionGeneral::class)->findOneByApp($app);
  104.         if($condition_general){
  105.             if($condition_general->getVersion()){
  106.                 $userAcceptConditionGeneral $em->getRepository(UserAcceptConditionGeneral::class)->findOneBy(['user'=>$this->getUser(),'version'=>$condition_general->getVersion()]);
  107.                 if(!$userAcceptConditionGeneral){
  108.                     $userAcceptConditionGeneral = new UserAcceptConditionGeneral();
  109.                     $userAcceptConditionGeneral->setUser($this->getUser());
  110.                     $userAcceptConditionGeneral->setVersion($condition_general->getVersion());
  111.                     $userAcceptConditionGeneral->setCoditionGeneral($condition_general);
  112.                     $em->persist($userAcceptConditionGeneral);
  113.                     $em->flush();
  114.                     return new JsonResponse([
  115.                         'message' => 'Les conditions sont bien acceptées',
  116.                         'status' => true
  117.                     ]);
  118.                 }
  119.                 return new JsonResponse([
  120.                     'message' => 'Vous avez déjà accepté les conditions',
  121.                     'status' => true
  122.                 ]);
  123.             }
  124.             return new JsonResponse([
  125.                 'message' => 'Version introuvable',
  126.                 'status' => true
  127.             ]);
  128.         }else{
  129.             return new JsonResponse([
  130.                 'message' => 'Conditions génerales introuvables',
  131.                 'status' => true
  132.             ]);
  133.         }
  134.     }
  135. }