src/App/Controller/Api/TiersController.php line 40

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api;
  3. use App\Model\Enum\AccessControl;
  4. use App\Controller\AbstractController;
  5. use App\Entity\Tiers;
  6. use App\Traits\Autowired\Manager\TiersManagerTrait;
  7. use GollumSF\RestBundle\Annotation\Serialize;
  8. use GollumSF\RestBundle\Annotation\Unserialize;
  9. use GollumSF\RestBundle\Annotation\Validate;
  10. use GollumSF\RestDocBundle\Annotation\ApiDescribe;
  11. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. /**
  14.  * @Route("/api/tierses")
  15.  * @ApiDescribe(Tiers::class)
  16.  */
  17. class TiersController extends AbstractController {
  18.     use TiersManagerTrait;
  19.     /**
  20.      * @Route("", methods="GET")
  21.      * @IsGranted(AccessControl::API_GET_TIERS, subject="current_user")
  22.      * @Serialize(groups="tiers_getc")
  23.      * @ApiDescribe(
  24.      *     request={
  25.      *         "parameters"={
  26.      *             "filters"={
  27.      *                 "in"="query",
  28.      *                 "required"=false,
  29.      *                 "type"="string",
  30.  *                     "example"="{""type"":"""",""name"":"""",""company"":"""",""remarques"":"""",""phone1"":"""",""phone2"":"""",""createdAt"":{""mode"":""equal"",""equal"":null,""start"":null,""end"":null}}"
  31.      *             }
  32.      *         }
  33.      *     }
  34.      * )
  35.      */
  36.     public function list() {
  37.         return $this->tiersManager->apiFindBy();
  38.     }
  39.     
  40.     /**
  41.      * @Route("/{id}", methods="GET", requirements={"id"="\d+"})
  42.      * @IsGranted(AccessControl::API_GET_TIERS, subject="current_user")
  43.      * @Serialize(groups="tiers_get")
  44.      */
  45.     public function find(Tiers $tiers) {
  46.         return $tiers;
  47.     }
  48.     /**
  49.      * @Route("", methods="POST")
  50.      * @IsGranted(AccessControl::API_POST_TIERS, subject="current_user")
  51.      * @Unserialize("tiers", groups="tiers_post")
  52.      * @Validate({ "tiers_post" })
  53.      * @Serialize(groups="tiers_get")
  54.      *
  55.      */
  56.     public function post(Tiers $tiers) {
  57.         return $tiers;
  58.     }
  59.     /**
  60.      * @Route("/{id}", methods="PUT", requirements={"id"="\d+"})
  61.      * @IsGranted(AccessControl::API_PUT_TIERS, subject="current_user")
  62.      * @Unserialize("tiers", groups="tiers_put")
  63.      * @Validate({ "tiers_put" })
  64.      * @Serialize(groups="tiers_get")
  65.      *
  66.      */
  67.     public function put(Tiers $tiers) {
  68.         return $tiers;
  69.     }
  70.     /**
  71.      * @Route("/{id}", methods="DELETE", requirements={"id"="\d+"})
  72.      * @IsGranted(AccessControl::API_DELETE_TIERS, subject="current_user")
  73.      * @Serialize(groups="tiers_get")
  74.      *
  75.      */
  76.     public function delete(Tiers $tiers) {
  77.         return $this->tiersManager->delete($tiers);
  78.     }
  79.     /**
  80.      * @Route("/attestation/{id}/{year}", methods="GET", requirements={"id"="\d+"})
  81.      * @IsGranted(AccessControl::API_GET_TIERS, subject="current_user")
  82.      * @Serialize(groups="tiers_get")
  83.      *
  84.      */
  85.     public function attestation(Tiers $tiersstring $year) {
  86.         $host $this->getParameter('database_host');
  87.         $port $this->getParameter('database_port');
  88.         $user $this->getParameter('database_user');
  89.         $pass $this->getParameter('database_password');
  90.         $db   $this->getParameter('database_name');
  91.         $charset 'utf8mb4';
  92.         $dsn "mysql:host=$host;dbname=$db;charset=$charset;port=$port";
  93.         return $this->tiersManager->getPrestation($tiers$year$dsn$user$pass);
  94.     }
  95. }