src/Controller/Api/v1/EnrollmentApiController.php line 179

Open in your IDE?
  1. <?php
  2. namespace EADPlataforma\Controller\Api\v1;
  3. use OpenApi\Annotations as OA;
  4. use Nelmio\ApiDocBundle\Annotation\Model;
  5. use Nelmio\ApiDocBundle\Annotation\Security;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use EADPlataforma\Controller\Api\AbstractApiController;
  9. use EADPlataforma\Entity\User;
  10. use EADPlataforma\Entity\UserSubscription;
  11. use EADPlataforma\Entity\Course;
  12. use EADPlataforma\Entity\CourseCertificateTemplate;
  13. use EADPlataforma\Entity\Lesson;
  14. use EADPlataforma\Entity\Group;
  15. use EADPlataforma\Entity\GroupUser;
  16. use EADPlataforma\Entity\GroupCourse;
  17. use EADPlataforma\Entity\ProductCourse;
  18. use EADPlataforma\Entity\Enrollment;
  19. use EADPlataforma\Enum\EnrollmentEnum;
  20. use EADPlataforma\Enum\TrashEnum;
  21. use EADPlataforma\Enum\UserLogEnum;
  22. use EADPlataforma\Enum\UserPermissionEnum;
  23. use EADPlataforma\Enum\LessonEnum;
  24. use EADPlataforma\Enum\ErrorEnum;
  25. class EnrollmentApiController extends AbstractApiController {
  26.     public function getEntityClass(){
  27.         return Enrollment::class;
  28.     }
  29.     /**
  30.      * Listagem de matrículas do EAD.
  31.      *
  32.      * @Route("/api/1/enrollment", methods={"GET"})
  33.      * @OA\Response(
  34.      *     response=200,
  35.      *     description="Retorna os cursos do EAD.",
  36.      *     @OA\JsonContent(
  37.      *         type="object",
  38.      *         @OA\Property(property="matricula_id", type="integer", example=1, description="Id da matrícula no EAD."),
  39.      *         @OA\Property(property="aluno_id", type="integer", example=10, description="Id do aluno no EAD."),
  40.      *         @OA\Property(property="aluno_nome", type="string", example="Nome do aluno."),
  41.      *         @OA\Property(property="aluno_email", type="string", example="E-mail do aluno."),
  42.      *         @OA\Property(property="curso_id", type="integer", example=10, description="Id do curso no EAD."),
  43.      *         @OA\Property(property="titulo_curso", type="string", example="Nome do curso", description="Título do curso."),
  44.      *         @OA\Property(property="emitir_certificado", type="integer", example=360, description="Determina se o curso irá emitir certificado. (0-Não / 1-Sim)"),
  45.      *         @OA\Property(property="cadastro", type="date time", example="2020-01-01 00:00:01", description="Data em que o aluno foi matriculado."),
  46.      *         @OA\Property(property="inicio", type="date time", example="2020-01-01 00:00:01", description="Data início do curso."),
  47.      *         @OA\Property(property="suporte", type="date time", example="2020-01-01 00:00:01", description="Data final do suporte."),
  48.      *         @OA\Property(property="expira", type="date time", example="2020-01-01 00:00:01", description="Data que encerra o acesso ao curso."),
  49.      *         @OA\Property(property="status", type="integer", example="1", description="Status da matrícula. (1-Ativa / 2-Suspensa / 3-Cancelada / 4-Expirada)"),
  50.      *         @OA\Property(property="assinatura_id", type="integer", example=10, description="Id da assinatura que originou a matrícula."),
  51.      *         @OA\Property(property="cupom", type="string", example="CHAVE", description="Cupom utilizado na matrícula."),
  52.      *         @OA\Property(property="origem", type="integer", example="professor(a)@email.com", description="E-mail do professor(a) cadastrado no EAD. (1-Grátis / 2-Venda / 3-Assinatura / 4-Grupo / 5-Cupom / 6-API / 7-Grátis)"),
  53.      *         @OA\Property(property="grupo_id", type="integer", example="123", description="Id de um grupo do EAD."),
  54.      *         @OA\Property(property="grupo_nome", type="string", example="Nome grupo", description="Nome do grupo a que pertence o aluno.")
  55.      *     )
  56.      * )
  57.      * 
  58.      * @OA\Response(
  59.      *     response=204,
  60.      *     description="No content"
  61.      * )
  62.      * 
  63.      * @OA\Response(
  64.      *     response=401,
  65.      *     description="Token not found",
  66.      *     @OA\JsonContent(
  67.      *         type="object",
  68.      *         @OA\Property(property="http_status", type="integer", example=401, description="Token not found"),
  69.      *         @OA\Property(property="message", type="string", example="Token not found")
  70.      *     )
  71.      * )
  72.      * 
  73.      * @OA\Response(
  74.      *     response=429,
  75.      *     description="Too many requests",
  76.      *     @OA\JsonContent(
  77.      *         type="object",
  78.      *         @OA\Property(property="http_status", type="integer", example=429, description="Too many requests"),
  79.      *         @OA\Property(property="message", type="string", example="Too many requests")
  80.      *     )
  81.      * )
  82.      * 
  83.      * @OA\Response(
  84.      *     response=500,
  85.      *     description="Internal Server Error",
  86.      *     @OA\JsonContent(
  87.      *         type="object",
  88.      *         @OA\Property(property="http_status", type="integer", example=500, description="Internal Server Error"),
  89.      *         @OA\Property(property="message", type="string", example="Internal Server Error")
  90.      *     )
  91.      * )
  92.      * 
  93.      * @OA\Parameter(
  94.      *     name="id",
  95.      *     in="query",
  96.      *     description="Matricula Id",
  97.      *     @OA\Schema(type="integer")
  98.      * )
  99.      * 
  100.      * @OA\Parameter(
  101.      *     name="usuario_id",
  102.      *     in="query",
  103.      *     description="Usuário Id",
  104.      *     @OA\Schema(type="integer")
  105.      * )
  106.      * 
  107.      * @OA\Parameter(
  108.      *     name="curso",
  109.      *     in="query",
  110.      *     description="Curso Id",
  111.      *     @OA\Schema(type="integer")
  112.      * )
  113.      * 
  114.      * @OA\Parameter(
  115.      *     name="grupo",
  116.      *     in="query",
  117.      *     description="Grupo Id",
  118.      *     @OA\Schema(type="integer")
  119.      * )
  120.      * 
  121.      * @OA\Parameter(
  122.      *     name="assinatura_id",
  123.      *     in="query",
  124.      *     description="Assinatura Id",
  125.      *     @OA\Schema(type="integer")
  126.      * )
  127.      * 
  128.      * @OA\Parameter(
  129.      *     name="cupom",
  130.      *     in="query",
  131.      *     description="Cupom",
  132.      *     @OA\Schema(type="string")
  133.      * )
  134.      * 
  135.      *  @OA\Parameter(
  136.      *     name="data_inicio",
  137.      *     in="query",
  138.      *     description="Data inicial última visualização (yyyy-mm-dd)",
  139.      *     @OA\Schema(type="string")
  140.      * )
  141.      * 
  142.      * @OA\Parameter(
  143.      *     name="data_fim",
  144.      *     in="query",
  145.      *     description="Data final última visualização (yyyy-mm-dd)",
  146.      *     @OA\Schema(type="string")
  147.      * )
  148.      * 
  149.      * @OA\Parameter(
  150.      *     name="paginate",
  151.      *     in="query",
  152.      *     description="Informaçoes para paginação",
  153.      *     @OA\Schema(type="integer")
  154.      * )
  155.      * 
  156.      * @OA\Parameter(
  157.      *      name="limit",
  158.      *      in="query",
  159.      *      description="Número máximo de dados retornados por página, valor padrão 1000",
  160.      *      @OA\Schema(type="integer")
  161.      * )
  162.      * 
  163.      * @OA\Parameter(
  164.      *      name="offset",
  165.      *      in="query",
  166.      *      description="Indica o início da leitura, caso não informado valor padrão será 0",
  167.      *      @OA\Schema(type="integer")
  168.      * )
  169.      * 
  170.      * @OA\Tag(name="Matrículas")
  171.      * @Security(name="Bearer")
  172.      * 
  173.      */
  174.     public function getEnrollment(Request $request)
  175.     {
  176.        
  177.         $this->requestUtil->setRequest($request)->setData();
  178.         $columns = [
  179.             "e.id AS matricula_id",
  180.             "u.id AS aluno_id",
  181.             "u.name AS aluno_nome"
  182.             "u.email AS aluno_email",
  183.             "c.id AS curso_id"
  184.             "c.title AS titulo_curso",
  185.             "e.certificate AS emitir_certificado",
  186.             "DATE_FORMAT(e.dateRegister, '%Y-%m-%d %H:%i:%s') AS cadastro",
  187.             "DATE_FORMAT(e.dateStart, '%Y-%m-%d %H:%i:%s') AS inicio"
  188.             "DATE_FORMAT(e.dateSupport, '%Y-%m-%d %H:%i:%s') AS suporte",
  189.             "DATE_FORMAT(e.datePeriod, '%Y-%m-%d %H:%i:%s') AS expira",
  190.             "e.status",
  191.             "us.id AS assinatura_id",
  192.             "e.couponKey AS cupom",
  193.             "g.id AS grupo_id",
  194.             "g.name AS grupo_nome",
  195.             "e.origin AS origem"
  196.         ];
  197.         $userClass User::class;
  198.         $courseClass Course::class;
  199.         $userSubscription UserSubscription::class;
  200.         $groupClass Group::class;
  201.         $joins = [
  202.             "{$userClass} AS u" => "u.id = e.user AND u.deleted = 0",
  203.             "{$courseClass} AS c" => "c.id = e.course AND c.deleted = 0",
  204.             "{$userSubscription} AS us" => ["LEFT""us.id = e.userSubscription"],
  205.             "{$groupClass} AS g" => ["LEFT""g.id = e.group"],
  206.         ];
  207.         $enrollmentId = (int)$request->get('id');
  208.         $userId $request->get('usuario_id');
  209.         $courseId = (int)$request->get('curso');
  210.         $groupId = (int)$request->get('grupo');
  211.         $subscriptionId = (int)$request->get('assinatura_id');
  212.         $coupom $request->get('cupom');
  213.         $dateStart $request->get('data_inicio');
  214.         $dateEnd $request->get('data_fim');
  215.         $paginate $request->get('paginate');
  216.     
  217.         $limit = (int)$request->get('limit');
  218.         $offset = (int)$request->get('offset');
  219.         $filter = [
  220.             "e.deleted" => 0,
  221.             "e.user" => [ "!="]
  222.         ];
  223.         if(empty($limit) || $limit 1000){
  224.             $limit 1000;
  225.         }
  226.         if(empty($offset)){
  227.             $offset 0;
  228.         }
  229.         if($enrollmentId 0){
  230.             $filter["e.id"] = $enrollmentId;
  231.         }
  232.         if(!empty($userId) && $userId 1){
  233.             $filter["e.user"] = (int)$userId;
  234.         }
  235.         if($courseId 0){
  236.             $filter["e.course"] = $courseId;
  237.         }
  238.         if($subscriptionId 0){
  239.             $filter["e.userSubscription"] = $subscriptionId;
  240.         }
  241.         if(!empty($coupom)){
  242.             $filter["e.couponKey"] = $coupom;
  243.         }
  244.         if($groupId 0){
  245.             
  246.             $filter["e.group"] = $groupId;
  247.         }
  248.         if(empty($dateStart) && !empty($dateEnd)){
  249.             $dateStart date('Y-m-d'strtotime("-1 day",strtotime($dateEnd)));  
  250.         }
  251.         if(empty($dateEnd) && !empty($dateStart)){
  252.             $dateEnd date('Y-m-d'strtotime("+1 day",strtotime($dateStart))); 
  253.         }
  254.         if(!empty($dateStart) && !empty($dateEnd)){
  255.             $filter["whereText"] = "e.dateStart BETWEEN '{$dateStart}' AND '{$dateEnd}'"
  256.         }
  257.         $order = ["e.id" => "ASC"];
  258.         $data $this->repository->paginate(
  259.             "e"
  260.             null
  261.             $columns
  262.             $joins
  263.             $filter
  264.             $order
  265.             $limit
  266.             $offset
  267.         );
  268.         if(count($data['rows']) == 0){
  269.             return $this->eadResponse(nullErrorEnum::NO_CONTENTnull);
  270.         }
  271.         foreach ($data['rows'] as $key => $enrollment) {            
  272.             if($enrollment->status == EnrollmentEnum::STATUS_ACTIVE){
  273.                 if(strtotime($enrollment->expira) < time()){
  274.                     $enrollment->status EnrollmentEnum::STATUS_EXPIRED;
  275.                 }
  276.             }
  277.         }
  278.         if($paginate == 1){
  279.             unset($data['searchText']);
  280.             return $this->json($data);
  281.         }
  282.         return $this->json($data['rows']);
  283.     }
  284.     /**
  285.      * Progresso dos alunos em um curso.
  286.      *
  287.      * @Route("/api/1/progress", methods={"GET"})
  288.      * @OA\Response(
  289.      *     response=200,
  290.      *     description="Retorna o progresso dos alunos em um curso",
  291.      *     @OA\JsonContent(
  292.      *         type="object",
  293.      *         @OA\Property(property="curso_id", type="integer", example=10, description="Id do curso no EAD."),
  294.      *         @OA\Property(property="curso_titulo", type="string", example="Nome Curso", description="Título do curso."),
  295.      *         @OA\Property(property="aluno_id", type="integer", example=12, description="Id do aluno cadastrado no EAD."),
  296.      *         @OA\Property(property="aluno_nome", type="string", example="Nome Aluno", description="Nome do aluno."),
  297.      *         @OA\Property(property="total_aulas", type="integer", example=134, description="Número de aulas de um curso."),
  298.      *         @OA\Property(property="aulas_acessadas", type="integer", example=55, description="Número de aulas visualizadas."),
  299.      *         @OA\Property(property="progresso", type="float", example=30, description="Porcentagem concluída do curso."),
  300.      *         @OA\Property(property="visualizacoes", type="integer", example=60, description="Número de visualizações do aluno no curso."),
  301.      *         @OA\Property(property="suporte", type="integer", example=2, description="Número de suportes solicitados pelo aluno."),
  302.      *         @OA\Property(property="ultimo_acesso", type="datetime", example="", description="Data e hora do último acesso do aluno no curso.")
  303.      *     )
  304.      * )
  305.      * 
  306.      * @OA\Response(
  307.      *     response=204,
  308.      *     description="No content"
  309.      * )
  310.      * 
  311.      * @OA\Response(
  312.      *     response=401,
  313.      *     description="Token not found",
  314.      *     @OA\JsonContent(
  315.      *         type="object",
  316.      *         @OA\Property(property="http_status", type="integer", example=401, description="Token not found"),
  317.      *         @OA\Property(property="message", type="string", example="Token not found")
  318.      *     )
  319.      * )
  320.      * 
  321.      * @OA\Response(
  322.      *     response=429,
  323.      *     description="Too many requests",
  324.      *     @OA\JsonContent(
  325.      *         type="object",
  326.      *         @OA\Property(property="http_status", type="integer", example=429, description="Too many requests"),
  327.      *         @OA\Property(property="message", type="string", example="Too many requests")
  328.      *     )
  329.      * )
  330.      * 
  331.      * @OA\Response(
  332.      *     response=500,
  333.      *     description="Internal Server Error",
  334.      *     @OA\JsonContent(
  335.      *         type="object",
  336.      *         @OA\Property(property="http_status", type="integer", example=500, description="Internal Server Error"),
  337.      *         @OA\Property(property="message", type="string", example="Internal Server Error")
  338.      *     )
  339.      * )
  340.      * 
  341.      * @OA\Parameter(
  342.      *     name="curso",
  343.      *     in="query",
  344.      *     description="Curso Id",
  345.      *     @OA\Schema(type="integer")
  346.      * )
  347.      * 
  348.      * @OA\Parameter(
  349.      *     name="grupo_id",
  350.      *     in="query",
  351.      *     description="Grupo Id",
  352.      *     @OA\Schema(type="integer")
  353.      * )
  354.      * 
  355.      * @OA\Parameter(
  356.      *     name="plano_id",
  357.      *     in="query",
  358.      *     description="Plano Id",
  359.      *     @OA\Schema(type="integer")
  360.      * )
  361.      * 
  362.      * @OA\Parameter(
  363.      *     name="usuario_id",
  364.      *     in="query",
  365.      *     description="Usuário Id",
  366.      *     @OA\Schema(type="integer")
  367.      * )
  368.      * 
  369.      * @OA\Parameter(
  370.      *     name="data_inicio",
  371.      *     in="query",
  372.      *     description="Data inicial último acesso (yyyy-mm-dd)",
  373.      *     @OA\Schema(type="string")
  374.      * )
  375.      * 
  376.      * @OA\Parameter(
  377.      *     name="data_fim",
  378.      *     in="query",
  379.      *     description="Data final último acesso (yyyy-mm-dd)",
  380.      *     @OA\Schema(type="string")
  381.      * )
  382.      * 
  383.      * @OA\Parameter(
  384.      *     name="paginate",
  385.      *     in="query",
  386.      *     description="Informaçoes para paginação",
  387.      *     @OA\Schema(type="integer")
  388.      * )
  389.      * 
  390.      * @OA\Parameter(
  391.      *      name="limit",
  392.      *      in="query",
  393.      *      description="Número máximo de dados retornados por página, valor padrão 1000",
  394.      *      @OA\Schema(type="integer")
  395.      * )
  396.      * 
  397.      * @OA\Parameter(
  398.      *      name="offset",
  399.      *      in="query",
  400.      *      description="Indica o início da leitura, caso não informado valor padrão será 0",
  401.      *      @OA\Schema(type="integer")
  402.      * )
  403.      * 
  404.      * @OA\Tag(name="Log de acesso e Progresso do aluno")
  405.      * @Security(name="Bearer")
  406.      * 
  407.      */
  408.     public function getCourseProgress(Request $request)
  409.     {
  410.        
  411.         $discordService $this->generalService->getService('DiscordService');
  412.         $discordService->setChannel('debug');
  413.         $this->requestUtil->setRequest($request)->setData();
  414.         $columns = [
  415.             "e.id AS matricula_id",
  416.             "c.id AS curso_id"
  417.             "c.title AS curso_titulo",
  418.             "c.numberLesson AS total_aulas",
  419.             "u.id AS aluno_id",
  420.             "u.name AS aluno_nome",
  421.             "e.lessonNumberComplete AS aulas_acessadas",
  422.             "e.lessonNumberViews AS visualizacoes",
  423.             "e.supportNumberRequest AS suporte",
  424.             "DATE_FORMAT(e.dateLastAccess, '%Y-%m-%d %H:%i:%s') AS ultimo_acesso"
  425.         ];
  426.         $userClass User::class;
  427.         $courseClass Course::class;
  428.         $joins = [
  429.             "{$userClass} AS u" => "u.id = e.user AND u.deleted = 0",
  430.             "{$courseClass} AS c" => "c.id = e.course AND c.deleted = 0"
  431.         ];
  432.         $courseId = (int)$request->get('curso');
  433.         $userId = (int)$request->get('usuario_id');
  434.         $groupId = (int)$request->get('grupo_id');
  435.         $planId = (int)$request->get('plano_id');
  436.         $dateStart $request->get('data_inicio');
  437.         $dateEnd $request->get('data_fim');
  438.         $paginate $request->get('paginate');
  439.         $limit = (int)$request->get('limit');
  440.         $offset = (int)$request->get('offset');
  441.         $filter = [
  442.             "e.deleted" => 0,
  443.             "e.user" => [ "!="]
  444.         ];
  445.         $filter["whereText"] = " e.id > 0 ";
  446.         if($groupId 0){
  447.             $groupUserClass GroupUser::class;
  448.             $groupCourseClass GroupCourse::class;
  449.             $filter["whereText"] .= 
  450.                 AND u.id IN (
  451.                     SELECT
  452.                        IDENTITY(gUser.user)
  453.                     FROM {$groupUserClass} AS gUser 
  454.                     WHERE gUser.group = {$groupId}
  455.                 )
  456.             ";
  457.             $filter["whereText"] .= 
  458.                 AND c.id IN ( 
  459.                     SELECT
  460.                        IDENTITY(gCourse.course)
  461.                     FROM {$groupCourseClass} AS gCourse 
  462.                     WHERE gCourse.group = {$groupId}
  463.                 )
  464.             ";
  465.         }
  466.         if($planId 0){
  467.             $userSubscriptionClass UserSubscription::class;
  468.             $productCourseClass ProductCourse::class;
  469.             $filter["whereText"] .= 
  470.                 AND u.id IN (
  471.                     SELECT
  472.                        IDENTITY(us.user)
  473.                     FROM {$userSubscriptionClass} AS us 
  474.                     WHERE us.product = {$planId}
  475.                 )
  476.             ";
  477.             $filter["whereText"] .= 
  478.                 AND c.id IN ( 
  479.                     SELECT
  480.                        IDENTITY(pCourse.course)
  481.                     FROM {$productCourseClass} AS pCourse 
  482.                     WHERE pCourse.product = {$planId}
  483.                 )
  484.             ";
  485.         }
  486.         if(empty($limit) || $limit 1000){
  487.             $limit 1000;
  488.         }
  489.         if(empty($offset)){
  490.             $offset 0;
  491.         }
  492.         if($courseId 0){
  493.             $filter["e.course"] = $courseId;
  494.         }
  495.         if(!empty($userId) && $userId 1){
  496.             $filter["e.user"] = $userId;
  497.         }
  498.         if(empty($dateStart) && !empty($dateEnd)){
  499.             $dateStart date('Y-m-d'strtotime("-1 day",strtotime($dateEnd)));  
  500.         }
  501.         if(empty($dateEnd) && !empty($dateStart)){
  502.             $dateEnd date('Y-m-d'strtotime("+1 day",strtotime($dateStart))); 
  503.         }
  504.         if(!empty($dateStart) && !empty($dateEnd)){
  505.             $filter["whereText"] = "e.dateLastAccess BETWEEN '{$dateStart}' AND '{$dateEnd}'"
  506.         }
  507.         
  508.         $order = ["e.id" => "ASC"];
  509.         try {
  510.             $data $this->em->getRepository(Enrollment::class)->paginate(
  511.                 "e"
  512.                 null
  513.                 $columns
  514.                 $joins
  515.                 $filter
  516.                 $order
  517.                 $limit
  518.                 $offset
  519.             );
  520.             if(count($data['rows']) == 0){
  521.                 return $this->eadResponse(nullErrorEnum::NO_CONTENTnull);
  522.             }
  523.             foreach ($data['rows'] as $key => $value) {
  524.                 $data['rows'][$key]->progresso 0;
  525.                 if($data['rows'][$key]->total_aulas 0){
  526.                     $data['rows'][$key]->progresso round($data['rows'][$key]->aulas_acessadas 100 $data['rows'][$key]->total_aulas2);
  527.                 }
  528.             }
  529.             if($paginate == 1){
  530.                 unset($data['searchText']);
  531.                 return $this->json($data);
  532.             }
  533.             return $this->json($data['rows']);
  534.         } catch (Exception $e) {
  535.             $discordService->setMessage($e->getMessage());
  536.             $discordService->sendDiscord();
  537.         }
  538.     }
  539.     /**
  540.      * Inserir uma matrícula no EAD.
  541.      *
  542.      * @Route("/api/1/enrollment", methods={"POST"})
  543.      * consumes={"application/json"}
  544.      * produces={"application/json"}
  545.      * 
  546.      * @OA\Response(
  547.      *     response=200,
  548.      *     description="Success",
  549.      *     @OA\JsonContent(
  550.      *         type="object",
  551.      *         @OA\Property(property="http_status", type="integer", example=200, description="Success"),
  552.      *         @OA\Property(property="message", type="string", example="Success"),
  553.      *         @OA\Property(
  554.      *              property="data", 
  555.      *              type="object", 
  556.      *              @OA\Property(property="id", type="integer", example=1), 
  557.      *              @OA\Property(property="inicio", type="string", example="2021-10-11 00:00:00"),
  558.      *              @OA\Property(property="expira", type="string", example="2022-10-11 00:00:00"),
  559.      *              @OA\Property(property="suporte", type="string", example="2022-10-11 00:00:00"),
  560.      *              @OA\Property(property="curso_id", type="integer", example=5),
  561.      *              @OA\Property(property="aluno_id", type="integer", example=55),
  562.      *              @OA\Property(property="status", type="integer", example=1),
  563.      *              @OA\Property(property="emitir_certificado", type="integer", example=1),
  564.      *              @OA\Property(property="origem", type="integer", example=1),
  565.      *              @OA\Property(property="cupom", type="string", example="CUPOMKEY"),
  566.      *              @OA\Property(property="assinatura_id", type="integer", example=222),
  567.      *              @OA\Property(property="grupo_id", type="integer", example=2)
  568.      *         )  
  569.      *     )
  570.      * )
  571.      * 
  572.      * @OA\Response(
  573.      *     response=401,
  574.      *     description="Token not found",
  575.      *     @OA\JsonContent(
  576.      *         type="object",
  577.      *         @OA\Property(property="http_status", type="integer", example=401, description="Token not found"),
  578.      *         @OA\Property(property="message", type="string", example="Token not found")
  579.      *     )
  580.      * )
  581.      * 
  582.      * @OA\Response(
  583.      *     response=404,
  584.      *     description="Not found",
  585.      *     @OA\JsonContent(
  586.      *         type="object",
  587.      *         @OA\Property(property="http_status", type="integer", example=404, description="Not found"),
  588.      *         @OA\Property(property="message", type="string", example="Not found"),
  589.      *         @OA\Property(
  590.      *              property="data", 
  591.      *              type="array", 
  592.      *              collectionFormat="multi", 
  593.      *              @OA\Items(
  594.      *                  type="string",
  595.      *                  example="field"
  596.      *              )
  597.      *         ),
  598.      *     )
  599.      * )
  600.      * 
  601.      * @OA\Response(
  602.      *     response=406,
  603.      *     description="Empty Fields",
  604.      *     @OA\JsonContent(
  605.      *         type="object",
  606.      *         @OA\Property(property="http_status", type="integer", example=406, description="Empty Field"),
  607.      *         @OA\Property(property="message", type="string", example="Error"),
  608.      *         @OA\Property(
  609.      *              property="data", 
  610.      *              type="array", 
  611.      *              collectionFormat="multi", 
  612.      *              @OA\Items(
  613.      *                  type="string",
  614.      *                  example="field"
  615.      *              )
  616.      *         ),
  617.      *     )
  618.      * )
  619.      * 
  620.      * @OA\Response(
  621.      *     response=409,
  622.      *     description="Conflict",
  623.      *     @OA\JsonContent(
  624.      *         type="object",
  625.      *         @OA\Property(property="http_status", type="integer", example=409, description="Conflict"),
  626.      *         @OA\Property(property="message", type="string", example="Usuário já matriculado neste curso."),
  627.      *         @OA\Property(property="data", nullable=true, type="application/json", example="null")
  628.      *     )
  629.      * )
  630.      * 
  631.      * @OA\Response(
  632.      *     response=429,
  633.      *     description="Too many requests",
  634.      *     @OA\JsonContent(
  635.      *         type="object",
  636.      *         @OA\Property(property="http_status", type="integer", example=429, description="Too many requests"),
  637.      *         @OA\Property(property="message", type="string", example="Too many requests")
  638.      *     )
  639.      * )
  640.      * 
  641.      * @OA\Response(
  642.      *     response=500,
  643.      *     description="Internal Server Error",
  644.      *     @OA\JsonContent(
  645.      *         type="object",
  646.      *         @OA\Property(property="http_status", type="integer", example=500, description="Internal Server Error"),
  647.      *         @OA\Property(property="message", type="string", example="Internal Server Error")
  648.      *     )
  649.      * )
  650.      * 
  651.      * @OA\RequestBody(
  652.      *      required=true,
  653.      *      @OA\MediaType(
  654.      *          mediaType="multipart/form-data",
  655.      *          @OA\Schema(
  656.      *              type="object",
  657.      *              @OA\Property(
  658.      *                  property="curso_id",
  659.      *                  description="Curso Id",
  660.      *                  type="integer"
  661.      *              ),
  662.      *              @OA\Property(
  663.      *                  property="usuario_id",
  664.      *                  description="Usuário Id",
  665.      *                  type="integer"
  666.      *              ),
  667.      *              @OA\Property(
  668.      *                  property="expira",
  669.      *                  description="Período de acesso do aluno (Y-m-d H:i:s)",
  670.      *                  type="string"
  671.      *              ),
  672.      *              @OA\Property(
  673.      *                  property="suporte",
  674.      *                  description="Período de suporte do aluno (Y-m-d H:i:s)",
  675.      *                  type="string"
  676.      *              ),
  677.      *              required={"curso_id", "usuario_id"}
  678.      *          )
  679.      *      )
  680.      * )
  681.      * 
  682.      * @OA\Tag(name="Matrículas")
  683.      * @Security(name="Bearer")
  684.      * 
  685.      */
  686.     public function postEnrollment(Request $request)
  687.     {
  688.        
  689.         $this->requestUtil->setRequest($request)->setData();
  690.         
  691.         $courseId $this->requestUtil->getField('curso_id');
  692.         $userId $this->requestUtil->getField('usuario_id');
  693.         $datePeriodPost $this->requestUtil->getField('expira');
  694.         $dateSupportPost $this->requestUtil->getField('suporte');
  695.         
  696.         $course $this->em->getRepository(Course::class)->findOneBy([
  697.             "id" => $courseId,
  698.             "deleted" => EnrollmentEnum::ITEM_NO_DELETED
  699.         ]);
  700.         if(!$course){
  701.             return $this->eadResponse(['curso_id'], ErrorEnum::NOT_FOUNDErrorEnum::MESSAGE_NOT_FOUND);
  702.         }
  703.         $user $this->em->getRepository(User::class)->findOneBy([
  704.             "id" => $userId,
  705.             "deleted" => EnrollmentEnum::ITEM_NO_DELETED
  706.         ]);
  707.         if(!$user){
  708.             return $this->eadResponse(
  709.                 [ 'usuario_id' ], 
  710.                 ErrorEnum::FIELD_EMPTY
  711.                 ErrorEnum::MESSAGE_EMPTY_FIELD
  712.             );
  713.         }
  714.         $enrollmentService $this->generalService->getService('EnrollmentService');
  715.         $enrollmentService->setEmail(true);
  716.         $enrollmentService->setOrigin(EnrollmentEnum::ORIGIN_API);
  717.         $dateNow date('Y-m-d H:i:s');
  718.         if(!empty($datePeriodPost)){
  719.             $enrollmentService->setAccessDate(
  720.                 date('Y-m-d H:i:s'strtotime($datePeriodPost))
  721.             );
  722.         }
  723.         if(!empty($dateSupportPost)){
  724.             $enrollmentService->setSupportDate(
  725.                 date('Y-m-d H:i:s'strtotime($dateSupportPost))
  726.             );
  727.         }
  728.         
  729.         $data $enrollmentService->enrollUser($user$coursetruefalsetrue);
  730.         
  731.         if($data->errors){
  732.             return $this->eadResponse(
  733.                 $data->errors
  734.                 ErrorEnum::FIELD_EMPTY
  735.                 ErrorEnum::MESSAGE_EMPTY_FIELD
  736.             );
  737.         }
  738.         $enrollment $data->enrollment;
  739.         $data $enrollment->toReturnApi();
  740.         $this->userLogService->logInsert(
  741.             "enrollment"
  742.             $enrollment->getId(), 
  743.             $data
  744.             UserLogEnum::ORIGIN_CLIENT_API
  745.         );
  746.         return $this->eadResponse($dataErrorEnum::SUCCESSErrorEnum::MESSAGE_SUCCESS);
  747.     }
  748.     /**
  749.      * Atualizar uma matrícula do EAD.
  750.      *
  751.      * @Route("/api/1/enrollment/{id}", methods={"PUT"})
  752.      * consumes={"application/json"}
  753.      * produces={"application/json"}
  754.      * 
  755.      * @OA\Response(
  756.      *     response=200,
  757.      *     description="Success",
  758.      *     @OA\JsonContent(
  759.      *         type="object",
  760.      *         @OA\Property(property="http_status", type="integer", example=200, description="Success"),
  761.      *         @OA\Property(property="message", type="string", example="Success"),
  762.      *         @OA\Property(
  763.      *              property="data", 
  764.      *              type="object", 
  765.      *              @OA\Property(property="id", type="integer", example=1), 
  766.      *              @OA\Property(property="inicio", type="string", example="2021-10-11 00:00:00"),
  767.      *              @OA\Property(property="expira", type="string", example="2022-10-11 00:00:00"),
  768.      *              @OA\Property(property="suporte", type="string", example="2022-10-11 00:00:00"),
  769.      *              @OA\Property(property="curso_id", type="integer", example=5),
  770.      *              @OA\Property(property="aluno_id", type="integer", example=55),
  771.      *              @OA\Property(property="status", type="integer", example=1),
  772.      *              @OA\Property(property="emitir_certificado", type="integer", example=1),
  773.      *              @OA\Property(property="origem", type="integer", example=1),
  774.      *              @OA\Property(property="cupom", type="string", example="CUPOMKEY"),
  775.      *              @OA\Property(property="assinatura_id", type="integer", example=222),
  776.      *              @OA\Property(property="grupo_id", type="integer", example=2)
  777.      *         )  
  778.      *     )
  779.      * )
  780.      * 
  781.      * @OA\Response(
  782.      *     response=401,
  783.      *     description="Token not found",
  784.      *     @OA\JsonContent(
  785.      *         type="object",
  786.      *         @OA\Property(property="http_status", type="integer", example=401, description="Token not found"),
  787.      *         @OA\Property(property="message", type="string", example="Token not found")
  788.      *     )
  789.      * )
  790.      * 
  791.      * @OA\Response(
  792.      *     response=404,
  793.      *     description="Not found",
  794.      *     @OA\JsonContent(
  795.      *         type="object",
  796.      *         @OA\Property(property="http_status", type="integer", example=404, description="Not found"),
  797.      *         @OA\Property(property="message", type="string", example="Not found"),
  798.      *         @OA\Property(
  799.      *              property="data", 
  800.      *              type="array", 
  801.      *              collectionFormat="multi", 
  802.      *              @OA\Items(
  803.      *                  type="string",
  804.      *                  example="field"
  805.      *              )
  806.      *         ),
  807.      *     )
  808.      * )
  809.      * 
  810.      * @OA\Response(
  811.      *     response=406,
  812.      *     description="Empty Fields",
  813.      *     @OA\JsonContent(
  814.      *         type="object",
  815.      *         @OA\Property(property="http_status", type="integer", example=406, description="Empty Field"),
  816.      *         @OA\Property(property="message", type="string", example="Error"),
  817.      *         @OA\Property(
  818.      *              property="data", 
  819.      *              type="array", 
  820.      *              collectionFormat="multi", 
  821.      *              @OA\Items(
  822.      *                  type="string",
  823.      *                  example="field"
  824.      *              )
  825.      *         ),
  826.      *     )
  827.      * )
  828.      * 
  829.      * @OA\Response(
  830.      *     response=429,
  831.      *     description="Too many requests",
  832.      *     @OA\JsonContent(
  833.      *         type="object",
  834.      *         @OA\Property(property="http_status", type="integer", example=429, description="Too many requests"),
  835.      *         @OA\Property(property="message", type="string", example="Too many requests")
  836.      *     )
  837.      * )
  838.      * 
  839.      * @OA\Response(
  840.      *     response=500,
  841.      *     description="Internal Server Error",
  842.      *     @OA\JsonContent(
  843.      *         type="object",
  844.      *         @OA\Property(property="http_status", type="integer", example=500, description="Internal Server Error"),
  845.      *         @OA\Property(property="message", type="string", example="Internal Server Error")
  846.      *     )
  847.      * )
  848.      * 
  849.      * @OA\Parameter(
  850.      *     name="id",
  851.      *     in="path",
  852.      *     description="Matrícula Id",
  853.      *     required=true,
  854.      *     @OA\Schema(type="integer")
  855.      * )
  856.      * 
  857.      * @OA\RequestBody(
  858.      *      required=false,
  859.      *      @OA\MediaType(
  860.      *          mediaType="multipart/form-data",
  861.      *          @OA\Schema(
  862.      *              type="object",
  863.      *              @OA\Property(
  864.      *                  property="expira",
  865.      *                  description="Período de acesso do aluno (Y-m-d H:i:s)",
  866.      *                  type="string"
  867.      *              ),
  868.      *              @OA\Property(
  869.      *                  property="suporte",
  870.      *                  description="Período de suporte do aluno (Y-m-d H:i:s)",
  871.      *                  type="string"
  872.      *              ),
  873.      *              @OA\Property(
  874.      *                  property="emitir_certificado",
  875.      *                  description="Emitir Certificado. (0-Não / 1-Sim)",
  876.      *                  type="integer"
  877.      *              ),
  878.      *              @OA\Property(
  879.      *                  property="periodo_suporte",
  880.      *                  description="Período de Suporte em número de dias",
  881.      *                  type="integer"
  882.      *              ),
  883.      *              @OA\Property(
  884.      *                  property="status",
  885.      *                  description="Status da Matrícula. (1-Ativa / 2-Suspensa / 3-Cancelada / 4-Expirada)",
  886.      *                  type="integer"
  887.      *              ),
  888.      *           )
  889.      *       )
  890.      *   ),
  891.      * 
  892.      * @OA\Tag(name="Matrículas")
  893.      * @Security(name="Bearer")
  894.      * 
  895.      */
  896.     public function putEnrollment(Request $request)
  897.     {
  898.        
  899.         $this->requestUtil->setRequest($request)->setData();
  900.         
  901.         $enrollmentId $request->get('id');
  902.         $enrollment $this->repository->findOneBy([
  903.             "id" => $enrollmentId,
  904.             "deleted" => EnrollmentEnum::ITEM_NO_DELETED
  905.         ]);
  906.         
  907.         if (!$enrollment) {
  908.             return $this->eadResponse(nullErrorEnum::NOT_FOUNDErrorEnum::MESSAGE_NOT_FOUND);
  909.         }
  910.         $datePeriod $this->requestUtil->getField('expira');
  911.         if(!empty($datePeriod)){
  912.             $this->requestUtil->setField('datePeriod'$datePeriod);
  913.             $enrollment->setDatePeriod($datePeriod);
  914.         }
  915.         $dateSupport $this->requestUtil->getField('suporte');
  916.         if(!empty($dateSupport)){
  917.             $enrollment->setDateSupport($dateSupport);
  918.         }
  919.         $certificate $this->requestUtil->getField('emitir_certificado');
  920.         if(is_numeric($certificate)){
  921.             $enrollment->setCertificate($certificate);
  922.         }
  923.         $status $this->requestUtil->getField("status");
  924.         if(is_numeric($status) && ($status && $status <= 4)){
  925.             $enrollment->setStatus($status);
  926.         }
  927.         $errors $this->validateEntity($enrollment);
  928.         if($errors){
  929.             return $this->eadResponse($errorsErrorEnum::FIELD_EMPTYErrorEnum::MESSAGE_EMPTY_FIELD);
  930.         }
  931.         $this->em->flush();
  932.         $return $enrollment->toReturnApi();
  933.         $this->userLogService->logUpdate("enrollment"$enrollment->getId(), $returnUserLogEnum::ORIGIN_CLIENT_API);
  934.         return $this->eadResponse($returnErrorEnum::SUCCESSErrorEnum::MESSAGE_SUCCESS);
  935.     }
  936.     /**
  937.      * Excluir uma matrícula do EAD.
  938.      *
  939.      * @Route("/api/1/enrollment/{id}", methods={"DELETE"})
  940.      * @OA\Response(
  941.      *     response=200,
  942.      *     description="Success",
  943.      *     @OA\JsonContent(
  944.      *         type="object",
  945.      *         @OA\Property(property="http_status", type="integer", example=200, description="Success"),
  946.      *         @OA\Property(property="message", type="string", example="Success"),
  947.      *         @OA\Property(property="data", nullable=true, type="application/json", example="null"),  
  948.      *     )
  949.      * )
  950.      * 
  951.      * @OA\Response(
  952.      *     response=401,
  953.      *     description="Token not found",
  954.      *     @OA\JsonContent(
  955.      *         type="object",
  956.      *         @OA\Property(property="http_status", type="integer", example=401, description="Token not found"),
  957.      *         @OA\Property(property="message", type="string", example="Token not found")
  958.      *     )
  959.      * )
  960.      * 
  961.      * @OA\Response(
  962.      *     response=404,
  963.      *     description="Not found",
  964.      *     @OA\JsonContent(
  965.      *         type="object",
  966.      *         @OA\Property(property="http_status", type="integer", example=404, description="Not found"),
  967.      *         @OA\Property(property="message", type="string", example="Not found"),
  968.      *         @OA\Property(
  969.      *              property="data", 
  970.      *              type="array", 
  971.      *              collectionFormat="multi", 
  972.      *              @OA\Items(
  973.      *                  type="string",
  974.      *                  example="field"
  975.      *              )
  976.      *         ),
  977.      *     )
  978.      * )
  979.      * 
  980.      * @OA\Response(
  981.      *     response=429,
  982.      *     description="Too many requests",
  983.      *     @OA\JsonContent(
  984.      *         type="object",
  985.      *         @OA\Property(property="http_status", type="integer", example=429, description="Too many requests"),
  986.      *         @OA\Property(property="message", type="string", example="Too many requests")
  987.      *     )
  988.      * )
  989.      * 
  990.      * @OA\Response(
  991.      *     response=500,
  992.      *     description="Internal Server Error",
  993.      *     @OA\JsonContent(
  994.      *         type="object",
  995.      *         @OA\Property(property="http_status", type="integer", example=500, description="Internal Server Error"),
  996.      *         @OA\Property(property="message", type="string", example="Internal Server Error")
  997.      *     )
  998.      * )
  999.      * 
  1000.      * @OA\Parameter(
  1001.      *     name="id",
  1002.      *     in="path",
  1003.      *     description="Matrícula Id",
  1004.      *     required=true,
  1005.      *     @OA\Schema(type="integer")
  1006.      * )
  1007.      * 
  1008.      * @OA\Tag(name="Matrículas")
  1009.      * @Security(name="Bearer")
  1010.      * 
  1011.      */
  1012.     public function deleteEnrollment(Request $request)
  1013.     {
  1014.         $this->requestUtil->setRequest($request)->setData();
  1015.         $enrollmentId $request->get('id');
  1016.         $enrollment $this->repository->findOneBy([
  1017.             "id" => $enrollmentId,
  1018.             "deleted" => EnrollmentEnum::ITEM_NO_DELETED
  1019.         ]);
  1020.         if (!$enrollment) {
  1021.             return $this->eadResponse(nullErrorEnum::NOT_FOUNDErrorEnum::MESSAGE_NOT_FOUND);
  1022.         }
  1023.         try {
  1024.             
  1025.             $this->repository->delete($enrollmentTrashEnum::ENROLLMENTUserPermissionEnum::HIGHfalse);
  1026.             $this->userLogService->logDelete("enrollment"$enrollment->getId(), nullUserLogEnum::ORIGIN_CLIENT_API);
  1027.         } catch (Exception $e) {
  1028.             return $this->eadResponse(nullErrorEnum::INTERNAL_ERROR$e->getMessage());
  1029.         }
  1030.         return $this->eadResponse(nullErrorEnum::SUCCESSErrorEnum::MESSAGE_SUCCESS);
  1031.     }
  1032. }