<?php
namespace App\Controller\Api;
use App\Entity\ApiToken;
use App\Entity\Laboratory\Laboratoire;
use App\Entity\Laboratory\Product;
use App\Entity\Laboratory\QrCode;
use App\Entity\Localisation\Cities;
use App\Entity\RepresentativesCode;
use App\Entity\Localisation\Localisation;
use App\Entity\Configuration;
use App\Entity\Configuration\ConditionGeneral;
use App\Entity\Configuration\UserAcceptConditionGeneral;
use App\Entity\Configuration\ConditionGeneralVersion;
use Symfony\Component\HttpFoundation\Response;
use App\Entity\AppVersion;
use App\Entity\PointVente;
use App\Notifiers\FirebaseNotifier;
use App\Entity\User;
use App\Entity\Users\Vendor;
use App\Entity\Users\WarehouseMan;
use App\Entity\Users\Representative;
use App\Entity\Users\SuperVisor;
use App\Entity\Users\LaboAdmin;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Component\HttpFoundation\UrlHelper;
class ConfigurationController extends AbstractController
{
/**
* @Route("/check_app_version", name="check_app_update")
*/
public function checkAppVersion(Request $request){
// return new JsonResponse([
// 'message' => '',
// 'status' => true,
// ]);
$data = json_decode($request->getContent(),true);
$app = isset($data['app']) ? $data['app'] : null;
$version = isset($data['version']) ? $data['version'] : null;
$em = $this->getDoctrine()->getManager();
$configuration = $em->getRepository(Configuration::class)->findOneBy(['app'=>$app]);
if($configuration){
if($configuration->getVersion()){
if($configuration->getVersion()->getName() != $version){
return new JsonResponse([
'message' => 'Configuration introuvable',
'status' => false,
'data' => [
'maintenance' => $configuration->getMaintenance(),
'is_obligatory' => $configuration->getVersion()->getIsObligatory(),
'link_store'=> $configuration->getLinkStore(),
'link_apple_store'=> $configuration->getLinkAppleStore(),
]
]);
}
return new JsonResponse([
'message' => '',
'status' => true
]);
}
return new JsonResponse([
'message' => 'Version introuvable',
'status' => true
]);
}else{
return new JsonResponse([
'message' => 'Configuration introuvable',
'status' => true
]);
}
}
/**
* @Route("/api/login", name="api_login",methods={"POST"})
*/
public function appLogin(Request $request,$app){
}
/**
* @Route("/condition_general/{app}", name="condition_general",methods={"GET"})
*/
public function conditionGeneral(Request $request,$app){
$em = $this->getDoctrine()->getManager();
$condition_general = $em->getRepository(ConditionGeneral::class)->findOneByApp($app);
if($condition_general){
if($condition_general->getVersion()){
return new Response($condition_general->getVersion()->getContent());
}
return null;
}else{
return null;
}
}
/**
* @Route("/api/accepte_condition_general_version", name="accepte_condition_general_version")
*/
public function accepteConditionGeneralVersion(Request $request){
$em = $this->getDoctrine()->getManager();
$data = json_decode($request->getContent(),true);
$app = isset($data['app']) ? $data['app'] : null;
$condition_general = $em->getRepository(ConditionGeneral::class)->findOneByApp($app);
if($condition_general){
if($condition_general->getVersion()){
$userAcceptConditionGeneral = $em->getRepository(UserAcceptConditionGeneral::class)->findOneBy(['user'=>$this->getUser(),'version'=>$condition_general->getVersion()]);
if(!$userAcceptConditionGeneral){
$userAcceptConditionGeneral = new UserAcceptConditionGeneral();
$userAcceptConditionGeneral->setUser($this->getUser());
$userAcceptConditionGeneral->setVersion($condition_general->getVersion());
$userAcceptConditionGeneral->setCoditionGeneral($condition_general);
$em->persist($userAcceptConditionGeneral);
$em->flush();
return new JsonResponse([
'message' => 'Les conditions sont bien acceptées',
'status' => true
]);
}
return new JsonResponse([
'message' => 'Vous avez déjà accepté les conditions',
'status' => true
]);
}
return new JsonResponse([
'message' => 'Version introuvable',
'status' => true
]);
}else{
return new JsonResponse([
'message' => 'Conditions génerales introuvables',
'status' => true
]);
}
}
}